Source

lrc / src / include / Resource.hxx

//      Resource.hxx
//
//      Copyright 2011, 2012 Andreas Tscharner <andy@vis.ethz.ch>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU Lesser General Public License as
//      published by the Free Software Foundation; either version 3 of the
//      License, or (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU Lesser General Public
//      License along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


/*! \file Resource.hxx
 *
 * This file contains one of the main classes: Resource
 *
 * \author Andreas Tscharner
 * \date 2012-06-10
 */


#ifndef __RESOURCE_HXX__
#define __RESOURCE_HXX__


#include <stddef.h>
#include "CompressDecompress.hxx"
#include "EncryptDecrypt.hxx"


/*! \mainpage lrc - Linux Resource Compiler
 *
 * \section intro Introduction
 * This documentation covers the classes and data structures of the \c lrc
 * compiler and the library \c liblrc.\n
 *
 * \section options Compiler Options
 * The compiler needs at least one input file. It is called as follows:\n
 * <tt>lrc -h | [-d] [-o \<rdfFile\>] [-c \<compression type\>]\<RCFile\>|\<rifFile\></tt>\n\n
 * The options have the following meaning:\n
 * <tt>-h</tt>: Show the usage of the compiler and quit.\n
 * <tt>-d</tt>: Deny overwrite an existing .rdf file. This parameter is
 * optional and the default is overwriting allowed. If <tt>-d</tt> is set
 * and the file already exists, the compiler exits with an error message.\n
 * <tt>-o \<file\></tt>: Specify the resource output file (.rdf). This
 * parameter is optional. If it is omitted the output file will be the name
 * of the input file, but with .rdf as file extension.\n
 * <tt>-c \<compression type\></tt>: Specify the compression type for the
 * whole .rdf file. Allowed are all compression types that are allowed for a
 * single resource file. These are at the moment:
 * - zLib: zLib compression
 * - bzip2: bzip2 compression
 *
 * \section liblrc The library liblrc
 * The library consists mainly of two classes: the \link
 * lrc::ResourceManager ResourceManager\endlink and the \link lrc::Resource
 * Resource\endlink class. One ResourceManager instance is used for one
 * resource data file (.rdf).\n
 * The resource manager provides two main methods: one lists all resource
 * entries from the .rdf file, the other returns an instance of a Resource
 * class, identified by its ID or index.
 *
 * \section example Example
 * A few examples that demonstrates the \c lrc and \c liblrc can be found in
 * the <tt>src/example</tt> directory.
 *
 * \author Andreas Tscharner
 * \date 2013-01-13
 */


#define MAX_ID_LEN 80                  //!< Maximum length of resource ID


/*! \brief Data for one resource entry
 *
 * This struct contains the data for one resource entry in a form to save to
 * the .rdf file
 */
struct resEntry_ {
	char resID[MAX_ID_LEN];            //!< Resource ID
	unsigned int startOffset;          //!< Offset from the start
	unsigned int resSize;              //!< Size of resource
	lrc::EncryptionType encType;       //!< Type of encryption of this entry
	lrc::CompressionType compType;     //!< Type of compression of this entry
};

//! Define a better name for struct resEntry_
typedef struct resEntry_ resEntry;


/*! \namespace lrc
 *  \brief Namespace lrc for classes in the library and for extending \c lrc
 *
 * The namespace lrc was introduced and used for classes and functions that
 * will be used in the \c liblrc library to avoid confusion with other
 * classes that may have the same name.
 *
 * It is also used for two abstract classes: CompressDecompress and
 * EncryptDecrypt. These two classes are the base classes for compression
 * and decompression and for encryption and decryption of the resource data.
 * They can be found in the CompressDecompress.hxx and the
 * EncryptDecrypt.hxx file respectively.
 */
namespace lrc
{
	/*! \class Resource
	 *  \brief Resource class for use with library
	 *
	 * This class is used to define one resource for the developer that uses
	 * lrc. It contains a pointer to the data and the size of the data. It
	 * also provides its ID.
	 */
	class Resource
	{
		protected:
			char *m_resID;             //!< Resource ID
			unsigned char *m_resData;  //!< Pointer to resource data
			size_t m_resSize;          //!< Size of resource data

		public:
			/*! \brief Constructor
			 *
			 * This is a standard constructor. It initializes all members
			 * to default values
			 *
			 * \remarks The values will be filled by the derived class
			 */
			Resource(void);
			/*! \brief Destructor
			 *
			 * Cleans up the used memory of the class
			 */
			~Resource(void);

			/*! \brief Returns the ID of the resource
			 *
			 * Method to return the ID of the resource
			 *
			 * \return ID of resource
			 */
			char *get_ID(void);
			/*! \brief Actual resource data
			 *
			 * This method returns a pointer to the actual resource data as
			 * bytes
			 *
			 * \return Pointer to resource data
			 */
			unsigned char *get_res_data(void);
			/*! \brief Actual resource size
			 *
			 * Method to return the actual size of the resource (in bytes)
			 *
			 * \return Size of resource
			 */
			size_t get_res_size(void);
	};
}


#endif /* __RESOURCE_HXX__ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.