UGDK
|
00001 00002 #ifndef UGDK_SCRIPT_VIRTUALPRIMITIVE_H_ 00003 #define UGDK_SCRIPT_VIRTUALPRIMITIVE_H_ 00004 00005 #include <ugdk/script/virtualdata.h> 00006 #include <ugdk/script/type.h> 00007 00008 namespace ugdk { 00009 namespace script { 00010 00011 #define TYPENAME_MAP(definition) \ 00012 definition(const char*, String); \ 00013 definition(bool, Boolean); \ 00014 definition(int, Integer); \ 00015 definition(long, Integer); \ 00016 definition(short, Integer); \ 00017 definition(float, Number); \ 00018 definition(double, Number); 00019 00020 template <class T> 00021 class VirtualPrimitive { private: VirtualPrimitive() {} }; 00022 00023 template <class T> 00024 class VirtualPrimitive<T*> { 00025 public: 00026 static T* value(const VirtualData::Ptr data, bool disown) { 00027 return static_cast <T*> ( 00028 data->Unwrap(TypeRegistry<T>::type(), disown) 00029 ); 00030 } 00031 static void set_value(const VirtualData::Ptr data, T* value) { 00032 data->Wrap(value, TypeRegistry<T>::type()); 00033 } 00034 private: 00035 VirtualPrimitive() {} 00036 }; 00037 00038 #define DEFINE_SCRIPT_PRIMITIVE_VALUE(type, name, arg) \ 00039 template <> \ 00040 class VirtualPrimitive<type> { \ 00041 public: \ 00042 static type value(const VirtualData::Ptr data, bool disown) { \ 00043 return static_cast<type>(data->Unwrap##name()); \ 00044 } \ 00045 static void set_value(const VirtualData::Ptr data, type value) { \ 00046 data->Wrap##name(arg); \ 00047 } \ 00048 private: \ 00049 VirtualPrimitive() {} \ 00050 } 00051 00052 #define DEFINE_SCRIPT_SIMPLE_PRIMITIVE_VALUE(type, name) \ 00053 DEFINE_SCRIPT_PRIMITIVE_VALUE(type, name, value) 00054 00055 DEFINE_SCRIPT_PRIMITIVE_VALUE(std::string, String, value.c_str()); 00056 // Because I can! 00057 TYPENAME_MAP(DEFINE_SCRIPT_SIMPLE_PRIMITIVE_VALUE) 00058 00059 #undef TYPENAME_MAP 00060 00061 } /* namespace script */ 00062 } /* namespace ugdk */ 00063 00064 #endif /* UGDK_SCRIPT_VIRTUALPRIMITIVE_H_ */