Open Babel  3.0
op.h
Go to the documentation of this file.
1 /**********************************************************************
2 op.h - plugin options or operations
3 
4 Copyright (C) 2007 by Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17 ***********************************************************************/
18 
19 #ifndef OB_OP_H
20 #define OB_OP_H
21 
22 #include <openbabel/babelconfig.h>
23 #include <string>
24 #include <map>
25 #include <openbabel/plugin.h>
26 
27 namespace OpenBabel
28 {
29  class OBConversion; //used only as a pointer
30  class OBBase;
31 
32 // Class introduction below
33 class OBAPI OBOp : public OBPlugin
34 {
36 
37 public:
38  typedef const std::map<std::string, std::string> OpMap ;
39 
41  virtual const char* TypeID(){ return "ops"; }
42 
44  //NOTE: the parameters were changed in r3532
45  virtual bool Do(OBBase* pOb, const char* OptionText=NULL, OpMap* pOptions=NULL, OBConversion* pConv=NULL)=0;
46 
48  virtual bool WorksWith(OBBase* pOb)const=0;
49 
51  virtual bool ProcessVec(std::vector<OBBase*>& /* vec */){ return false; }
52 
54  static std::string OpOptions(OBBase* pOb)
55  {
56  std::string s;
58  for(itr=OBPlugin::Begin("ops");itr!=OBPlugin::End("ops");++itr)
59  {
60  OBOp* pOp = dynamic_cast<OBOp*>(itr->second);
61  //ignore ops with IDs that begin with '_' or have "not displayed in GUI" in their first line of description
62  if(*(itr->first)=='_'
63  || OBPlugin::FirstLine(pOp->Description()).find("not displayed in GUI")!=std::string::npos)
64  continue;
65  if(pOp && pOp->WorksWith(pOb))
66  {
67  s += "--";
68  s += itr->first; //ID
69  s += ' ';
70  s += OBPlugin::FirstLine(pOp->Description()) + '\n';
71  }
72  }
73  s += '\n';
74  return s;
75  }
76 
82  static bool DoOps(OBBase* pOb, OpMap* pOptions, OBConversion* pConv)
83  {
84  OpMap::const_iterator itr;
85  for(itr=pOptions->begin();itr!=pOptions->end();++itr)
86  {
87  OBOp* pOp = FindType(itr->first.c_str());
88  if(pOp)
89  if(!pOp->Do(pOb, itr->second.c_str(), pOptions, pConv))
90  return false; //Op has decided molecule should not be output
91  }
92  return true;
93  }
94 };
95 
140 }//namespace
141 
142 #endif
143 
virtual bool WorksWith(OBBase *pOb) const =0
virtual const char * Description()
Required description of a sub-type.
Definition: plugin.h:66
const std::map< std::string, std::string > OpMap
Definition: op.h:38
Base class for all types of dynamic classes discovered at runtime.
Definition: plugin.h:52
Class to convert from one format to another.
Definition: obconversion.h:59
virtual bool Do(OBBase *pOb, const char *OptionText=NULL, OpMap *pOptions=NULL, OBConversion *pConv=NULL)=0
Required function that does the work. Normally return true, unless object is not to be output...
PluginMapType::const_iterator PluginIterator
Definition: plugin.h:60
virtual bool ProcessVec(std::vector< OBBase *> &)
Do something with an array of objects. Used a a callback routine in OpSort, etc.
Definition: op.h:51
static std::string OpOptions(OBBase *pOb)
Definition: op.h:54
#define MAKE_PLUGIN(BaseClass)
Definition: plugin.h:195
Simplify &#39;plugin&#39; classes to be discovered and/or loaded at runtime.
static std::string FirstLine(const char *txt)
Utility function to return only the first line of a string.
Definition: plugin.cpp:194
Operations to modify molecules before output.
Definition: op.h:33
virtual const char * TypeID()
Provides the name of this kind of plugin. Use -L "ops" to list from commandline.
Definition: op.h:41
Base Class.
Definition: base.h:239
static PluginIterator End(const char *PluginID)
Definition: plugin.h:119
static PluginIterator Begin(const char *PluginID)
Definition: plugin.h:111
static bool DoOps(OBBase *pOb, OpMap *pOptions, OBConversion *pConv)
Definition: op.h:82
Global namespace for all Open Babel code.
Definition: alias.h:22