Loading...
Searching...
No Matches
op.h
Go to the documentation of this file.
/**********************************************************************
op.h - plugin options or operations
Copyright (C) 2007 by Chris Morley
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
***********************************************************************/
#ifndef OB_OP_H
#define OB_OP_H
#include <openbabel/babelconfig.h>
#include <string>
#include <map>
#include <openbabel/plugin.h>
namespace OpenBabel
{
class OBConversion; //used only as a pointer
class OBBase;
// Class introduction below
class OBAPI OBOp : public OBPlugin
{
MAKE_PLUGIN(OBOp);
public:
typedef const std::map<std::string, std::string> OpMap ;
virtual const char* TypeID(){ return "ops"; }
//NOTE: the parameters were changed in r3532
virtual bool Do(OBBase* pOb, const char* OptionText=nullptr, OpMap* pOptions=nullptr, OBConversion* pConv=nullptr)=0;
virtual bool WorksWith(OBBase* pOb)const=0;
virtual bool ProcessVec(std::vector<OBBase*>& /* vec */){ return false; }
static std::string OpOptions(OBBase* pOb)
{
std::string s;
OBPlugin::PluginIterator itr;
for(itr=OBPlugin::Begin("ops");itr!=OBPlugin::End("ops");++itr)
{
OBOp* pOp = dynamic_cast<OBOp*>(itr->second);
//ignore ops with IDs that begin with '_' or have "not displayed in GUI" in their first line of description
if(*(itr->first)=='_'
|| OBPlugin::FirstLine(pOp->Description()).find("not displayed in GUI")!=std::string::npos)
continue;
if(pOp && pOp->WorksWith(pOb))
{
s += "--";
s += itr->first; //ID
s += ' ';
s += OBPlugin::FirstLine(pOp->Description()) + '\n';
}
}
s += '\n';
return s;
}
static bool DoOps(OBBase* pOb, OpMap* pOptions, OBConversion* pConv)
{
OpMap::const_iterator itr;
for(itr=pOptions->begin();itr!=pOptions->end();++itr)
{
OBOp* pOp = FindType(itr->first.c_str());
if(pOp)
if(!pOp->Do(pOb, itr->second.c_str(), pOptions, pConv))
return false; //Op has decided molecule should not be output
}
return true;
}
};
}//namespace
#endif
OpenBabel::OBBase
Base Class.
Definition base.h:240
OpenBabel::OBConversion
Class to convert from one format to another.
Definition obconversion.h:60
OpenBabel::OBOp
Operations to modify molecules before output.
Definition op.h:34
OpenBabel::OBOp::DoOps
static bool DoOps(OBBase *pOb, OpMap *pOptions, OBConversion *pConv)
Definition op.h:82
OpenBabel::OBOp::Do
virtual bool Do(OBBase *pOb, const char *OptionText=nullptr, OpMap *pOptions=nullptr, OBConversion *pConv=nullptr)=0
Required function that does the work. Normally return true, unless object is not to be output.
OpenBabel::OBOp::OpMap
const std::map< std::string, std::string > OpMap
Definition op.h:38
OpenBabel::OBOp::OpOptions
static std::string OpOptions(OBBase *pOb)
Definition op.h:54
OpenBabel::OBOp::WorksWith
virtual bool WorksWith(OBBase *pOb) const =0
OpenBabel::OBOp::ProcessVec
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
OpenBabel::OBOp::TypeID
virtual const char * TypeID()
Provides the name of this kind of plugin. Use -L "ops" to list from commandline.
Definition op.h:41
OpenBabel::OBPlugin
Base class for all types of dynamic classes discovered at runtime.
Definition plugin.h:53
OpenBabel::OBPlugin::Begin
static PluginIterator Begin(const char *PluginID)
Definition plugin.h:111
OpenBabel::OBPlugin::FirstLine
static std::string FirstLine(const char *txt)
Utility function to return only the first line of a string.
Definition plugin.cpp:194
OpenBabel::OBPlugin::PluginIterator
PluginMapType::const_iterator PluginIterator
Definition plugin.h:60
OpenBabel::OBPlugin::End
static PluginIterator End(const char *PluginID)
Definition plugin.h:119
OpenBabel::OBPlugin::Description
virtual const char * Description()
Required description of a sub-type.
Definition plugin.h:66
MAKE_PLUGIN
#define MAKE_PLUGIN(BaseClass)
Definition plugin.h:195
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
plugin.h
Simplify 'plugin' classes to be discovered and/or loaded at runtime.