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-2005 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 "babelconfig.h"
00024 
00025 #include <vector>
00026 #include <map>
00027 
00028 #if HAVE_IOSTREAM
00029 #include <iostream>
00030 #elif HAVE_IOSTREAM_H
00031 #include <iostream.h>
00032 #endif
00033 
00034 namespace OpenBabel
00035 {
00036 
00037 class OBBase;
00038 class OBNodeBase;
00039 class OBEdgeBase;
00040 class OBGraphBase;
00041 
00047 class OBAPI OBBase
00048 {
00049 public:
00050     virtual ~OBBase()
00051     {}
00052     ; //NF
00053     virtual OBBase* DoTransformations(const std::map<std::string,std::string>*pOptions)
00054     {
00055         return this;
00056     } //NF Base type does nothing
00057     static const char* ClassDescription()
00058     {
00059         return "";
00060     } //NF
00061 
00062 };
00063 
00068 class OBAPI OBNodeBase : public OBBase
00069 {
00070 protected:
00072     unsigned short int  _idx;
00074     OBGraphBase        *_parent;
00078     std::vector<OBEdgeBase*> _vbond;
00079 
00080 public:
00082     bool Visit;
00083 
00085     OBNodeBase()
00086     {
00087         Visit = false;
00088     }
00090     virtual ~OBNodeBase()
00091     {}
00092     virtual unsigned int  GetIdx()                   const
00093     {
00094         return(_idx);
00095     }
00097     void                  SetIdx(int idx)
00098     {
00099         _idx = idx;
00100     }
00101     virtual OBGraphBase  *GetParent()
00102     {
00103         return(_parent);
00104     }
00106     void                  SetParent(OBGraphBase*);
00108     void                  AddEdge(OBEdgeBase *b)
00109     {
00110         _vbond.push_back(b);
00111     }
00113     virtual unsigned int  GetValence()               const
00114     {
00115         return(_vbond.size());
00116     }
00118     OBNodeBase           *BeginNbr(std::vector<OBEdgeBase*>::iterator&);
00119     OBNodeBase           *NextNbr(std::vector<OBEdgeBase*>::iterator&);
00121     OBEdgeBase           *Begin(std::vector<OBEdgeBase*>::iterator&);
00122     OBEdgeBase           *Next(std::vector<OBEdgeBase*>::iterator&);
00124     virtual bool          IsConnected(OBNodeBase*);
00125 
00127     void Error(int f)
00128     {
00129         std::cerr << "atom vf called = " << f << std::endl;
00130     }
00136     virtual int           GetFormalCharge()          const
00137     {
00138         ((OBNodeBase*)this)->Error(1);
00139         return(0);
00140     }
00141     virtual unsigned int  ExplicitHydrogenCount()    const
00142     {
00143         ((OBNodeBase*)this)->Error(22);
00144         return(0);
00145     }
00146     virtual unsigned int  ImplicitHydrogenCount()    const
00147     {
00148         ((OBNodeBase*)this)->Error(22);
00149         return(0);
00150     }
00151     virtual unsigned int  GetImplicitValence()       const
00152     {
00153         ((OBNodeBase*)this)->Error(3);
00154         return(0);
00155     }
00156     virtual unsigned int  GetHvyValence()            const
00157     {
00158         ((OBNodeBase*)this)->Error(4);
00159         return(0);
00160     }
00161     virtual unsigned int  KBOSum()                const
00162     {
00163         ((OBNodeBase*)this)->Error(5);
00164         return(0);
00165     }
00166     virtual unsigned int  GetHyb()                   const
00167     {
00168         ((OBNodeBase*)this)->Error(6);
00169         return(0);
00170     }
00171     virtual unsigned int  MemberOfRingCount()        const
00172     {
00173         ((OBNodeBase*)this)->Error(7);
00174         return(0);
00175     }
00176     virtual unsigned int  GetAtomicNum()                         const
00177     {
00178         ((OBNodeBase*)this)->Error(8);
00179         return(0);
00180     }
00181     virtual void          SetMatch(OBNodeBase*)
00182     {}
00183     virtual void          SetAromatic()
00184     {}
00185     virtual bool          IsInRingSize(int)          const
00186     {
00187         ((OBNodeBase*)this)->Error(9);
00188         return(false);
00189     }
00190     virtual bool          IsAromatic()               const
00191     {
00192         ((OBNodeBase*)this)->Error(10);
00193         return(false);
00194     }
00195     virtual bool          IsInRing()                 const
00196     {
00197         ((OBNodeBase*)this)->Error(11);
00198         return(false);
00199     }
00200     virtual bool          Eval(OBNodeBase*)          const
00201     {
00202         ((OBNodeBase*)this)->Error(12);
00203         return(false);
00204     }
00205     virtual OBNodeBase   *GetMatch()
00206     {
00207         ((OBNodeBase*)this)->Error(13);
00208         return(NULL);
00209     }
00211 };
00212 
00217 class OBAPI OBEdgeBase : public OBBase
00218 {
00219 protected:
00221     unsigned short int _idx;
00222     OBNodeBase        *_bgn;     
00223     OBNodeBase        *_end;     
00224 
00225     OBGraphBase       *_parent;
00226 public:
00227     bool Visit;
00228 
00230     OBEdgeBase()
00231     {
00232         Visit = false;
00233         _bgn = _end = NULL;
00234     }
00236     OBEdgeBase(OBNodeBase *bgn,OBNodeBase *end)
00237     {}
00239     virtual ~OBEdgeBase()
00240     {}
00241 
00242     virtual OBGraphBase* GetParent()
00243     {
00244         return(_parent);
00245     }
00246     void SetParent(OBGraphBase*);
00247     unsigned int GetIdx()
00248     {
00249         return(_idx);
00250     }
00251     void SetIdx(int idx)
00252     {
00253         _idx = idx;
00254     }
00255     void SetBgn(OBNodeBase *n)
00256     {
00257         _bgn = n;
00258     }
00259     void SetEnd(OBNodeBase *n)
00260     {
00261         _end = n;
00262     }
00263     void SwapEnds()
00264     {
00265         std::swap(_bgn,_end);
00266     }
00267     OBNodeBase *GetBgn()
00268     {
00269         return(_bgn);
00270     }
00271     OBNodeBase *GetEnd()
00272     {
00273         return(_end);
00274     }
00275 
00276     void Error(int f)
00277     {
00278         std::cerr << "bond vf err = " << f << std::endl;
00279     }
00285     virtual void SetClosure()
00286     {}
00287     virtual bool IsAromatic()      const
00288     {
00289         ((OBEdgeBase*)this)->Error(1);
00290         return(false);
00291     }
00292     virtual bool IsInRing()        const
00293     {
00294         ((OBEdgeBase*)this)->Error(2);
00295         return(false);
00296     }
00297     virtual bool IsClosure()
00298     {
00299         ((OBEdgeBase*)this)->Error(3);
00300         return(false);
00301     }
00302     virtual bool Eval(OBEdgeBase*)
00303     {
00304         ((OBEdgeBase*)this)->Error(4);
00305         return(false);
00306     }
00307     virtual unsigned int  GetBO()  const
00308     {
00309         ((OBEdgeBase*)this)->Error(5);
00310         return(0);
00311     }
00313 };
00314 
00320 class OBAPI OBGraphBase : public OBBase
00321 {
00322 protected:
00323     bool                 _vlock;
00324     std::vector<OBNodeBase*>  _vatom;
00325     std::vector<OBEdgeBase*>  _vbond;
00326 public:
00327     OBGraphBase()
00328     {
00329         _vlock = false;
00330         _vatom.clear();
00331         _vbond.clear();
00332     }
00333     OBGraphBase(const OBGraphBase &src) : OBBase() { }
00334     virtual     ~OBGraphBase()          { }
00335     unsigned int NumNodes()
00336     {
00337         return(_vatom.empty() ? 0 : _vatom.size());
00338     }
00339     unsigned int NumEdges()
00340     {
00341         return(_vbond.empty() ? 0 : _vbond.size());
00342     }
00343     void        ResetVisitFlags();
00344     bool        SetVisitLock(bool);
00345     bool        GetVisitLock()
00346     {
00347         return(_vlock);
00348     }
00349     OBNodeBase *Begin(std::vector<OBNodeBase*>::iterator&);
00350     OBNodeBase *Next(std::vector<OBNodeBase*>::iterator&);
00351     OBEdgeBase *Begin(std::vector<OBEdgeBase*>::iterator&);
00352     OBEdgeBase *Next(std::vector<OBEdgeBase*>::iterator&);
00353         
00354 /*The following (placeholder) routines removed to avoid finding solution to
00355 iterators being illegally returned as NULL
00356     //substructure search functions
00357     virtual bool SingleMatch()                  const
00358     {
00359         return(false);
00360     }
00361     virtual void SetSingleMatch(bool)
00362     {}
00363     virtual bool FinishedMatch()                const
00364     {
00365         return(false);
00366     }
00367     virtual void SetFinishedMatch(bool)
00368     {}
00369     virtual void ClearMatches()
00370     {}
00371     virtual void PushBack(std::vector<OBNodeBase*>&)
00372     {}
00373     virtual void PrepForMatch()
00374     {}
00375         virtual std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator BgnMatch()
00376     {
00377         return((std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator) NULL);
00378     }
00379     virtual std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator EndMatch()
00380     {
00381         return((std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator) NULL);
00382     }
00383         virtual OBNodeBase *GetFirstSeed()
00384     {
00385         return((OBNodeBase*)NULL);
00386     }
00387     bool Match(OBGraphBase &,bool singleMatch=false);
00388     bool Match(OBGraphBase &,
00389                std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator,
00390                std::vector<OBEdgeBase*>::iterator);
00391 */
00392 };
00393 
00394 } //namespace OpenBabel
00395 
00396 #endif // OB_BASE_H
00397