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.org/> 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 #ifdef UNUSED 00032 #elif (__GNUC__ == 4) 00033 # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) 00034 #elif defined(__LCLINT__) 00035 # define UNUSED(x) /*@unused@*/ x 00036 #else 00037 # define UNUSED(x) x 00038 #endif 00039 00040 namespace OpenBabel 00041 { 00042 00043 //Forward declaration of the base class for OBMol OBReaction, OBAtom, etc. 00044 //Declaration later in this file. 00045 class OBBase; 00046 class OBConversion; //used only as pointer 00047 00049 OBAPI std::string OBReleaseVersion(); 00050 00062 namespace OBGenericDataType 00063 { 00064 enum 00065 { 00067 UndefinedData = 0, 00068 00070 PairData = 1, 00071 00073 EnergyData = 2, 00074 00076 CommentData = 3, 00077 00079 ConformerData = 4, 00080 00082 ExternalBondData = 5, 00083 00085 RotamerList = 6, 00086 00088 VirtualBondData = 7, 00089 00091 RingData = 8, 00092 00094 TorsionData = 9, 00095 00097 AngleData = 10, 00098 00100 SerialNums = 11, 00101 00103 UnitCell = 12, 00104 00106 SpinData = 13, 00107 00109 ChargeData = 14, 00110 00112 SymmetryData = 15, 00113 00115 ChiralData = 16, 00116 00118 OccupationData = 17, 00119 00121 DensityData = 18, 00122 00124 ElectronicData = 19, 00125 00127 VibrationData = 20, 00128 00130 RotationData = 21, 00131 00133 NuclearData = 22, 00134 00136 SetData = 23, 00137 00139 GridData = 24, 00140 00142 VectorData = 25, 00143 00145 MatrixData = 26, 00146 00148 StereoData = 27, 00149 00151 DOSData = 28, 00152 00154 ElectronicTransitionData = 29, 00155 00156 // space for up to 2^14 more entries... 00157 00159 CustomData0 = 16384, 00160 CustomData1 = 16385, 00161 CustomData2 = 16386, 00162 CustomData3 = 16387, 00163 CustomData4 = 16388, 00164 CustomData5 = 16389, 00165 CustomData6 = 16390, 00166 CustomData7 = 16391, 00167 CustomData8 = 16392, 00168 CustomData9 = 16393, 00169 CustomData10 = 16394, 00170 CustomData11 = 16395, 00171 CustomData12 = 16396, 00172 CustomData13 = 16397, 00173 CustomData14 = 16398, 00174 CustomData15 = 16399 00175 }; 00176 } // end namespace 00177 enum DataOrigin { 00178 any, 00179 fileformatInput, 00180 userInput, 00181 perceived, 00182 external, 00183 local 00184 }; 00185 00187 // Class introduction in generic.cpp 00188 // This base class declaration has no dependence on mol.h 00189 class OBAPI OBGenericData 00190 { 00191 protected: 00192 std::string _attr; 00193 unsigned int _type; 00194 DataOrigin _source; 00195 public: 00196 OBGenericData(const std::string attr = "undefined", 00197 const unsigned int type = OBGenericDataType::UndefinedData, 00198 const DataOrigin source = any); 00199 //Use default copy constructor and assignment operators 00200 //OBGenericData(const OBGenericData&); 00201 00202 /* Virtual constructors added. see 00203 http://www.parashift.com/c++-faq-lite/abcs.html#faq-22.5 00204 to allow copying given only a base class OBGenericData pointer. 00205 It may be necessary to cast the return pointer to the derived class 00206 type, since we are doing without Covariant Return Types 00207 http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8 00208 00209 A derived class may return NULL if copying is inappropriate */ 00210 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00211 { return NULL; } 00212 virtual ~OBGenericData() {} 00213 //Use default copy constructor and assignment operators 00214 //OBGenericData& operator=(const OBGenericData &src); 00215 00217 void SetAttribute(const std::string &v) 00218 { _attr = v; } 00220 void SetOrigin(const DataOrigin s) { _source = s; } 00222 virtual const std::string &GetAttribute() const 00223 { return(_attr); } 00225 unsigned int GetDataType() const 00226 { return(_type); } 00229 virtual const std::string &GetValue() const 00230 { return _attr; } 00231 virtual DataOrigin GetOrigin() const 00232 { return _source; } 00233 }; 00234 00236 typedef std::vector<OBGenericData*>::iterator OBDataIterator; 00237 00239 // introduction in base.cpp 00240 class OBAPI OBBase 00241 { 00242 public: 00243 virtual ~OBBase() 00244 { 00245 if (!_vdata.empty()) 00246 { 00247 std::vector<OBGenericData*>::iterator m; 00248 for (m = _vdata.begin();m != _vdata.end();m++) 00249 delete *m; 00250 _vdata.clear(); 00251 } 00252 } 00253 00255 virtual bool Clear(); 00256 00262 virtual OBBase* DoTransformations(const std::map<std::string,std::string>* /*pOptions*/, 00263 OBConversion* /*pConv*/) 00264 { 00265 return this; 00266 } 00267 00269 static const char* ClassDescription() 00270 { 00271 return ""; 00272 } 00273 00275 template< class T > 00276 T* CastAndClear(bool clear=true) 00277 { 00278 T* pOb = dynamic_cast<T*>(this); 00279 if(pOb && clear)// Clear only if this is of target class 00280 Clear(); 00281 return pOb; 00282 } 00283 00286 //Currently no title data member in base class. 00287 virtual const char *GetTitle(bool UNUSED(replaceNewlines) = true) const { return "";} 00288 virtual void SetTitle(const char *) {} 00289 00291 00292 00293 bool HasData(const std::string &); 00295 bool HasData(const char *); 00297 bool HasData(const unsigned int type); 00299 void DeleteData(unsigned int type); 00301 void DeleteData(OBGenericData*); 00303 void DeleteData(std::vector<OBGenericData*>&); 00305 bool DeleteData(const std::string& s); 00307 void SetData(OBGenericData *d) 00308 { 00309 if(d) _vdata.push_back(d); 00310 } 00313 void CloneData(OBGenericData *d); 00315 size_t DataSize() const 00316 { return(_vdata.size()); } 00319 OBGenericData *GetData(const unsigned int type); 00321 OBGenericData *GetData(const std::string&); 00323 OBGenericData *GetData(const char *); 00327 std::vector<OBGenericData*> GetAllData(const unsigned int type); 00329 std::vector<OBGenericData*> &GetData() { return(_vdata); } 00331 std::vector<OBGenericData*> GetData(DataOrigin source); 00333 OBDataIterator BeginData() 00334 { return(_vdata.begin()); } 00336 OBDataIterator EndData() 00337 { return(_vdata.end()); } 00339 protected: 00340 std::vector<OBGenericData*> _vdata; 00341 00342 }; 00343 00344 } //namespace OpenBabel 00345 00346 #endif // OB_BASE_H 00347
This file is part of the documentation for Open Babel, version 2.3.