00001 /* SimData: Data Infrastructure for Simulations 00002 * Copyright (C) 2002 Mark Rose <tm2@stm.lbl.gov> 00003 * 00004 * This file is part of SimData. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00021 00029 #ifndef __SIMDATA_OBJECT_H__ 00030 #define __SIMDATA_OBJECT_H__ 00031 00032 00033 #include <cstdio> 00034 #include <cassert> 00035 #include <string> 00036 00037 #include <SimData/HashUtility.h> 00038 #include <SimData/BaseType.h> 00039 #include <SimData/Export.h> 00040 #include <SimData/Ref.h> 00041 00042 00043 class DataArchive; 00044 class LinkBase; 00045 00046 00047 // Various object macros for internal use only. 00048 #define __SIMDATA_LEAKCHECK(a) \ 00049 a() { printf(#a " %p\n", this); } \ 00050 ~a() { printf("~" #a " %p\n", this); } 00051 00052 #define __SIMDATA_GETCLASSNAME(a) \ 00053 static const char* _getClassName() { return #a; } \ 00054 virtual const char* getClassName() const { return _getClassName(); } 00055 00056 #define __SIMDATA_GETCLASSVERSION(major, minor) \ 00057 static const char* _getClassVersion() { return #major "." #minor; } \ 00058 virtual const char* getClassVersion() const { return _getClassVersion(); } 00059 00060 #define __SIMDATA_GETCLASSHASH(a, major) \ 00061 static SIMDATA(hasht) _getClassHash() { \ 00062 static SIMDATA(hasht) hash = 0; \ 00063 if (hash == 0) hash = _getHash(#a ":" #major); \ 00064 return hash; \ 00065 } \ 00066 virtual SIMDATA(hasht) getClassHash() const { return _getClassHash(); } 00067 00068 #define __SIMDATA_ISSTATIC(static_) \ 00069 static bool _isClassStatic() { return static_; } \ 00070 static bool isClassStatic() { return _isClassStatic(); } 00071 00072 #define __SIMDATA_CLASSDEF(a, major, minor) \ 00073 __SIMDATA_GETCLASSNAME(a) \ 00074 __SIMDATA_GETCLASSHASH(a, major) \ 00075 __SIMDATA_GETCLASSVERSION(major, minor) \ 00076 00077 #define __SIMDATA_NEW(a) virtual SIMDATA(Object)* _new() const { return new a(); } 00078 00090 #define SIMDATA_OBJECT(a, major, minor) \ 00091 __SIMDATA_CLASSDEF(a, major, minor) \ 00092 __SIMDATA_ISSTATIC(false) \ 00093 __SIMDATA_NEW(a) 00094 00105 #define SIMDATA_STATIC_OBJECT(a, major, minor) \ 00106 __SIMDATA_CLASSDEF(a, major, minor) \ 00107 __SIMDATA_ISSTATIC(true) \ 00108 __SIMDATA_NEW(a) 00109 00110 // Macro to automatically register an object class with the 00111 // object registry. This macro should be called for each 00112 // object class, preferably at the start of the cpp file 00113 // defining the class. 00114 #define SIMDATA_REGISTER(a) SIMDATA(ObjectProxy)<a> proxy##a; 00115 00116 00117 00118 NAMESPACE_SIMDATA 00119 00143 class SIMDATA_EXPORT Object: public virtual Referenced, public BaseType { 00144 friend class DataArchive; 00145 friend class LinkBase; 00146 00147 private: 00148 // Objects should never be copied 00149 Object(Object const &o); 00150 Object const &operator=(Object const &); 00151 00152 void _setPath(hasht); 00153 00154 hasht _path; 00155 00156 protected: 00165 virtual void postCreate() {} 00166 00167 public: 00168 explicit Object(); 00169 virtual ~Object(); 00170 00176 virtual Object* _new() const { 00177 assert(0); 00178 return 0; 00179 } 00180 00181 __SIMDATA_CLASSDEF(Object, 0, 0) 00182 00183 00191 virtual void serialize(Archive& archive); 00192 00198 virtual std::string asString() const; 00199 00208 virtual std::string typeString() const { return getClassName(); } 00209 00215 hasht getPath() const; 00216 00219 static hasht _getHash(const char* c); 00220 00221 }; 00222 00223 00224 NAMESPACE_SIMDATA_END 00225 00226 00227 #endif //__SIMDATA_OBJECT_H__ 00228
|
SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage. Generated on Tue Oct 14 12:06:39 2003, using Doxygen 1.2.18. |