struct  CharPtrLess
 Case insensitive string comparison for PluginMapType key. More...
class  OBPlugin
 Base class for all types of dynamic classes discovered at runtime. More...


file  plugin.h


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




virtual ~OBPlugin ()
virtual const char * Description ()
virtual const char * TypeID ()
virtual bool Display (std::string &txt, const char *param, const char *ID=NULL)
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=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 PluginMapType & GetMap () const =0
static PluginMapType & PluginMap ()
static void LoadAllPlugins ()
static PluginMapType & GetTypeMap (const char *PluginID)
static OBPlugin * BaseFindType (PluginMapType &Map, const char *ID)
std::vector< std::string > EnableStaticPlugins ()


static int AllPluginsLoaded = 0
const char * _id

Detailed Description

/ /


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 babel -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: babel -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) error

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.

Define Documentation

#define MAKE_PLUGIN (   BaseClass  ) 
#define OB_STATIC_PLUGIN (   className,
class className; \
  OBAPI EXTERN className instanceName;

Typedef Documentation

typedef PluginMapType::const_iterator PluginIterator [inherited]

Function Documentation

virtual ~OBPlugin (  )  [inline, virtual, inherited]

Virtual destructor necessary for classes with virtual functions.

virtual const char* Description (  )  [inline, virtual, inherited]

Required description of a sub-type.

Reimplemented in OBFormat, OBGroupContrib, and OpTransform.

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

virtual const char* TypeID (  )  [inline, virtual, inherited]

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

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

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

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.

virtual OBPlugin* MakeInstance ( const std::vector< std::string > &   )  [inline, virtual, inherited]

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

virtual void Init (  )  [inline, virtual, inherited]

Initialize the plugin. The default version does nothing.

OBPlugin * GetPlugin ( const char *  Type,
const char *  ID 
) [static, inherited]

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

const char* GetID (  )  const [inline, inherited]
bool ListAsVector ( const char *  PluginID,
const char *  param,
std::vector< std::string > &  vlist 
) [static, inherited]

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 OBPlugin::List().

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

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

Referenced by OBPlugin::ListAsString().

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

As ListAsVector but returns a string containing the list.

string FirstLine ( const char *  txt  )  [static, inherited]

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

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

static PluginIterator Begin ( const char *  PluginID  )  [inline, static, inherited]

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

static PluginIterator End ( const char *  PluginID  )  [inline, static, inherited]
virtual PluginMapType& GetMap (  )  const [pure virtual, inherited]

Returns the map of the subtypes.

Referenced by OBFormat::RegisterFormat().

static PluginMapType& PluginMap (  )  [inline, static, protected, inherited]

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 OBPlugin::GetPlugin(), OBPlugin::GetTypeMap(), OBPlugin::ListAsVector(), and OBFormat::RegisterFormat().

void LoadAllPlugins (  )  [static, protected, inherited]

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

Referenced by OBPlugin::BaseFindType(), OBPlugin::GetPlugin(), OBPlugin::GetTypeMap(), and OBPlugin::ListAsVector().

OBPlugin::PluginMapType & GetTypeMap ( const char *  PluginID  )  [static, protected, inherited]

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

Referenced by OBPlugin::GetPlugin().

OBPlugin * BaseFindType ( PluginMapType Map,
const char *  ID 
) [static, protected, inherited]

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 OBPlugin::GetPlugin().

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

Variable Documentation

int AllPluginsLoaded = 0 [static, protected, inherited]
const char* _id [protected, inherited]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines