UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
virtualprimitive.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_SCRIPT_VIRTUALPRIMITIVE_H_
3 #define UGDK_SCRIPT_VIRTUALPRIMITIVE_H_
4 
6 #include <ugdk/script/type.h>
7 
8 namespace ugdk {
9 namespace script {
10 
11 #define TYPENAME_MAP(definition) \
12  definition(const char*, String); \
13  definition(bool, Boolean); \
14  definition(int, Integer); \
15  definition(long, Integer); \
16  definition(short, Integer); \
17  definition(float, Number); \
18  definition(double, Number);
19 
20 template <class T>
21 class VirtualPrimitive { private: VirtualPrimitive() {} };
22 
23 template <class T>
24 class VirtualPrimitive<T*> {
25  public:
26  static T* value(const VirtualData::Ptr data, bool disown) {
27  return static_cast <T*> (
28  data->Unwrap(TypeRegistry<T>::type(), disown)
29  );
30  }
31  static void set_value(const VirtualData::Ptr data, T* value) {
32  data->Wrap(value, TypeRegistry<T>::type());
33  }
34  private:
35  VirtualPrimitive() {}
36 };
37 
38 #define DEFINE_SCRIPT_PRIMITIVE_VALUE(type, name, arg) \
39  template <> \
40  class VirtualPrimitive<type> { \
41  public: \
42  static type value(const VirtualData::Ptr data, bool disown) { \
43  return static_cast<type>(data->Unwrap##name()); \
44  } \
45  static void set_value(const VirtualData::Ptr data, type value) { \
46  data->Wrap##name(arg); \
47  } \
48  private: \
49  VirtualPrimitive() {} \
50  }
51 
52 #define DEFINE_SCRIPT_SIMPLE_PRIMITIVE_VALUE(type, name) \
53  DEFINE_SCRIPT_PRIMITIVE_VALUE(type, name, value)
54 
55 DEFINE_SCRIPT_PRIMITIVE_VALUE(std::string, String, value.c_str());
56 // Because I can!
58 
59 #undef TYPENAME_MAP
60 
61 } /* namespace script */
62 } /* namespace ugdk */
63 
64 #endif /* UGDK_SCRIPT_VIRTUALPRIMITIVE_H_ */