![]() |
VR-Vantage 1.4.1 API Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2007 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: virtualConstructor.h,v $ $Revision: 1.6 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00014 00015 00016 #ifndef virtualConstructor_H__ 00017 #define virtualConstructor_H__ 00018 00019 #include <vlutil/vlExceptions.h> 00020 00036 #define DT_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST ) \ 00037 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\ 00038 static CLASS_NAME* create ARG_TYPES_LIST;\ 00039 static creatorFunction theCreator;\ 00040 static void setCreator(creatorFunction);\ 00041 /*lint -e{1736}*/\ 00042 protected:\ 00043 explicit CLASS_NAME ARG_TYPES_LIST;\ 00044 public: 00045 00064 #define DT_VIRTUAL_COPY_ASSIGN( CLASS_NAME ) \ 00065 typedef CLASS_NAME* (*copierFunction)(const CLASS_NAME &);\ 00066 typedef CLASS_NAME& (*assignerFunction)(CLASS_NAME&,const CLASS_NAME &);\ 00067 static CLASS_NAME* copy (const CLASS_NAME &);\ 00068 static CLASS_NAME& assign(CLASS_NAME&,const CLASS_NAME &);\ 00069 static copierFunction theCopier;\ 00070 static assignerFunction theAssigner;\ 00071 static void setCopier (copierFunction);\ 00072 static void setAssigner(assignerFunction);\ 00073 protected:\ 00074 explicit CLASS_NAME (const CLASS_NAME &);\ 00075 CLASS_NAME& operator=(const CLASS_NAME &);\ 00076 public: 00077 00089 #define DT_VIRTUAL_BASE_CTR( BASE_NAME , ARG_TYPES_LIST ) \ 00090 static BASE_NAME* createBase ARG_TYPES_LIST;\ 00091 static void overrideCreator(); 00092 00093 00109 #define DT_PURE_VIRTUAL_CTR( CLASS_NAME , ARG_TYPES_LIST )\ 00110 static CLASS_NAME* create ARG_TYPES_LIST;\ 00111 /*lint -e{1736}*/\ 00112 public:\ 00113 typedef CLASS_NAME* (*creatorFunction)ARG_TYPES_LIST;\ 00114 static creatorFunction theCreator;\ 00115 static void setCreator(creatorFunction);\ 00116 protected:\ 00117 explicit CLASS_NAME ARG_TYPES_LIST;\ 00118 public: 00119 00147 #define DT_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\ 00148 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\ 00149 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\ 00150 {\ 00151 theCreator = aCreatorFunc;\ 00152 }\ 00153 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \ 00154 {\ 00155 if(theCreator)\ 00156 return theCreator ARG_NAMES_LIST;\ 00157 else\ 00158 return new CLASS_NAME ARG_NAMES_LIST;\ 00159 } 00160 00184 00185 #define DT_VIRTUAL_COPY_ASSIGN_DEFINE(CLASS_NAME)\ 00186 CLASS_NAME::copierFunction CLASS_NAME::theCopier = 0;\ 00187 CLASS_NAME::assignerFunction CLASS_NAME::theAssigner = 0;\ 00188 void CLASS_NAME::setCopier(CLASS_NAME::copierFunction aCopierFunc)\ 00189 {\ 00190 theCopier = aCopierFunc;\ 00191 }\ 00192 void CLASS_NAME::setAssigner(CLASS_NAME::assignerFunction anAssignerFunc)\ 00193 {\ 00194 theAssigner = anAssignerFunc;\ 00195 }\ 00196 CLASS_NAME* CLASS_NAME::copy ( const CLASS_NAME & orig ) \ 00197 {\ 00198 if(theCopier)\ 00199 return theCopier (orig);\ 00200 else\ 00201 return new CLASS_NAME (orig);\ 00202 }\ 00203 CLASS_NAME& CLASS_NAME::assign(CLASS_NAME& toAssign,const CLASS_NAME& orig)\ 00204 {\ 00205 if(theAssigner)\ 00206 return theAssigner(toAssign,orig);\ 00207 else\ 00208 return toAssign = orig;\ 00209 } 00210 00211 00212 00213 #define DT_VIRTUAL_BASE_CTR_DEFINE(CLASS_NAME,BASE_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\ 00214 BASE_NAME* CLASS_NAME::createBase ARG_TYPES_AND_NAMES_LIST \ 00215 {\ 00216 if(CLASS_NAME::theCreator && (void*)&CLASS_NAME::theCreator != (void*)&BASE_NAME::theCreator)\ 00217 return CLASS_NAME::theCreator ARG_NAMES_LIST;\ 00218 else\ 00219 return new CLASS_NAME ARG_NAMES_LIST;\ 00220 }\ 00221 void CLASS_NAME::overrideCreator() \ 00222 {\ 00223 BASE_NAME::setCreator(&CLASS_NAME::createBase);\ 00224 } 00225 00257 #define DT_PURE_VIRTUAL_CTR_DEFINE(CLASS_NAME,ARG_TYPES_AND_NAMES_LIST,ARG_NAMES_LIST)\ 00258 CLASS_NAME::creatorFunction CLASS_NAME::theCreator = 0;\ 00259 void CLASS_NAME::setCreator(CLASS_NAME::creatorFunction aCreatorFunc)\ 00260 {\ 00261 theCreator = aCreatorFunc;\ 00262 }\ 00263 CLASS_NAME* CLASS_NAME::create ARG_TYPES_AND_NAMES_LIST \ 00264 {\ 00265 if(theCreator && theCreator != CLASS_NAME::create)\ 00266 return theCreator ARG_NAMES_LIST;\ 00267 else\ 00268 throw DtCorruptedState("Class " #CLASS_NAME " has not be defined\n");\ 00269 } 00270 00271 #endif 00272