ML Reference
MeVis/Foundation/Sources/MLUtilities/mlBase.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00010 
00015 //-------------------------------------------------------------------------
00016 #ifndef __mlBase_H
00017 #define __mlBase_H
00018 
00019 // Project-includes
00020 #ifndef __mlUtilsSystem_H
00021 #include "mlUtilsSystem.h"
00022 #endif
00023 #ifndef __mlRuntimeSubClass_H
00024 #include "mlRuntimeSubClass.h"
00025 #endif
00026 
00027 #include "mlSystemWarningsDisable.h"
00028 #include <vector>
00029 #include "mlSystemWarningsRestore.h"
00030 
00032 #define ML_SET_ADDSTATE_VERSION(v) static int getAddStateVersion(void) { return v; };
00033 
00034 #define ML_PERSISTENCE_VERSION(v) ML_SET_ADDSTATE_VERSION(v)
00035 
00036 ML_UTILS_START_NAMESPACE
00037 
00039 class TreeNode;
00040 class AbstractPersistenceOutputStream;
00041 class AbstractPersistenceInputStream;
00043 
00044 //----------------------------------------------------------------------
00049 
00057 //----------------------------------------------------------------------
00058 class ML_UTILS_EXPORT Base 
00059 {
00060   
00061 public:
00062 
00064   Base();
00065 
00067   virtual ~Base();
00068 
00070 
00072 
00074   enum PersistenceInterface {
00075     PersistenceByString,
00076     PersistenceByTreeNode,
00077     PersistenceByStream
00078   };
00079 
00082   virtual bool implementsPersistence(PersistenceInterface) const { return false; }
00083 
00087   virtual char* getPersistentState() const  ML_RETURN_VALUE_SHOULD_BE_USED { return 0; }
00088 
00091   virtual void setPersistentState(const char* /*state*/){ ; }
00092 
00094   virtual void clearPersistentState(char* /*state*/) const { ; }
00095 
00097   virtual void addStateToTree(TreeNode* /*parent*/) const { ; }
00098 
00100   virtual void readStateFromTree(TreeNode* /*parent*/) { ; }
00101 
00109   virtual void writeTo(AbstractPersistenceOutputStream* /*stream*/) const {}
00110 
00120   virtual void readFrom(AbstractPersistenceInputStream* /*stream*/, int /*version*/) {}
00121 
00123   ML_PERSISTENCE_VERSION(0);
00124 
00126 
00130   virtual Base* deepCopy() const { return NULL; };
00131 
00135   bool isOfAllowedType(const std::vector<const RuntimeType*>& types) const;
00136 
00138   virtual bool isRefCountedBase() const { return false; } 
00139 
00142   ML_ABSTRACT_CLASS_HEADER(Base)
00143 
00144 };
00145 
00146 ML_UTILS_END_NAMESPACE
00147 
00148 #undef ML_BASE_VERSION
00149 
00151 
00179 template<typename ToTypePtr>
00180 inline ToTypePtr mlbase_cast(ML_UTILS_NAMESPACE::Base* from) {
00181   if (from) {
00182     if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
00183       return static_cast<ToTypePtr>(from);
00184     } else {
00185       return NULL;
00186     }
00187   } else {
00188     return NULL;
00189   }
00190 }
00191 
00193 template<typename ToTypePtr>
00194 inline ToTypePtr mlbase_cast(const ML_UTILS_NAMESPACE::Base* from) {
00195   if (from) {
00196     if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
00197       return static_cast<ToTypePtr>(from);
00198     } else {
00199       return NULL;
00200     }
00201   } else {
00202     return NULL;
00203   }
00204 }
00205 
00206 #endif // __mlBase_H
00207 
00208