]> git.cworth.org Git - vogl/blob - src/extlib/loki/include/loki/Register.h
Initial vogl checkin
[vogl] / src / extlib / loki / include / loki / Register.h
1 ////////////////////////////////////////////////////////////////////////////////
2 // The Loki Library
3 // Copyright (c) 2006 Peter Kümmel
4 // Permission to use, copy, modify, distribute and sell this software for any
5 //     purpose is hereby granted without fee, provided that the above copyright
6 //     notice appear in all copies and that both that copyright notice and this
7 //     permission notice appear in supporting documentation.
8 // The author makes no representations about the
9 //     suitability of this software for any purpose. It is provided "as is"
10 //     without express or implied warranty.
11 ////////////////////////////////////////////////////////////////////////////////
12 #ifndef LOKI_REGISTER_INC_
13 #define LOKI_REGISTER_INC_
14
15 // $Id: Register.h 776 2006-11-09 13:12:57Z syntheticpp $
16
17
18 #include "TypeManip.h"
19 #include "HierarchyGenerators.h"
20
21 ///  \defgroup RegisterGroup Register
22
23 namespace Loki
24 {
25
26 ////////////////////////////////////////////////////////////////////////////////
27 //
28 //  Helper classes/functions for RegisterByCreateSet
29 //
30 ////////////////////////////////////////////////////////////////////////////////
31
32 ////////////////////////////////////////////////////////////////////////////////
33 ///  \ingroup RegisterGroup
34 ///  Must be specialized be the user
35 ////////////////////////////////////////////////////////////////////////////////
36 template<class t> bool RegisterFunction();
37
38 ////////////////////////////////////////////////////////////////////////////////
39 ///  \ingroup RegisterGroup
40 ///  Must be specialized be the user
41 ////////////////////////////////////////////////////////////////////////////////
42 template<class t> bool UnRegisterFunction();
43
44 namespace Private
45 {
46 template<class T>
47 struct RegisterOnCreate
48 {
49         RegisterOnCreate()
50         {
51                 RegisterFunction<T>();
52         }
53 };
54
55 template<class T>
56 struct UnRegisterOnDelete
57 {
58         ~UnRegisterOnDelete()
59         {
60                 UnRegisterFunction<T>();
61         }
62 };
63
64 template<class T>
65 struct RegisterOnCreateElement
66 {
67         RegisterOnCreate<T> registerObj;
68 };
69
70 template<class T>
71 struct UnRegisterOnDeleteElement
72 {
73         UnRegisterOnDelete<T> unregisterObj;
74 };
75 }
76
77 ////////////////////////////////////////////////////////////////////////////////
78 ///  \class RegisterOnCreateSet
79 ///
80 ///  \ingroup RegisterGroup
81 ///  Implements a generic register class which registers classes of a typelist
82 ///
83 ///  \par Usage
84 ///  see test/Register
85 ////////////////////////////////////////////////////////////////////////////////
86
87 template<typename ElementList>
88 struct RegisterOnCreateSet
89                 : GenScatterHierarchy<ElementList, Private::RegisterOnCreateElement>
90         {};
91
92 ////////////////////////////////////////////////////////////////////////////////
93 ///  \class UnRegisterOnDeleteSet
94 ///
95 ///  \ingroup RegisterGroup
96 ///  Implements a generic register class which unregisters classes of a typelist
97 ///
98 ///  \par Usage
99 ///  see test/Register
100 ////////////////////////////////////////////////////////////////////////////////
101 template<typename ElementList>
102 struct UnRegisterOnDeleteSet
103                 : GenScatterHierarchy<ElementList, Private::UnRegisterOnDeleteElement>
104         {};
105
106
107 ////////////////////////////////////////////////////////////////////////////////
108 ///  \def  LOKI_CHECK_CLASS_IN_LIST( CLASS , LIST )
109 ///
110 ///  \ingroup RegisterGroup
111 ///  Check if CLASS is in the typelist LIST.
112 ///
113 ///  \par Usage
114 ///  see test/Register
115 ////////////////////////////////////////////////////////////////////////////////
116
117
118 #define LOKI_CONCATE(a,b,c,d) a ## b ## c ## d
119 #define LOKI_CONCAT(a,b,c,d) LOKI_CONCATE(a,b,c,d)
120
121 #define LOKI_CHECK_CLASS_IN_LIST( CLASS , LIST )                                \
122                                                                                 \
123     struct LOKI_CONCAT(check_,CLASS,_isInList_,LIST)                            \
124     {                                                                           \
125         typedef int LOKI_CONCAT(ERROR_class_,CLASS,_isNotInList_,LIST);         \
126     };                                                                          \
127     typedef Loki::Select<Loki::TL::IndexOf<LIST, CLASS>::value == -1,           \
128                         CLASS,                                                  \
129                         LOKI_CONCAT(check_,CLASS,_isInList_,LIST)>              \
130                         ::Result LOKI_CONCAT(CLASS,isInList,LIST,result);       \
131     typedef LOKI_CONCAT(CLASS,isInList,LIST,result)::                           \
132                         LOKI_CONCAT(ERROR_class_,CLASS,_isNotInList_,LIST)      \
133                         LOKI_CONCAT(ERROR_class_,CLASS,_isNotInList__,LIST);
134
135
136 } // namespace Loki
137
138
139 #endif // end file guardian
140