Base/type.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Riegel         <juergen.riegel@web.de>                  *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  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 Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef BASE_TYPE_H
00025 #define BASE_TYPE_H
00026 
00027 // Std. configurations
00028 
00029 #include <string>
00030 #include <map>
00031 #include <set>
00032 #include <vector>
00033 
00034 namespace Base
00035 {
00036 
00037 struct TypeData;
00038 
00039 
00077 class BaseExport Type
00078 {
00079 public:
00081   Type(const Type& type);
00082   Type(void);
00084   virtual ~Type();
00085 
00087   void *createInstance(void);
00089   static void *createInstanceByName(const char* TypeName, bool bLoadModule=false);
00090 
00091   typedef void * (*instantiationMethod)(void);
00092 
00093   static Type fromName(const char *name);
00094   const char *getName(void) const;
00095   const Type getParent(void) const;
00096   bool isDerivedFrom(const Type type) const;
00097 
00098   static int getAllDerivedFrom(const Type type, std::vector<Type>& List);
00099 
00100   static int getNumTypes(void);
00101 
00102   static const Type createType(const Type parent, const char *name,instantiationMethod method = 0);
00103 
00104   unsigned int getKey(void) const;
00105   bool isBad(void) const;
00106 
00107   void operator =  (const Type type); 
00108   bool operator == (const Type type) const;
00109   bool operator != (const Type type) const;
00110 
00111   bool operator <  (const Type type) const;
00112   bool operator <= (const Type type) const;
00113   bool operator >= (const Type type) const;
00114   bool operator >  (const Type type) const;
00115 
00116   static Type badType(void);
00117   static void init(void);
00118   static void destruct(void);
00119 
00120 protected:
00121   static std::string getModuleName(const char* ClassName);
00122 
00123 
00124 private:
00125 
00126 
00127   unsigned int index;
00128 
00129 
00130   static std::map<std::string,unsigned int> typemap;
00131   static std::vector<TypeData*>     typedata;
00132 
00133   static std::set<std::string>  loadModuleSet;
00134 
00135 };
00136 
00137 
00138 inline unsigned int
00139 Type::getKey(void) const
00140 {
00141   return this->index;
00142 }
00143 
00144 inline bool
00145 Type::operator != (const Type type) const
00146 {
00147   return (this->getKey() != type.getKey());
00148 }
00149 
00150 inline void
00151 Type::operator = (const Type type) 
00152 {
00153   this->index = type.getKey();
00154 }
00155 
00156 inline bool
00157 Type::operator == (const Type type) const
00158 {
00159   return (this->getKey() == type.getKey());
00160 }
00161 
00162 inline bool
00163 Type::operator <  (const Type type) const
00164 {
00165   return (this->getKey() < type.getKey());
00166 }
00167 
00168 inline bool
00169 Type::operator <= (const Type type) const
00170 {
00171   return (this->getKey() <= type.getKey());
00172 }
00173 
00174 inline bool
00175 Type::operator >= (const Type type) const
00176 {
00177   return (this->getKey() >= type.getKey());
00178 }
00179 
00180 inline bool
00181 Type::operator >  (const Type type) const
00182 {
00183   return (this->getKey() > type.getKey());
00184 }
00185 
00186 inline bool
00187 Type::isBad(void) const
00188 {
00189   return (this->index == 0);
00190 }
00191 
00192 } //namespace Base
00193 
00194 
00195 #endif // BASE_TYPE_H
00196 

Generated on Wed Nov 23 19:00:51 2011 for FreeCAD by  doxygen 1.6.1