base.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 base.h - Base classes to build a graph
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 
00028 #include <iostream>
00029 
00030 // Needed for the OBGenericData handling in this class
00031 // (can't just forward declare it.)
00032 #include <openbabel/generic.h>
00033 
00034 namespace OpenBabel
00035 {
00036 
00038   typedef std::vector<OBGenericData*>::iterator OBDataIterator;
00039   
00041   // introduction in base.cpp
00042   class OBAPI OBBase
00043     {
00044     public:
00045       virtual ~OBBase()
00046         {
00047           if (!_vdata.empty())
00048             {
00049               std::vector<OBGenericData*>::iterator m;
00050               for (m = _vdata.begin();m != _vdata.end();m++)
00051                 delete *m;
00052               _vdata.clear();
00053             }
00054         }
00055 
00057       virtual bool Clear();
00058 
00063       virtual OBBase* DoTransformations(const std::map<std::string,std::string>* /*pOptions*/)
00064         {
00065           return this;
00066         } 
00067 
00068       //Base type does nothing
00070       static const char* ClassDescription()
00071         {
00072           return "";
00073         } 
00074 
00076       template< class T >
00077       T* CastAndClear(bool clear=true)
00078         {
00079           T* pOb = dynamic_cast<T*>(this);
00080           if(pOb && clear)// Clear only if this is of target class
00081             Clear();
00082           return pOb;
00083         };
00084 
00085 
00087 
00088 
00089       bool                              HasData(const std::string &);
00091       bool                              HasData(const char *);
00093       bool                              HasData(const unsigned int type);
00095       void                              DeleteData(unsigned int type);
00097       void                              DeleteData(OBGenericData*);
00099       void                              DeleteData(std::vector<OBGenericData*>&);
00101       void                              SetData(OBGenericData *d)
00102         {
00103           if(d) _vdata.push_back(d);
00104         }
00106       unsigned int                      DataSize() const 
00107         { return(_vdata.size()); }
00110       OBGenericData                    *GetData(const unsigned int type);
00112       OBGenericData                    *GetData(const std::string&);
00114       OBGenericData                    *GetData(const char *);
00116       std::vector<OBGenericData*>      &GetData() { return(_vdata); }
00118       std::vector<OBGenericData*>      GetData(DataOrigin source);
00120       OBDataIterator  BeginData()
00121         { return(_vdata.begin());        }
00123       OBDataIterator  EndData()
00124         { return(_vdata.end());          }
00126     protected:
00127       std::vector<OBGenericData*> _vdata; 
00128 
00129     };
00130 
00131 } //namespace OpenBabel
00132 
00133 #endif // OB_BASE_H
00134