Loading...
Searching...
No Matches
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 *, CharPtrLess > | PluginMapType
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=nullptr)
virtual OBPlugin * | MakeInstance (const std::vector< std::string > &)
virtual void | Init ()
static OBPlugin * | GetPlugin (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=nullptr, std::ostream *os=&std::cout)
static std::string | ListAsString (const char *PluginID, const char *param=nullptr)
static std::string | FirstLine (const char *txt)
static PluginIterator | Begin (const char *PluginID)
static PluginIterator | End (const char *PluginID)
virtual PluginMapType & | GetMap () const =0
static void | LoadAllPlugins ()
static PluginMapType & | PluginMap ()
static PluginMapType & | GetTypeMap (const char *PluginID)
static OBPlugin * | BaseFindType (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 OB_EXTERN className instanceName;
OB_EXTERN
#define OB_EXTERN
Definition atom.h:27

## 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 | ( |  | ) |

inline virtual

Virtual destructor necessary for classes with virtual functions.

## Description()

virtual const char * Description | ( |  | ) |

inline virtual

Required description of a sub-type.

Reimplemented in OBFormat, OBGroupContrib, and OpTransform.

Referenced by Display(), and OBOp::OpOptions().

## TypeID()

virtual const char * TypeID | ( |  | ) |

inline virtual

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

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

## Display()

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

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 OBDescriptor, and OBFormat.

Referenced by OBDescriptor::Display().

## MakeInstance()

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

inline virtual

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 LoadAllPlugins().

## Init()

virtual void Init | ( |  | ) |

inline virtual

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*

Referenced by LoadAllPlugins().

## GetID()

const char * GetID | ( |  | ) | const

inline

Return the ID of the sub-type instance.

Referenced by OBFormat::Display(), Display(), and OBDescriptor::PredictAndSave().

## 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(), OBConversion::GetSupportedOutputFormat(), and List().

## List()

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

static

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

Referenced by ListAsString().

## ListAsString()

string ListAsString | ( | const char * | PluginID,
|  | const char * | param = nullptr )

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 OBFormat::Display(), Display(), and OBOp::OpOptions().

## Begin()

PluginIterator Begin | ( | const char * | PluginID | ) |

inline static

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()

PluginIterator End | ( | const char * | PluginID | ) |

inline static

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

## GetMap()

virtual PluginMapType & GetMap | ( |  | ) | const

pure virtual

Returns the map of the subtypes.

Referenced by OBFormat::RegisterFormat().

## LoadAllPlugins()

void LoadAllPlugins | ( |  | ) |

static

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

Referenced by BaseFindType(), GetMap(), GetPlugin(), GetTypeMap(), and ListAsVector().

## PluginMap()

PluginMapType & PluginMap | ( |  | ) |

inline static protected

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

Referenced by Begin(), GetPlugin(), GetTypeMap(), ListAsVector(), and OBFormat::RegisterFormat().

## GetTypeMap()

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

static protected

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

Referenced by Begin(), End(), and GetPlugin().

## BaseFindType()

OBPlugin * BaseFindType | ( | PluginMapType & | Map,
|  | const char * | ID )

static protected

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

Referenced by GetPlugin().

## EnableStaticPlugins()

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

## Variable Documentation

## AllPluginsLoaded

int AllPluginsLoaded = 0

static protected

Keep a record if all plugins have been loaded.

Referenced by BaseFindType(), GetPlugin(), GetTypeMap(), ListAsVector(), and LoadAllPlugins().

## _id

const char* _id

protected

Referenced by GetID(), and OBFormat::RegisterFormat().