00001
00003
00004 #ifndef header_resourcetype_integer
00005 #define header_resourcetype_integer
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_Integer : public CL_ResourceType
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00030
00031 public:
00032 static int load(std::string res_id, CL_ResourceManager *manager, int _default);
00033 static int load(std::string res_id, CL_ResourceManager *manager );
00034
00035 CL_Res_Integer();
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_IntegerResource : public CL_Resource
00051 {
00052 public:
00053 CL_IntegerResource(
00054 std::string name,
00055 int value)
00056 : CL_Resource("integer", name)
00057 {
00058 this->value = value;
00059 load_count = 0;
00060 }
00061
00062 CL_IntegerResource(
00063 std::string name,
00064 std::string location,
00065 CL_ResourceOptions *options,
00066 CL_ResourceManager *parent)
00067 : CL_Resource("integer", name)
00068 {
00069 CL_String str = location;
00070 value = str.get_as_int();
00071
00072 load_count = 0;
00073 }
00074
00075 CL_IntegerResource(
00076 std::string name,
00077 CL_ResourceManager *parent)
00078 : CL_Resource("integer", name)
00079 {
00080 CL_InputSource *input =
00081 parent->get_resource_provider()->open_source(name.c_str());
00082
00083 value = input->read_int32();
00084
00085 delete input;
00086 load_count = 0;
00087 }
00088
00089 int get_value() const { return value; }
00090
00091 virtual void load() { load_count++; }
00092 virtual void unload() { load_count--; }
00093 virtual int get_load_count() { return load_count; }
00094
00095 virtual void serialize_save(CL_OutputSource *output)
00096 {
00097 output->write_int32(value);
00098 }
00099
00100 private:
00101 int value;
00102 int load_count;
00103 };
00104
00105 #endif