Open Babel  3.0
base.h
Go to the documentation of this file.
1 /**********************************************************************
2 base.h - Base class for OpenBabel objects
3 
4 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
6 
7 This file is part of the Open Babel project.
8 For more information, see <http://openbabel.org/>
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 ***********************************************************************/
19 
20 #ifndef OB_BASE_H
21 #define OB_BASE_H
22 
23 #include <openbabel/babelconfig.h>
24 
25 #include <vector>
26 #include <map>
27 #include <string>
28 #include <iostream>
29 #include <openbabel/tokenst.h>
30 
31 #ifdef UNUSED
32 #elif (__GNUC__ == 4)
33 # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
34 #elif defined(__LCLINT__)
35 # define UNUSED(x) /*@unused@*/ x
36 #else
37 # define UNUSED(x) x
38 #endif
39 
40 namespace OpenBabel
41 {
42 
43  //Forward declaration of the base class for OBMol OBReaction, OBAtom, etc.
44  //Declaration later in this file.
45 class OBBase;
46 class OBConversion; //used only as pointer
47 
49  OBAPI std::string OBReleaseVersion();
50 
62  namespace OBGenericDataType
63  {
64  enum
65  {
68 
70  PairData = 1,
71 
74 
77 
80 
83 
86 
89 
91  RingData = 8,
92 
95 
97  AngleData = 10,
98 
101 
103  UnitCell = 12,
104 
106  SpinData = 13,
107 
110 
113 
114  // 16 - Value unused, formerly ChiralData
115 
118 
121 
124 
127 
130 
133 
135  SetData = 23,
136 
138  GridData = 24,
139 
142 
145 
148 
150  DOSData = 28,
151 
154 
155  // space for up to 2^14 more entries...
156 
158  CustomData0 = 16384,
159  CustomData1 = 16385,
160  CustomData2 = 16386,
161  CustomData3 = 16387,
162  CustomData4 = 16388,
163  CustomData5 = 16389,
164  CustomData6 = 16390,
165  CustomData7 = 16391,
166  CustomData8 = 16392,
167  CustomData9 = 16393,
168  CustomData10 = 16394,
169  CustomData11 = 16395,
170  CustomData12 = 16396,
171  CustomData13 = 16397,
172  CustomData14 = 16398,
173  CustomData15 = 16399
174  };
175  } // end namespace
176  enum DataOrigin {
177  any,
183  };
184 
186  // Class introduction in generic.cpp
187  // This base class declaration has no dependence on mol.h
188  class OBAPI OBGenericData
189  {
190  protected:
191  std::string _attr;
192  unsigned int _type;
194  public:
195  OBGenericData(const std::string attr = "undefined",
196  const unsigned int type = OBGenericDataType::UndefinedData,
197  const DataOrigin source = any);
198  //Use default copy constructor and assignment operators
199  //OBGenericData(const OBGenericData&);
200 
201  /* Virtual constructors added. see
202  http://www.parashift.com/c++-faq-lite/abcs.html#faq-22.5
203  to allow copying given only a base class OBGenericData pointer.
204  It may be necessary to cast the return pointer to the derived class
205  type, since we are doing without Covariant Return Types
206  http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8
207 
208  A derived class may return NULL if copying is inappropriate */
209  virtual OBGenericData* Clone(OBBase* /*parent*/) const
210  { return NULL; }
211  virtual ~OBGenericData() {}
212  //Use default copy constructor and assignment operators
213  //OBGenericData& operator=(const OBGenericData &src);
214 
216  void SetAttribute(const std::string &v)
217  { _attr = v; }
219  void SetOrigin(const DataOrigin s) { _source = s; }
221  virtual const std::string &GetAttribute() const
222  { return(_attr); }
224  unsigned int GetDataType() const
225  { return(_type); }
228  virtual const std::string &GetValue() const
229  { return _attr; }
230  virtual DataOrigin GetOrigin() const
231  { return _source; }
232  };
233 
235  typedef std::vector<OBGenericData*>::iterator OBDataIterator;
236 
238  // introduction in base.cpp
239  class OBAPI OBBase
240  {
241  public:
242  virtual ~OBBase()
243  {
244  if (!_vdata.empty())
245  {
246  std::vector<OBGenericData*>::iterator m;
247  for (m = _vdata.begin();m != _vdata.end();m++)
248  delete *m;
249  _vdata.clear();
250  }
251  }
252 
254  virtual bool Clear();
255 
261  virtual OBBase* DoTransformations(const std::map<std::string,std::string>* /*pOptions*/,
262  OBConversion* /*pConv*/)
263  {
264  return this;
265  }
266 
268  static const char* ClassDescription()
269  {
270  return "";
271  }
272 
274  template< class T >
275  T* CastAndClear(bool clear=true)
276  {
277  T* pOb = dynamic_cast<T*>(this);
278  if(pOb && clear)// Clear only if this is of target class
279  Clear();
280  return pOb;
281  }
282 
285  //Currently no title data member in base class.
286  virtual const char *GetTitle(bool UNUSED(replaceNewlines) = true) const { return "";}
287  virtual void SetTitle(const char *) {}
288 
290 
291  bool HasData(const std::string &);
294  bool HasData(const char *);
296  bool HasData(const unsigned int type);
298  void DeleteData(unsigned int type);
300  void DeleteData(OBGenericData*);
302  void DeleteData(std::vector<OBGenericData*>&);
304  bool DeleteData(const std::string& s);
307  {
308  if(d) _vdata.push_back(d);
309  }
312  void CloneData(OBGenericData *d);
314  size_t DataSize() const
315  { return(_vdata.size()); }
318  OBGenericData *GetData(const unsigned int type);
320  OBGenericData *GetData(const std::string&);
322  OBGenericData *GetData(const char *);
326  std::vector<OBGenericData*> GetAllData(const unsigned int type);
328  std::vector<OBGenericData*> &GetData() { return(_vdata); }
330  std::vector<OBGenericData*> GetData(DataOrigin source);
332  OBDataIterator BeginData()
333  { return(_vdata.begin()); }
335  OBDataIterator EndData()
336  { return(_vdata.end()); }
338  protected:
339  std::vector<OBGenericData*> _vdata;
340 
341  };
342 
343 } //namespace OpenBabel
344 
345 #endif // OB_BASE_H
346 
Spin data, including NMR, atomic and molecular spin, etc.
Definition: base.h:106
Definition: residue.h:336
Vibrational modes, frequencies, etc.
Definition: base.h:126
Base class for generic data.
Definition: base.h:188
Matrix data (i.e., a 3x3 matrix like a rotation or quadrupole moment)
Definition: base.h:144
unsigned int GetDataType() const
Definition: base.h:224
Stereochemistry data (see OBStereoBase)
Definition: base.h:147
static const char * ClassDescription()
Definition: base.h:268
virtual ~OBGenericData()
Definition: base.h:211
Density (cube) data and surfaces.
Definition: base.h:120
virtual OBGenericData * Clone(OBBase *) const
Definition: base.h:209
Info. for storing bonds to atoms yet to be added, i.e. OBVirtualBond.
Definition: base.h:88
Class to convert from one format to another.
Definition: obconversion.h:59
Custom (user-defined data)
Definition: base.h:158
Perceived by Open Babel library methods.
Definition: base.h:180
virtual OBBase * DoTransformations(const std::map< std::string, std::string > *, OBConversion *)
Definition: base.h:261
virtual const std::string & GetAttribute() const
Definition: base.h:221
Crystallographic unit cell data, i.e., OBUnitCell.
Definition: base.h:103
virtual ~OBBase()
Definition: base.h:242
std::vector< OBGenericData * > _vdata
Custom data.
Definition: base.h:339
void SetData(OBGenericData *d)
Adds a data object; does nothing if d==NULL.
Definition: base.h:306
unsigned int _type
attribute type – declared for each subclass
Definition: base.h:192
Arbitrary partial and total charges, dipole moments, etc.
Definition: base.h:109
OBDataIterator BeginData()
Definition: base.h:332
Information for generating & manipulating rotamers, i.e. OBRotamerList.
Definition: base.h:85
Arbitrary information about conformers, i.e., OBConformerData.
Definition: base.h:79
Electronic transition data (e.g., UV/Vis, excitation energies, etc.)
Definition: base.h:153
Rotational energy information.
Definition: base.h:129
Not for routine external use (e.g. in sdf or cml properties)
Definition: base.h:182
Set Data (a set of OBGenericData)
Definition: base.h:135
Grid Data (e.g., 3D grids of data a.k.a. cubes)
Definition: base.h:138
std::string OBReleaseVersion()
Definition: base.cpp:31
DataOrigin
Definition: base.h:176
Storing text comments (one per molecule, atom, bond, etc.) (for other data, e.g., author...
Definition: base.h:76
Bond data external to OpenBabel, i.e., OBExternalBond, OBExternalBondData.
Definition: base.h:82
Arbitrary key/value data, i.e., OBPairData.
Definition: base.h:70
Nuclear transitions (e.g., decay, capture, fission, fusion)
Definition: base.h:132
size_t DataSize() const
Definition: base.h:314
OBDataIterator EndData()
Definition: base.h:335
void SetAttribute(const std::string &v)
Set the attribute (key), which can be used to retrieve this data.
Definition: base.h:216
Information on rings in a molecule, i.e., OBRingData.
Definition: base.h:91
virtual void SetTitle(const char *)
Definition: base.h:287
Unknown data type (default)
Definition: base.h:67
Atomic and molecular occupation data (e.g., for crystal structures)
Definition: base.h:117
Density of States data (fermi energy and energy vs. density data)
Definition: base.h:150
Read from an input file.
Definition: base.h:178
Added by an external program.
Definition: base.h:181
Vector Data (i.e., one vector like a dipole moment)
Definition: base.h:141
Symmetry data – point and space groups, transforms, etc. i.e., OBSymmetryData.
Definition: base.h:112
Electronic levels, redox states, orbitals, etc.
Definition: base.h:123
DataOrigin _source
source of data for accounting
Definition: base.h:193
virtual DataOrigin GetOrigin() const
Definition: base.h:230
virtual const std::string & GetValue() const
Base class returns a default value (the attribute type) but should never be called.
Definition: base.h:228
Residue serial numbers.
Definition: base.h:100
virtual const char * GetTitle(bool replaceNewlines=true) const
Base type does nothing Made virtual around r3535 to simplify code which passes around OBBase*...
Definition: base.h:286
Bond angles in a molecule, i.e., OBAngle, OBAngleData.
Definition: base.h:97
std::vector< OBGenericData * > & GetData()
Definition: base.h:328
std::vector< OBGenericData * >::iterator OBDataIterator
A standard iterator over vectors of OBGenericData (e.g., inherited from OBBase)
Definition: base.h:235
Undefined or unspecified (default)
Definition: base.h:177
Base Class.
Definition: base.h:239
T * CastAndClear(bool clear=true)
By default clears the object. Called from ReadMolecule of most format classes.
Definition: base.h:275
Added by the user.
Definition: base.h:179
std::string _attr
attribute tag (e.g., "UnitCell", "Comment" or "Author")
Definition: base.h:191
Energetics data (e.g., total energy, heat of formation, etc.)
Definition: base.h:73
Tokenize strings, open data files.
Information about torsion/dihedral angles, i.e., OBTorsionData and OBTorsion.
Definition: base.h:94
void SetOrigin(const DataOrigin s)
Set the origin of this data, which can be used to filter the data.
Definition: base.h:219
Global namespace for all Open Babel code.
Definition: alias.h:22