00001
00002
00003
00004
00005
00006
00007 #ifndef __WVTYPETRAITS_H
00008 #define __WVTYPETRAITS_H
00009
00010 #include "wvxplc.h"
00011
00012 template<class T, bool b>
00013 struct WvTraits_Helper
00014 {
00015 static inline void maybe_addref(T* obj)
00016 {
00017 }
00018 static inline void release(T* obj)
00019 {
00020 delete obj;
00021 }
00022 };
00023
00024
00025 template<class T>
00026 struct WvTraits_Helper<T, true>
00027 {
00028 static inline void maybe_addref(T* obj)
00029 {
00030 obj->addRef();
00031 }
00032 static inline void release(T* obj)
00033 {
00034 if (obj)
00035 obj->release();
00036 }
00037 };
00038
00039
00040 template<class From>
00041 class WvTraits
00042 {
00043 typedef char Yes;
00044 struct No { char dummy[2]; };
00045 static From* from;
00046 static Yes test(IObject*);
00047 static No test(...);
00048 public:
00049 static inline void maybe_addref(From* obj)
00050 {
00051 const bool is_iobject = (sizeof(test(from)) == sizeof(Yes));
00052 WvTraits_Helper<From, is_iobject>::maybe_addref(obj);
00053 }
00054 static inline void release(From* obj)
00055 {
00056 const bool is_iobject = (sizeof(test(from)) == sizeof(Yes));
00057 WvTraits_Helper<From, is_iobject>::release(obj);
00058 }
00059 };
00060
00061 #endif