Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

resourcetype_raw.h

Go to the documentation of this file.
00001 
00003 
00004 #ifndef header_resourcetype_raw
00005 #define header_resourcetype_raw
00006 
00007 #include "resource_manager.h"
00008 #include "resourcetype.h"
00009 #include "resource.h"
00010 #include "../System/clanstring.h"
00011 #include "../System/error.h"
00012 #include "../IOData/inputsource.h"
00013 #include "../IOData/inputsource_provider.h"
00014 #include "../../stl.h"
00015 
00016 class CL_Res_Raw : public CL_ResourceType
00017 //: The Raw resource is used to read raw data from a resource file.
00018 // CL_Res_Raw allows you to store a binary file in a resource file,
00019 // and then get the content of the binary file in an STL vector of bytes.
00020 // This is usefull if you want to handle your own binary format without
00021 // writting a whole ClanLib resource manager component, you just get the
00022 // binary data and can do whatever you want with it (as long as you don't
00023 // modify the contents of the resource of course).
00024 // This class allows you to store anything in a resource file,
00025 // since it does not perform any check on the stored data. For instance
00026 // it might be a good idea to use it to store game maps or levels.
00027 //
00028 // The data is accessible with std::vector::begin(), 
00029 // which returns an unsigned char *. The size (in bytes) of the data 
00030 // can be obtained with std::vector::size(). Keep in mind that if
00031 // you store complex classes or structs in such a buffer, it is not
00032 // safe to do a brutal cast, for different compilers might not use
00033 // the same memory alignments, especially if the endianess of the
00034 // machines are different for instance. So if you store complex data,
00035 // it is wise to write some clean and portable serialization functions.
00036 //
00039 {
00040 public:
00041         static std::vector<unsigned char> *load(std::string res_id, CL_ResourceManager *manager );
00042         //: Returns a buffer containing raw data.
00046 
00047         CL_Res_Raw();
00048 
00049 private:
00050 friend CL_ResourceManager;
00051         virtual CL_Resource *create_from_location(
00052                 std::string name,
00053                 std::string location,
00054                 CL_ResourceOptions *options,
00055                 CL_ResourceManager *parent);
00056 
00057         virtual CL_Resource *create_from_serialization(
00058                 std::string name,
00059                 CL_ResourceManager *parent);
00060 };
00061 
00062 class CL_RawResource : public CL_Resource
00063 {
00064 public:
00065         CL_RawResource(
00066                 std::string name,
00067                 std::string location,
00068                 CL_ResourceOptions *options,
00069                 CL_ResourceManager *parent);
00070 
00071         CL_RawResource(
00072                 std::string name,
00073                 CL_ResourceManager *parent);
00074         
00075         std::vector<unsigned char> *get_value();
00076 
00077         virtual void load();
00078         virtual void unload();
00079         virtual int get_load_count() { return load_count; }
00080         virtual void serialize_save(CL_OutputSource *output);
00081 
00082 private:
00083         void load_from_datafile();
00084         void load_from_file();
00085 
00086         std::vector<unsigned char> *value;
00087 
00088         CL_String location;
00089         CL_ResourceManager *parent;
00090         bool from_datafile;
00091         int load_count;
00092 };
00093 
00094 #endif
00095 

Generated at Wed Apr 4 19:54:03 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001