Go to the documentation of this file.00001
00002
00003
00004
00005
00011
00012
00013 #ifndef virtualConstructor_H_
00014 #define virtualConstructor_H_
00015
00016 #include "lgrExceptions.h"
00017
00034 #define DT_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST ) \
00035 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\
00036 static CLASS_NAME* create ARG_TYPES_LIST;\
00037 static creatorFunction theCreator;\
00038 static void setCreator(creatorFunction);\
00039 \
00040 protected:\
00041 explicit CLASS_NAME ARG_TYPES_LIST;\
00042 public:
00043
00044
00045
00063 #define DT_VIRTUAL_CTR_DEFAULTS( CLASS_NAME , ARG_TYPES_LIST , ARG_DEFAULTS_LIST ) \
00064 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\
00065 static CLASS_NAME* create ARG_DEFAULTS_LIST;\
00066 static creatorFunction theCreator;\
00067 static void setCreator(creatorFunction);\
00068 \
00069 protected:\
00070 explicit CLASS_NAME ARG_TYPES_LIST;\
00071 public:
00072
00073
00093 #define DT_VIRTUAL_COPY_ASSIGN( CLASS_NAME ) \
00094 typedef CLASS_NAME* (*copierFunction)(const CLASS_NAME &);\
00095 typedef CLASS_NAME& (*assignerFunction)(CLASS_NAME&,const CLASS_NAME &);\
00096 static CLASS_NAME* copy (const CLASS_NAME &);\
00097 static CLASS_NAME& assign(CLASS_NAME&,const CLASS_NAME &);\
00098 static copierFunction theCopier;\
00099 static assignerFunction theAssigner;\
00100 static void setCopier (copierFunction);\
00101 static void setAssigner(assignerFunction);\
00102 protected:\
00103 explicit CLASS_NAME (const CLASS_NAME &);\
00104 CLASS_NAME& operator=(const CLASS_NAME &);\
00105 public:
00106
00118 #define DT_VIRTUAL_BASE_CTR( BASE_NAME , ARG_TYPES_LIST ) \
00119 static BASE_NAME* createBase ARG_TYPES_LIST;\
00120
00121
00138 #define DT_PURE_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST )\
00139 static CLASS_NAME* create ARG_TYPES_LIST;\
00140 \
00141 public:\
00142 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\
00143 static creatorFunction theCreator;\
00144 static void setCreator(creatorFunction);\
00145 protected:\
00146 explicit CLASS_NAME ARG_TYPES_LIST;\
00147 public:
00148
00177 #define DT_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
00178 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\
00179 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\
00180 {\
00181 theCreator = aCreatorFunc;\
00182 }\
00183 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \
00184 {\
00185 if(theCreator)\
00186 return theCreator ARG_NAMES_LIST;\
00187 else\
00188 return new CLASS_NAME ARG_NAMES_LIST;\
00189 }
00190
00215 #define DT_VIRTUAL_COPY_ASSIGN_DEFINE(CLASS_NAME)\
00216 CLASS_NAME::copierFunction CLASS_NAME::theCopier = 0;\
00217 CLASS_NAME::assignerFunction CLASS_NAME::theAssigner = 0;\
00218 void CLASS_NAME::setCopier(CLASS_NAME::copierFunction aCopierFunc)\
00219 {\
00220 theCopier = aCopierFunc;\
00221 }\
00222 void CLASS_NAME::setAssigner(CLASS_NAME::assignerFunction anAssignerFunc)\
00223 {\
00224 theAssigner = anAssignerFunc;\
00225 }\
00226 CLASS_NAME* CLASS_NAME::copy ( const CLASS_NAME & orig ) \
00227 {\
00228 if(theCopier)\
00229 return theCopier (orig);\
00230 else\
00231 return new CLASS_NAME (orig);\
00232 }\
00233 CLASS_NAME& CLASS_NAME::assign(CLASS_NAME& toAssign,const CLASS_NAME& orig)\
00234 {\
00235 if(theAssigner)\
00236 return theAssigner(toAssign,orig);\
00237 else\
00238 return toAssign = orig;\
00239 }
00240
00241
00242
00244 #define DT_VIRTUAL_BASE_CTR_DEFINE(CLASS_NAME,BASE_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
00245 BASE_NAME* CLASS_NAME::createBase ARG_TYPES_AND_NAMES_LIST \
00246 {\
00247 if(CLASS_NAME::theCreator)\
00248 return CLASS_NAME::theCreator ARG_NAMES_LIST;\
00249 else\
00250 return new CLASS_NAME ARG_NAMES_LIST;\
00251 }
00252
00285 #define DT_PURE_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\
00286 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\
00287 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\
00288 {\
00289 theCreator = aCreatorFunc;\
00290 }\
00291 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \
00292 {\
00293 if(theCreator)\
00294 return theCreator ARG_NAMES_LIST;\
00295 else\
00296 throw DtAbstractInterfaceUndefined("Class " #CLASS_NAME " has not been defined\n");\
00297 }
00298
00299 #endif
00300