Plugins

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

Classes | Files | Defines | Typedefs | Functions | Variables
Plugins

## Classes
struct | CharPtrLess
| Case insensitive string comparison for PluginMapType key. More...
class | OBPlugin
| Base class for all types of dynamic classes discovered at runtime. More...
## Files
file | plugin.h
## Defines
#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=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 PluginMapType & | GetTypeMap (const char *PluginID)
static OBPlugin * | BaseFindType (PluginMapType &Map, const char *ID)
std::vector< std::string > | EnableStaticPlugins ()
## Variables
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 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)
         ...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.

## Define Documentation

#define MAKE_PLUGIN | ( |  | BaseClass | ) |

Value:

    protected:\
    static PluginMapType& Map(){static PluginMapType m;return m;}\
    virtual PluginMapType& GetMap()const{return Map();}\
    public:\
    static BaseClass*& Default(){static BaseClass* d;return d;}\
      BaseClass(const char* ID, bool IsDefault=false)\
     {_id=ID;if(ID&&*ID){if(IsDefault || Map().empty()) Default() = this;\
     Map()[ID]=this;PluginMap()[TypeID()] =this;}}\
    static BaseClass* FindType(const char* ID)\
     {if(!ID || *ID==0 || *ID==' ') return Default();\
     return static_cast<BaseClass*>(BaseFindType(Map(),ID));}

#define OB_STATIC_PLUGIN | ( |  | className,
|  |  | instanceName
| ) |  |

Value:

    class className; \
      OBAPI EXTERN className instanceName;

## Typedef Documentation

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

typedef PluginMapType::const_iterator PluginIterator

## Function Documentation

bool operator() | ( | const char * | p1,
|  | const char * | p2
| ) |  | const`[inline]`

virtual ~OBPlugin | ( |  | ) | `[inline, virtual]`

Virtual destructor necessary for classes with virtual functions.

virtual const char* Description | ( |  | ) | `[inline, virtual]`

Required description of a sub-type.

Reimplemented in OBFormat, OBGroupContrib, and OpTransform.

Referenced by OBOp::OpOptions().

virtual const char* TypeID | ( |  | ) | `[inline, virtual]`

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

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

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.

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 OBConversion::LoadFormatFiles().

virtual void Init | ( |  | ) | `[inline, virtual]`

Initialize the plugin. The default version does nothing.

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 OBConversion::LoadFormatFiles().

const char* GetID | ( |  | ) | const`[inline]`

Return the ID of the sub-type instance.

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

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.

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

As ListAsVector but returns a string containing the list.

string FirstLine | ( | const char * | txt | ) | `[static]`

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

Referenced by OBOp::OpOptions().

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

static PluginIterator End | ( | const char * | PluginID | ) | `[inline, static]`

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

virtual PluginMapType& GetMap | ( |  | ) | const`[pure virtual]`

Returns the map of the subtypes.

Referenced by OBPlugin::ListAsVector().

static 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.

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

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

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.

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

## Variable Documentation

const char* _id`[protected]`

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines