WvStreams
wvtypetraits.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
4  *
5  * Contains code you'd rather not think about.
6  */
7 #ifndef __WVTYPETRAITS_H
8 #define __WVTYPETRAITS_H
9 
10 #include "wvxplc.h"
11 
12 template<class T, bool b>
14 {
15  static inline void maybe_addref(T* obj)
16  {
17  }
18  static inline void release(T* obj)
19  {
20  delete obj;
21  }
22 };
23 
24 
25 template<class T>
26 struct WvTraits_Helper<T, true>
27 {
28  static inline void maybe_addref(T* obj)
29  {
30  obj->addRef();
31  }
32  static inline void release(T* obj)
33  {
34  if (obj)
35  obj->release();
36  }
37 };
38 
39 
40 template<class From>
41 class WvTraits
42 {
43  typedef char Yes;
44  struct No { char dummy[2]; };
45  static From* from;
46  static Yes test(IObject*);
47  static No test(...);
48 public:
49  static inline void maybe_addref(From* obj)
50  {
51  const bool is_iobject = (sizeof(test(from)) == sizeof(Yes));
53  }
54  static inline void release(From* obj)
55  {
56  const bool is_iobject = (sizeof(test(from)) == sizeof(Yes));
58  }
59 };
60 
61 #endif /* __WVTYPETRAITS_H */
IObject
Definition: IObject.h:65
WvTraits
Definition: wvtypetraits.h:41
WvTraits_Helper
Definition: wvtypetraits.h:13