Open Babel  3.0
Files | Classes | Macros | Typedefs | Functions | Variables
Plugins

Files

file  plugin.h
 

Classes

struct  CharPtrLess
 
class  OBPlugin
 

Macros

#define MAKE_PLUGIN(BaseClass)
 
#define OB_STATIC_PLUGIN(className, instanceName)
 

Typedefs

typedef std::map< const char *, OBPlugin *, CharPtrLessPluginMapType
 
typedef PluginMapType::const_iterator PluginIterator
 

Functions

bool operator() (const char *p1, const char *p2) const
 
virtual ~OBPlugin ()
 
virtual const char * Description ()
 
virtual const char * TypeID ()
 
virtual bool Display (std::string &txt, const char *param, const char *ID=NULL)
 
virtual OBPluginMakeInstance (const std::vector< std::string > &)
 
virtual void Init ()
 
static OBPluginGetPlugin (const char *Type, const char *ID)
 
const char * GetID () const
 
static bool ListAsVector (const char *PluginID, const char *param, std::vector< std::string > &vlist)
 
static void List (const char *PluginID, const char *param=NULL, std::ostream *os=&std::cout)
 
static std::string ListAsString (const char *PluginID, const char *param=NULL)
 
static std::string FirstLine (const char *txt)
 
static PluginIterator Begin (const char *PluginID)
 
static PluginIterator End (const char *PluginID)
 
virtual PluginMapTypeGetMap () const =0
 
static void LoadAllPlugins ()
 
static PluginMapTypePluginMap ()
 
static PluginMapTypeGetTypeMap (const char *PluginID)
 
static OBPluginBaseFindType (PluginMapType &Map, const char *ID)
 
std::vector< std::string > EnableStaticPlugins ()
 

Variables

static int AllPluginsLoaded = 0
 
const char * _id
 

Detailed Description

/ /

Plugins

Plugins are a way of extending OpenBabel without having to alter any of the existing code. They may be built as shared libraries (DLLs with an extension .obf or .so files in a specified location) and distributed separately, but plugin classes can also be in the main code. In both cases they are discovered at startup when a global instance of the plugin class is instantiated. It iss registered by its constructor and is added to a static record of all the plugins of its particular type that are currently loaded.There are two levels of plugin. The top layer (at the time of writing) are: formats descriptors fingerprints forcefields charges ops loaders but additional types can be added without disturbing the main API. At runtime obabel -L will list the top level of plugins. They typically are abstract classes with virtual functions that define an interface for that type. Classes derived from these are the second layer of plugins, and can be listed at runtime like, for instance: obabel -L formats cml where formats is the top level of plugin and cml is the id of a derived class of this type.The top level of plugins will usually have their interfaces declared in header files compiled with the main API. The second level of plugin will typically not be known to the API at compile time, usually will not have a header file and must be accessed indirectly, to allow for the possibility that they may not be loaded:

OBOp* pOp = OBOp::FindType("gen3D");
if(!pOp)
...report error
pOp->Do(mol);

This retrieves the global instance of the plugin. This is usually adequate but making a new instance may be appropriate in some cases.Instances of some plugin classes can be constructed at startup from information in a text file and used in the same way as those defined in code. See OBDefine. This is appropriate for some classes that differ only by the datafile or SMARTS strings they use.

Macro Definition Documentation

◆ MAKE_PLUGIN

#define MAKE_PLUGIN (   BaseClass)

◆ OB_STATIC_PLUGIN

#define OB_STATIC_PLUGIN (   className,
  instanceName 
)
Value:
class className; \
OBAPI EXTERN className instanceName;

Typedef Documentation

◆ PluginMapType

typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType

◆ PluginIterator

typedef PluginMapType::const_iterator PluginIterator

Function Documentation

◆ operator()()

bool operator() ( const char *  p1,
const char *  p2 
) const
inline

◆ ~OBPlugin()

virtual ~OBPlugin ( )
inlinevirtual

Virtual destructor necessary for classes with virtual functions.

◆ Description()

virtual const char* Description ( )
inlinevirtual

Required description of a sub-type.

Reimplemented in OBFormat, OBGroupContrib, and OpTransform.

Referenced by OBOp::OpOptions().

◆ TypeID()

virtual const char* TypeID ( )
inlinevirtual

Redefined by each plugin type: "formats", "fingerprints", etc.

Reimplemented in OBForceField, OBFormat, OBOp, OBDescriptor, and OBChargeModel.

◆ Display()

bool Display ( std::string &  txt,
const char *  param,
const char *  ID = NULL 
)
virtual

Write information on a plugin class to the string txt. Return false if not written. The default implementation outputs: the ID, a tab character, and the first line of the Description. The param string can be used in derived types to provide different outputs.

Reimplemented in OBFormat, and OBDescriptor.

◆ MakeInstance()

virtual OBPlugin* MakeInstance ( const std::vector< std::string > &  )
inlinevirtual

Make a new instance of the class. See OpTransform, OBGroupContrib, SmartsDescriptor classes for derived versions. Usually, the first parameter is the classname, the next three are parameters(ID, filename, description) for a constructor, and the rest data.

Reimplemented in OBGroupContrib, and OpTransform.

Referenced by OBPlugin::LoadAllPlugins().

◆ Init()

virtual void Init ( )
inlinevirtual

Initialize the plugin. The default version does nothing.

◆ GetPlugin()

OBPlugin * GetPlugin ( const char *  Type,
const char *  ID 
)
static

Get a pointer to a plugin from its type and ID. Return NULL if not found. If Type is NULL, search all types. Not cast to Type*

◆ GetID()

const char* GetID ( ) const
inline

Return the ID of the sub-type instance.

◆ ListAsVector()

bool ListAsVector ( const char *  PluginID,
const char *  param,
std::vector< std::string > &  vlist 
)
static

Output a list of sub-type classes of the the type PluginID, or, if PluginID is "plugins" or empty, a list of the base types. If PluginID is not recognized or is NULL, the base types are output and the return is false.

Referenced by OBConversion::GetSupportedInputFormat(), and OBConversion::GetSupportedOutputFormat().

◆ List()

void List ( const char *  PluginID,
const char *  param = NULL,
std::ostream *  os = &std::cout 
)
static

As ListAsVector but sent to an ostream with a default of cout if not specified.

◆ ListAsString()

string ListAsString ( const char *  PluginID,
const char *  param = NULL 
)
static

As ListAsVector but returns a string containing the list.

◆ FirstLine()

string FirstLine ( const char *  txt)
static

Utility function to return only the first line of a string.

Referenced by OBOp::OpOptions().

◆ Begin()

static PluginIterator Begin ( const char *  PluginID)
inlinestatic

Return an iterator at the start of the map of the plugin types PluginID or, if there is no such map, the end of the top level plugin map.

Referenced by OBConversion::GetNextFormat(), and OBOp::OpOptions().

◆ End()

static PluginIterator End ( const char *  PluginID)
inlinestatic

◆ GetMap()

virtual PluginMapType& GetMap ( ) const
pure virtual

Returns the map of the subtypes.

◆ LoadAllPlugins()

void LoadAllPlugins ( )
static

Load all plugins (formats, fingerprints, forcefields etc.)

◆ PluginMap()

static PluginMapType& PluginMap ( )
inlinestaticprotected

Returns a reference to the map of the plugin types. Is a function rather than a static member variable to avoid initialization problems.

◆ GetTypeMap()

OBPlugin::PluginMapType & GetTypeMap ( const char *  PluginID)
staticprotected

Returns the map of a particular plugin type, e.g. GetMapType("fingerprints")

◆ BaseFindType()

OBPlugin * BaseFindType ( PluginMapType Map,
const char *  ID 
)
staticprotected

Returns the type with the specified ID, or NULL if not found. Needs to be cast to the appropriate class in the calling routine.

◆ EnableStaticPlugins()

std::vector< std::string > EnableStaticPlugins ( )

Variable Documentation

◆ AllPluginsLoaded

int AllPluginsLoaded = 0
staticprotected

Keep a record if all plugins have been loaded.

◆ _id

const char* _id
protected