00001 /********************************************************************** 00002 base.h - Base class for OpenBabel objects 00003 00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. 00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison 00006 00007 This file is part of the Open Babel project. 00008 For more information, see <http://openbabel.sourceforge.net/> 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation version 2 of the License. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 ***********************************************************************/ 00019 00020 #ifndef OB_BASE_H 00021 #define OB_BASE_H 00022 00023 #include <openbabel/babelconfig.h> 00024 00025 #include <vector> 00026 #include <map> 00027 #include <string> 00028 #include <iostream> 00029 #include <openbabel/tokenst.h> 00030 00031 namespace OpenBabel 00032 { 00033 00034 //Forward declaration of the base class for OBMol OBReaction, OBAtom, etc. 00035 //Declaration later in this file. 00036 class OBBase; 00037 00049 namespace OBGenericDataType 00050 { 00051 enum 00052 { 00054 UndefinedData = 0, 00055 00057 PairData = 1, 00058 00060 EnergyData = 2, 00061 00063 CommentData = 3, 00064 00066 ConformerData = 4, 00067 00069 ExternalBondData = 5, 00070 00072 RotamerList = 6, 00073 00075 VirtualBondData = 7, 00076 00078 RingData = 8, 00079 00081 TorsionData = 9, 00082 00084 AngleData = 10, 00085 00087 SerialNums = 11, 00088 00090 UnitCell = 12, 00091 00093 SpinData = 13, 00094 00096 ChargeData = 14, 00097 00099 SymmetryData = 15, 00100 00102 ChiralData = 16, 00103 00105 OccupationData = 17, 00106 00108 DensityData = 18, 00109 00111 ElectronicData = 19, 00112 00114 VibrationData = 20, 00115 00117 RotationData = 21, 00118 00120 NuclearData = 22, 00121 00123 SetData = 23, 00124 00126 GridData = 24, 00127 00129 VectorData = 25, 00130 00132 MatrixData = 26, 00133 00134 // space for up to 2^14 more entries... 00135 00137 CustomData0 = 16384, 00138 CustomData1 = 16385, 00139 CustomData2 = 16386, 00140 CustomData3 = 16387, 00141 CustomData4 = 16388, 00142 CustomData5 = 16389, 00143 CustomData6 = 16390, 00144 CustomData7 = 16391, 00145 CustomData8 = 16392, 00146 CustomData9 = 16393, 00147 CustomData10 = 16394, 00148 CustomData11 = 16395, 00149 CustomData12 = 16396, 00150 CustomData13 = 16397, 00151 CustomData14 = 16398, 00152 CustomData15 = 16399 00153 }; 00154 } // end namespace 00155 enum DataOrigin { 00156 any, 00157 fileformatInput, 00158 userInput, 00159 perceived, 00160 external 00161 }; 00162 00164 // Class introduction in generic.cpp 00165 // This base class declaration has no dependence on mol.h 00166 class OBAPI OBGenericData 00167 { 00168 protected: 00169 std::string _attr; 00170 unsigned int _type; 00171 DataOrigin _source; 00172 public: 00173 OBGenericData(const std::string attr = "undefined", 00174 const unsigned int type = OBGenericDataType::UndefinedData, 00175 const DataOrigin source = any); 00176 //Use default copy constructor and assignment operators 00177 //OBGenericData(const OBGenericData&); 00178 00179 /* Virtual constructors added. see 00180 http://www.parashift.com/c++-faq-lite/abcs.html#faq-22.5 00181 to allow copying given only a base class OBGenericData pointer. 00182 It may be necessary to cast the return pointer to the derived class 00183 type, since we are doing without Covariant Return Types 00184 http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8 00185 00186 A derived class may return NULL if copying is inappropriate */ 00187 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00188 { return NULL; } 00189 virtual ~OBGenericData() {} 00190 //Use default copy constructor and assignment operators 00191 //OBGenericData& operator=(const OBGenericData &src); 00192 00194 void SetAttribute(const std::string &v) 00195 { _attr = v; } 00197 void SetOrigin(const DataOrigin s) { _source = s; } 00199 virtual const std::string &GetAttribute() const 00200 { return(_attr); } 00202 unsigned int GetDataType() const 00203 { return(_type); } 00206 virtual const std::string &GetValue() const 00207 { return _attr; } 00208 virtual DataOrigin GetOrigin() const 00209 { return _source; } 00210 }; 00211 00213 typedef std::vector<OBGenericData*>::iterator OBDataIterator; 00214 00216 // introduction in base.cpp 00217 class OBAPI OBBase 00218 { 00219 public: 00220 virtual ~OBBase() 00221 { 00222 if (!_vdata.empty()) 00223 { 00224 std::vector<OBGenericData*>::iterator m; 00225 for (m = _vdata.begin();m != _vdata.end();m++) 00226 delete *m; 00227 _vdata.clear(); 00228 } 00229 } 00230 00232 virtual bool Clear(); 00233 00238 virtual OBBase* DoTransformations(const std::map<std::string,std::string>* /*pOptions*/) 00239 { 00240 return this; 00241 } 00242 00243 //Base type does nothing 00245 static const char* ClassDescription() 00246 { 00247 return ""; 00248 } 00249 00251 template< class T > 00252 T* CastAndClear(bool clear=true) 00253 { 00254 T* pOb = dynamic_cast<T*>(this); 00255 if(pOb && clear)// Clear only if this is of target class 00256 Clear(); 00257 return pOb; 00258 } 00259 00260 00262 00263 00264 bool HasData(const std::string &); 00266 bool HasData(const char *); 00268 bool HasData(const unsigned int type); 00270 void DeleteData(unsigned int type); 00272 void DeleteData(OBGenericData*); 00274 void DeleteData(std::vector<OBGenericData*>&); 00276 bool DeleteData(const std::string& s); 00278 void SetData(OBGenericData *d) 00279 { 00280 if(d) _vdata.push_back(d); 00281 } 00284 void CloneData(OBGenericData *d); 00286 unsigned int DataSize() const 00287 { return(_vdata.size()); } 00290 OBGenericData *GetData(const unsigned int type); 00292 OBGenericData *GetData(const std::string&); 00294 OBGenericData *GetData(const char *); 00298 std::vector<OBGenericData*> GetAllData(const unsigned int type); 00300 std::vector<OBGenericData*> &GetData() { return(_vdata); } 00302 std::vector<OBGenericData*> GetData(DataOrigin source); 00304 OBDataIterator BeginData() 00305 { return(_vdata.begin()); } 00307 OBDataIterator EndData() 00308 { return(_vdata.end()); } 00310 protected: 00311 std::vector<OBGenericData*> _vdata; 00312 00313 }; 00314 00315 } //namespace OpenBabel 00316 00317 #endif // OB_BASE_H 00318
This file is part of the documentation for Open Babel, version 2.2.0.