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

resourcetype_boolean.h

Go to the documentation of this file.
00001 
00003 
00004 #ifndef header_resourcetype_boolean
00005 #define header_resourcetype_boolean
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 
00015 class CL_Res_Boolean : public CL_ResourceType
00016 //: The Boolean resource is used to read boolean values from a resource file.
00017 // CL_Res_Boolean, CL_Res_Integer and CL_Res_String helps you with seperating
00018 // the game code from the constants used in the game.
00019 // <br>
00020 // Using these resource types, you can easily change the text used in the game.
00021 // Just by changing the resource file, you can make you game speak Danish (or Dutch), or
00022 // any other language. You can change the constants like weapon damage, movement
00023 // speed, and so on.
00024 // <br>
00025 // These resources can also be used to apply theme support into your application.
00026 // By letting each theme become a datafile, you can give the player full control
00027 // of the visual parts of the game - and without using much work on it yourself.
00030 {
00031 public:
00032         static bool load(std::string res_id, CL_ResourceManager *manager, bool _default);
00033         static bool load(std::string res_id, CL_ResourceManager *manager );
00034 
00035         CL_Res_Boolean();
00036 
00037 private:
00038 friend CL_ResourceManager;
00039         virtual CL_Resource *create_from_location(
00040                 std::string name,
00041                 std::string location,
00042                 CL_ResourceOptions *options,
00043                 CL_ResourceManager *parent);
00044 
00045         virtual CL_Resource *create_from_serialization(
00046                 std::string name,
00047                 CL_ResourceManager *parent);
00048 };
00049 
00050 class CL_BooleanResource : public CL_Resource
00051 {
00052 public:
00053         CL_BooleanResource(
00054                 std::string name,
00055                 bool value)
00056         : CL_Resource("boolean", name)
00057         {
00058                 this->value = value;
00059                 load_count = 0;
00060         }
00061 
00062         CL_BooleanResource(
00063                 std::string name,
00064                 std::string location,
00065                 CL_ResourceOptions *options,
00066                 CL_ResourceManager *parent)
00067         : CL_Resource("boolean", name)
00068         {
00069                 if (location == "true") value = true;
00070                 else if (location == "false") value = false;
00071                 else
00072                 {
00073                         CL_String err;
00074                         err << "Boolean resource has invalid value: " << location;
00075                         throw CL_Error(err.get_string());
00076                 }
00077                 load_count = 0;
00078         }
00079 
00080         CL_BooleanResource(
00081                 std::string name,
00082                 CL_ResourceManager *parent)
00083         : CL_Resource("boolean", name)
00084         {
00085                 CL_InputSource *input =
00086                         parent->get_resource_provider()->open_source(name.c_str());
00087 
00088                 unsigned char v = input->read_uchar8();
00089                 value = (v == 1);
00090                 
00091                 delete input;
00092                 load_count = 0;
00093         }
00094         
00095         bool get_value() const { return value; }
00096 
00097         virtual void load() { load_count++; }
00098         virtual void unload() { load_count--; }
00099         virtual int get_load_count() { return load_count; }
00100 
00101         virtual void serialize_save(CL_OutputSource *output)
00102         {
00103                 unsigned char v = value ? 1 : 0;
00104                 output->write_uchar8(v);
00105         }
00106 
00107 private:
00108         bool value;
00109         int load_count;
00110 };
00111 
00112 #endif

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