VR-Vantage
Loading...
Searching...
No Matches
virtualConstructor.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2007 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
11
12
13#ifndef virtualConstructor_H__
14#define virtualConstructor_H__
15
16#include <vlutil/vlExceptions.h>
17
33#define DT_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST ) \
34 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\
35 static CLASS_NAME* create ARG_TYPES_LIST;\
36 static creatorFunction theCreator;\
37 static void setCreator(creatorFunction);\
38 /*lint -e{1736}*/\
39protected:\
40 explicit CLASS_NAME ARG_TYPES_LIST;\
41public:
42
61#define DT_VIRTUAL_COPY_ASSIGN( CLASS_NAME ) \
62 typedef CLASS_NAME* (*copierFunction)(const CLASS_NAME &);\
63 typedef CLASS_NAME& (*assignerFunction)(CLASS_NAME&,const CLASS_NAME &);\
64 static CLASS_NAME* copy (const CLASS_NAME &);\
65 static CLASS_NAME& assign(CLASS_NAME&,const CLASS_NAME &);\
66 static copierFunction theCopier;\
67 static assignerFunction theAssigner;\
68 static void setCopier (copierFunction);\
69 static void setAssigner(assignerFunction);\
70protected:\
71 explicit CLASS_NAME (const CLASS_NAME &);\
72 CLASS_NAME& operator=(const CLASS_NAME &);\
73public:
74
86#define DT_VIRTUAL_BASE_CTR( BASE_NAME , ARG_TYPES_LIST ) \
87 static BASE_NAME* createBase ARG_TYPES_LIST;\
88 static void overrideCreator();
89
90
106#define DT_PURE_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST )\
107 static CLASS_NAME* create ARG_TYPES_LIST;\
108 /*lint -e{1736}*/\
109public:\
110 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\
111 static creatorFunction theCreator;\
112 static void setCreator(creatorFunction);\
113protected:\
114 explicit CLASS_NAME ARG_TYPES_LIST;\
115public:
116
144#define DT_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
145 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\
146 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\
147 {\
148 theCreator = aCreatorFunc;\
149 }\
150 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \
151 {\
152 if(theCreator)\
153 return theCreator ARG_NAMES_LIST;\
154 else\
155 return new CLASS_NAME ARG_NAMES_LIST;\
156 }
157
181
182#define DT_VIRTUAL_COPY_ASSIGN_DEFINE(CLASS_NAME)\
183 CLASS_NAME::copierFunction CLASS_NAME::theCopier = 0;\
184 CLASS_NAME::assignerFunction CLASS_NAME::theAssigner = 0;\
185 void CLASS_NAME::setCopier(CLASS_NAME::copierFunction aCopierFunc)\
186 {\
187 theCopier = aCopierFunc;\
188 }\
189 void CLASS_NAME::setAssigner(CLASS_NAME::assignerFunction anAssignerFunc)\
190 {\
191 theAssigner = anAssignerFunc;\
192 }\
193 CLASS_NAME* CLASS_NAME::copy ( const CLASS_NAME & orig ) \
194 {\
195 if(theCopier)\
196 return theCopier (orig);\
197 else\
198 return new CLASS_NAME (orig);\
199 }\
200 CLASS_NAME& CLASS_NAME::assign(CLASS_NAME& toAssign,const CLASS_NAME& orig)\
201 {\
202 if(theAssigner)\
203 return theAssigner(toAssign,orig);\
204 else\
205 return toAssign = orig;\
206 }
207
208
209
210#define DT_VIRTUAL_BASE_CTR_DEFINE(CLASS_NAME,BASE_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
211 BASE_NAME* CLASS_NAME::createBase ARG_TYPES_AND_NAMES_LIST \
212 {\
213 if(CLASS_NAME::theCreator && (void*)&CLASS_NAME::theCreator != (void*)&BASE_NAME::theCreator)\
214 return CLASS_NAME::theCreator ARG_NAMES_LIST;\
215 else\
216 return new CLASS_NAME ARG_NAMES_LIST;\
217 }\
218 void CLASS_NAME::overrideCreator() \
219 {\
220 BASE_NAME::setCreator(&CLASS_NAME::createBase);\
221 }
222
254#define DT_PURE_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
255 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\
256 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\
257 {\
258 theCreator = aCreatorFunc;\
259 }\
260 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \
261 {\
262 if(theCreator && theCreator != CLASS_NAME::create)\
263 return theCreator ARG_NAMES_LIST;\
264 else\
265 throw DtCorruptedState("Class " #CLASS_NAME " has not be defined\n");\
266 }
267
268#endif
269