Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED
00023 #define PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED
00024
00025 #include <typeinfo>
00026
00027 namespace detail {
00028 template <class T>
00029 struct VTable {
00030 static void clone(const void* o, void** out) {
00031 *out = new T(*static_cast<const T*>(o));
00032 }
00033 static void destroy(const void* o, void** out) {
00034 delete static_cast<const T*>(o);
00035 *out = 0;
00036 }
00037 static void typeinfo(const void*, void** out) {
00038 *out = const_cast<void*>( static_cast<const void*>(&typeid(T)) );
00039 }
00040 static vtable_type vtable_s;
00041 };
00042 template <class T>
00043 struct OptVTable {
00044 static void clone(const void* o, void** out) {
00045 new (&*out) T(*static_cast<const T*>(o));
00046 }
00047 static void destroy(const void* o, void** out) {
00048 static_cast<const T*>(o)->~T();
00049 *out = 0;
00050 }
00051 static vtable_type vtable_s;
00052 };
00053 template <class T>
00054 vtable_type VTable<T>::vtable_s = {
00055 0
00056 , &VTable<T>::clone
00057 , &VTable<T>::destroy
00058 , &VTable<T>::typeinfo
00059 };
00060 template <class T>
00061 vtable_type OptVTable<T>::vtable_s = {
00062 (vcall_type)0x1
00063 , &OptVTable<T>::clone
00064 , &OptVTable<T>::destroy
00065 , &VTable<T>::typeinfo
00066 };
00067 template <bool> struct bool2type {};
00068 template <class T>
00069 inline vptr_type vtable_select(bool2type<0>, const T* = 0) {
00070 return &VTable<T>::vtable_s;
00071 }
00072 template <class T>
00073 inline vptr_type vtable_select(bool2type<1>, const T* = 0) {
00074 return &OptVTable<T>::vtable_s;
00075 }
00076 template <class T>
00077 inline vptr_type vtable(const T* x) {
00078 return vtable_select(bool2type<sizeof(T)<=sizeof(void*)>(), x);
00079 }
00080
00081 template <class T>
00082 inline vptr_type base_vtable(const T* x) {
00083 return vtable_select(bool2type<0>(), x);
00084 }
00085
00086 }
00087
00088 #endif