plugin.h
Go to the documentation of this file.
00001 /********************************************************************** 00002 plugin.h - facilitates construction of plugin classes 00003 00004 Copyright (C) 2007 by Chris Morley 00005 00006 This file is part of the Open Babel project. 00007 For more information, see <http://openbabel.org/> 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 General Public License for more details. 00017 ***********************************************************************/ 00018 00019 #ifndef OB_PLUGIN_H 00020 #define OB_PLUGIN_H 00021 00022 #include <openbabel/babelconfig.h> 00023 #include <openbabel/dlhandler.h> 00024 #include <string> 00025 #include <iostream> 00026 #include <vector> 00027 #include <map> 00028 #include <sstream> 00029 #include <cstring> 00030 00031 #ifndef OBERROR 00032 #define OBERROR 00033 #endif 00034 00035 namespace OpenBabel 00036 { 00039 00041 struct OBERROR CharPtrLess : public std::binary_function<const char*,const char*, bool> 00042 { 00043 bool operator()(const char* p1,const char* p2) const 00044 { return strcasecmp(p1,p2)<0; } 00045 }; 00046 00052 class OBERROR OBPlugin 00053 { 00054 public: 00055 00056 //Maps of thistype are used to store 00057 // (a)a list of the plugin types in OBPlugin, and 00058 // (b)a list of the sub-types in each type class derived from OBPlugin. 00059 typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType; 00060 typedef PluginMapType::const_iterator PluginIterator; 00061 00063 virtual ~OBPlugin(){}; 00064 00066 virtual const char* Description() { return NULL;} ; 00067 00069 virtual const char* TypeID(){ return "plugins"; } 00070 00076 virtual bool Display(std::string&txt, const char* param, const char* ID=NULL); 00077 00082 virtual OBPlugin* MakeInstance(const std::vector<std::string>&){return NULL;} 00083 00086 virtual void Init(){}; 00087 00090 static OBPlugin* GetPlugin(const char* Type, const char* ID); 00091 00093 const char* GetID()const{return _id;}; 00094 00098 static bool ListAsVector(const char* PluginID, const char* param, std::vector<std::string>& vlist); 00099 00101 static void List(const char* PluginID, const char* param=NULL, std::ostream* os=&std::cout); 00102 00104 static std::string ListAsString(const char* PluginID, const char* param=NULL); 00105 00107 static std::string FirstLine(const char* txt); 00108 00111 static PluginIterator Begin(const char* PluginID) 00112 { 00113 if( !strcmp(PluginID, "plugins") || GetTypeMap(PluginID)!=PluginMap()) 00114 return GetTypeMap(PluginID).begin(); 00115 else 00116 return PluginMap().end(); 00117 } 00118 00119 static PluginIterator End(const char* PluginID) 00120 { 00121 return GetTypeMap(PluginID).end(); 00122 } 00123 00125 virtual PluginMapType& GetMap() const =0; 00126 00127 protected: 00130 static PluginMapType& PluginMap() 00131 { 00132 static PluginMapType m; 00133 return m; 00134 } 00135 00137 static int AllPluginsLoaded; 00138 00140 static void LoadAllPlugins(); 00141 00143 static PluginMapType& GetTypeMap(const char* PluginID); 00144 00147 static OBPlugin* BaseFindType(PluginMapType& Map, const char* ID); 00148 00149 protected: 00150 const char* _id; 00151 }; 00152 00153 #if defined(__CYGWIN__) || defined(__MINGW32__) 00154 00155 //Macro to be added to definition of the base class 00156 #define MAKE_PLUGIN(BaseClass)\ 00157 protected:\ 00158 static PluginMapType& Map();\ 00159 virtual PluginMapType& GetMap() const {\ 00160 return Map();\ 00161 }\ 00162 public:\ 00163 static BaseClass*& Default() {\ 00164 static BaseClass* d;\ 00165 return d;\ 00166 }\ 00167 BaseClass(const char* ID, bool IsDefault=false) {\ 00168 _id=ID;\ 00169 if (ID&&*ID) {\ 00170 if (IsDefault || Map().empty()) {\ 00171 Default() = this;\ 00172 }\ 00173 if (Map().count(ID) == 0) {\ 00174 Map()[ID] = this;\ 00175 PluginMap()[TypeID()] = this;\ 00176 }\ 00177 }\ 00178 }\ 00179 static BaseClass* FindType(const char* ID) {\ 00180 if (!ID || *ID==0 || *ID==' ') {\ 00181 return Default();\ 00182 }\ 00183 return static_cast<BaseClass*>(BaseFindType(Map(),ID));\ 00184 } 00185 00186 #define PLUGIN_CPP_FILE(BaseClass)\ 00187 OBPlugin::PluginMapType& BaseClass::Map() {\ 00188 static OBPlugin::PluginMapType map;\ 00189 return map;\ 00190 } 00191 00192 #else // __CYGWIN__ || __MINGW32__ 00193 00194 //Macro to be added to definition of the base class 00195 #define MAKE_PLUGIN(BaseClass)\ 00196 protected:\ 00197 static PluginMapType& Map() {\ 00198 static PluginMapType m;\ 00199 return m;\ 00200 }\ 00201 virtual PluginMapType& GetMap() const {\ 00202 return Map();\ 00203 }\ 00204 public:\ 00205 static BaseClass*& Default() {\ 00206 static BaseClass* d;\ 00207 return d;\ 00208 }\ 00209 BaseClass(const char* ID, bool IsDefault=false) {\ 00210 _id=ID;\ 00211 if (ID&&*ID) {\ 00212 if (IsDefault || Map().empty()) {\ 00213 Default() = this;\ 00214 }\ 00215 if (Map().count(ID) == 0) {\ 00216 Map()[ID] = this;\ 00217 PluginMap()[TypeID()] = this;\ 00218 }\ 00219 }\ 00220 }\ 00221 static BaseClass* FindType(const char* ID) {\ 00222 if (!ID || *ID==0 || *ID==' ') {\ 00223 return Default();\ 00224 }\ 00225 return static_cast<BaseClass*>(BaseFindType(Map(),ID));\ 00226 } 00227 00228 #endif // __CYGWIN__ || __MINGW32__ 00229 00358 00366 /*\@}*/ 00367 00368 #ifndef SWIG // Skipped by SWIG (for the moment) 00369 00370 #ifndef USING_DYNAMIC_LIBS 00371 00372 #define OB_STATIC_PLUGIN(className,instanceName) \ 00373 class className; \ 00374 OBAPI EXTERN className instanceName; 00375 00376 // formats 00377 OB_STATIC_PLUGIN(AcesOutputFormat, theAcesOutputFormat) 00378 OB_STATIC_PLUGIN(AcesInputFormat, theAcesInputFormat) 00379 OB_STATIC_PLUGIN(ACRFormat, theACRFormat) 00380 OB_STATIC_PLUGIN(ADFOutputFormat, theADFOutputFormat) 00381 OB_STATIC_PLUGIN(ADFInputFormat, theADFInputFormat) 00382 OB_STATIC_PLUGIN(AlchemyFormat, theAlchemyFormat) 00383 OB_STATIC_PLUGIN(AmberPrepFormat, theAmberPrepFormat) 00384 OB_STATIC_PLUGIN(OBAPIInterface, theOBAPIInterface) 00385 OB_STATIC_PLUGIN(BallStickFormat, theBallStickFormat) 00386 OB_STATIC_PLUGIN(BGFFormat, theBGFFormat) 00387 OB_STATIC_PLUGIN(BoxFormat, theBoxFormat) 00388 OB_STATIC_PLUGIN(CacaoFormat, theCacaoFormat) 00389 OB_STATIC_PLUGIN(CacheFormat, theCacheFormat) 00390 OB_STATIC_PLUGIN(CARFormat, theCARFormat) 00391 OB_STATIC_PLUGIN(CCCFormat, theCCCFormat) 00392 OB_STATIC_PLUGIN(CHEM3D1Format, theCHEM3D1Format) 00393 OB_STATIC_PLUGIN(CHEM3D2Format, theCHEM3D2Format) 00394 OB_STATIC_PLUGIN(ChemDrawBinaryFormat, theChemDrawBinaryFormat) 00395 OB_STATIC_PLUGIN(ChemDrawFormat, theChemDrawFormat) 00396 OB_STATIC_PLUGIN(ChemKinFormat, theChemKinFormat) 00397 OB_STATIC_PLUGIN(CHTFormat, theCHTFormat) 00398 OB_STATIC_PLUGIN(CIFFormat, theCIFFormat) 00399 OB_STATIC_PLUGIN(CopyFormat, theCopyFormat) 00400 OB_STATIC_PLUGIN(CRK2DFormat, theCRK2DFormat) 00401 OB_STATIC_PLUGIN(CRK3DFormat, theCRK3DFormat) 00402 OB_STATIC_PLUGIN(CSRFormat, theCSRFormat) 00403 OB_STATIC_PLUGIN(CSSRFormat, theCSSRFormat) 00404 OB_STATIC_PLUGIN(DlpolyConfigFormat, theDlpolyConfigFormat) 00405 OB_STATIC_PLUGIN(DlpolyHISTORYFormat, theDlpolyHISTORYFormat) 00406 OB_STATIC_PLUGIN(DMolFormat, theDMolFormat) 00407 OB_STATIC_PLUGIN(FASTAFormat, theFASTAFormat) 00408 OB_STATIC_PLUGIN(FastSearchFormat, theFastSearchFormat) 00409 OB_STATIC_PLUGIN(FCHKFormat, theFCHKFormat) 00410 OB_STATIC_PLUGIN(FEATFormat, theFEATFormat) 00411 OB_STATIC_PLUGIN(FenskeZmatFormat, theFenskeZmatFormat) 00412 OB_STATIC_PLUGIN(FHIaimsFormat,theFHIaimsFormat) 00413 OB_STATIC_PLUGIN(FingerprintFormat, theFingerprintFormat) 00414 OB_STATIC_PLUGIN(FreeFormFractionalFormat, theFreeFormFractionalFormat) 00415 OB_STATIC_PLUGIN(GAMESSOutputFormat, theGAMESSOutputFormat) 00416 OB_STATIC_PLUGIN(GAMESSInputFormat, theGAMESSInputFormat) 00417 OB_STATIC_PLUGIN(OBGaussianCubeFormat, theGaussianCubeFormat) 00418 OB_STATIC_PLUGIN(GaussianOutputFormat, theGaussianOutputFormat) 00419 OB_STATIC_PLUGIN(GaussianInputFormat, theGaussianInputFormat) 00420 OB_STATIC_PLUGIN(GaussianZMatrixInputFormat, theGaussianZMatrixInputFormat) 00421 OB_STATIC_PLUGIN(GenBankFormat, theGenBankFormat) 00422 OB_STATIC_PLUGIN(GhemicalFormat, theGhemicalFormat) 00423 OB_STATIC_PLUGIN(GROMOS96Format, theGROMOS96Format) 00424 OB_STATIC_PLUGIN(GULPFormat, theGULPFormat) 00425 OB_STATIC_PLUGIN(HINFormat, theHINFormat) 00426 OB_STATIC_PLUGIN(JaguarOutputFormat, theJaguarOutputFormat) 00427 OB_STATIC_PLUGIN(JaguarInputFormat, theJaguarInputFormat) 00428 OB_STATIC_PLUGIN(MCDLFormat, theMCDLFormat) 00429 OB_STATIC_PLUGIN(MOLFormat, theMOLFormat) 00430 OB_STATIC_PLUGIN(SDFormat, theSDFormat) 00431 OB_STATIC_PLUGIN(OBT41Format, t41Format__) 00432 OB_STATIC_PLUGIN(OBMoldenFormat, moldenFormat__) 00433 OB_STATIC_PLUGIN(mmCIFFormat, themmCIFFormat) 00434 OB_STATIC_PLUGIN(MacroModFormat, theMacroModFormat) 00435 OB_STATIC_PLUGIN(MNAFormat, theMNAFormat) 00436 OB_STATIC_PLUGIN(MOL2Format, theMOL2Format) 00437 OB_STATIC_PLUGIN(MolproOutputFormat, theMolproOutputFormat) 00438 OB_STATIC_PLUGIN(MolproInputFormat, theMolproInputFormat) 00439 OB_STATIC_PLUGIN(MolReportFormat, theMolReportFormat) 00440 OB_STATIC_PLUGIN(MOPACFormat, theMOPACFormat) 00441 OB_STATIC_PLUGIN(MOPACCARTFormat, theMOPACCARTFormat) 00442 OB_STATIC_PLUGIN(MOPACINTFormat, theMOPACINTFormat) 00443 OB_STATIC_PLUGIN(MPDFormat, theMPDFormat) 00444 OB_STATIC_PLUGIN(MPQCFormat, theMPQCFormat) 00445 OB_STATIC_PLUGIN(MPQCInputFormat, theMPQCInputFormat) 00446 OB_STATIC_PLUGIN(MSIFormat, theMSIFormat) 00447 OB_STATIC_PLUGIN(OBMSMSFormat, msmsFormat__) 00448 OB_STATIC_PLUGIN(NulFormat, theNulFormat) 00449 OB_STATIC_PLUGIN(NWChemOutputFormat, theNWChemOutputFormat) 00450 OB_STATIC_PLUGIN(NWChemInputFormat, theNWChemInputFormat) 00451 OB_STATIC_PLUGIN(OBOpenDXCubeFormat, theOpenDXCubeFormat) 00452 OB_STATIC_PLUGIN(OutputFormat, theOutputFormat) 00453 OB_STATIC_PLUGIN(PCModelFormat, thePCModelFormat) 00454 OB_STATIC_PLUGIN(PDBFormat, thePDBFormat) 00455 OB_STATIC_PLUGIN(PDBQTFormat, thePDBQTFormat) 00456 #ifdef HAVE_LIBZ 00457 OB_STATIC_PLUGIN(PNGFormat, thePNGFormat) 00458 #endif 00459 OB_STATIC_PLUGIN(PovrayFormat, thePovrayFormat) 00460 OB_STATIC_PLUGIN(PQRFormat, thePQRFormat) 00461 OB_STATIC_PLUGIN(PQSFormat, thePQSFormat) 00462 OB_STATIC_PLUGIN(PWscfFormat, thePWscfFormat) 00463 OB_STATIC_PLUGIN(QChemOutputFormat, theQChemOutputFormat) 00464 OB_STATIC_PLUGIN(QChemInputFormat, theQChemInputFormat) 00465 OB_STATIC_PLUGIN(ReportFormat, theReportFormat) 00466 OB_STATIC_PLUGIN(SmiReactFormat, theSmiReactFormat) 00467 OB_STATIC_PLUGIN(RXNFormat, theRXNFormat) 00468 OB_STATIC_PLUGIN(ShelXFormat, theShelXFormat) 00469 OB_STATIC_PLUGIN(SMIFormat, theSMIFormat) 00470 OB_STATIC_PLUGIN(CANSMIFormat, theCANSMIFormat) 00471 OB_STATIC_PLUGIN(FIXFormat, theFIXFormat) 00472 OB_STATIC_PLUGIN(SVGFormat, theSVGFormat) 00473 OB_STATIC_PLUGIN(TextFormat, theTextFormat) 00474 OB_STATIC_PLUGIN(ThermoFormat, theThermoFormat) 00475 OB_STATIC_PLUGIN(TinkerFormat, theTinkerFormat) 00476 OB_STATIC_PLUGIN(TitleFormat, theTitleFormat) 00477 OB_STATIC_PLUGIN(TurbomoleFormat, theTurbomoleFormat) 00478 OB_STATIC_PLUGIN(UniChemFormat, theUniChemFormat) 00479 OB_STATIC_PLUGIN(VASPFormat, theVASPFormat) 00480 OB_STATIC_PLUGIN(ViewMolFormat, theViewMolFormat) 00481 OB_STATIC_PLUGIN(XEDFormat, theXEDFormat) 00482 OB_STATIC_PLUGIN(XYZFormat, theXYZFormat) 00483 OB_STATIC_PLUGIN(YOBFormat, theYOBFormat) 00484 OB_STATIC_PLUGIN(ZINDOFormat, theZINDOFormat) 00485 #ifdef HAVE_STATIC_LIBXML 00486 OB_STATIC_PLUGIN(ChemDrawXMLFormat, theChemDrawXMLFormat) 00487 OB_STATIC_PLUGIN(CMLFormat, theCMLFormat) 00488 OB_STATIC_PLUGIN(CMLReactFormat, theCMLReactFormat) 00489 OB_STATIC_PLUGIN(PubChemFormat, thePubChemFormat) 00490 OB_STATIC_PLUGIN(XMLFormat, theXMLFormat) 00491 #endif 00492 #ifdef HAVE_STATIC_INCHI 00493 OB_STATIC_PLUGIN(InChIFormat, theInChIFormat) 00494 #endif 00495 #ifdef HAVE_REGEX_H 00496 OB_STATIC_PLUGIN(GAMESSUKInputFormat, theGAMESSUKInputFormat) 00497 OB_STATIC_PLUGIN(GAMESSUKOutputFormat, theGAMESSUKOutputFormat) 00498 #endif 00499 #ifdef HAVE_RPC_XDR_H 00500 OB_STATIC_PLUGIN(XTCFormat, theXTCFormat) 00501 #endif 00502 00503 // descriptors 00504 OB_STATIC_PLUGIN(CanSmiles, theCanSmiles) 00505 OB_STATIC_PLUGIN(CompoundFilter, dummyCmpFilter) 00506 OB_STATIC_PLUGIN(MWFilter, theMWFilter) 00507 OB_STATIC_PLUGIN(SmartsFilter, firstSmartsFilter) 00508 OB_STATIC_PLUGIN(SmartsFilter, secondSmartsFilter) 00509 OB_STATIC_PLUGIN(TitleFilter, theTitleFilter) 00510 OB_STATIC_PLUGIN(FormulaDescriptor, TheFormulaDescriptor) 00511 //OB_STATIC_PLUGIN(FPCount, theFPCount) 00512 OB_STATIC_PLUGIN(InChIFilter, theInChIFilter) 00513 // smarts descriptors 00514 OB_STATIC_PLUGIN(SmartsDescriptor, theHBD) 00515 OB_STATIC_PLUGIN(SmartsDescriptor, theHBA1) 00516 OB_STATIC_PLUGIN(SmartsDescriptor, theHBA2) 00517 OB_STATIC_PLUGIN(SmartsDescriptor, thenF) 00518 // group contribution descriptors 00519 OB_STATIC_PLUGIN(OBGroupContrib, thelogP) 00520 OB_STATIC_PLUGIN(OBGroupContrib, theTPSA) 00521 OB_STATIC_PLUGIN(OBGroupContrib, theMR) 00522 00523 // fingerprints 00524 OB_STATIC_PLUGIN(fingerprint2, thefingerprint2) 00525 OB_STATIC_PLUGIN(PatternFP, FP3PatternFP) 00526 OB_STATIC_PLUGIN(PatternFP, FP4PatternFP) 00527 00528 // forcefields 00529 OB_STATIC_PLUGIN(OBForceFieldGaff, theForceFieldGaff) 00530 OB_STATIC_PLUGIN(OBForceFieldGhemical, theForceFieldGhemical) 00531 OB_STATIC_PLUGIN(OBForceFieldMMFF94, theForceFieldMMFF94) 00532 OB_STATIC_PLUGIN(OBForceFieldMMFF94, theForceFieldMMFF94s) 00533 OB_STATIC_PLUGIN(OBForceFieldUFF, theForceFieldUFF) 00534 00535 // operations 00536 OB_STATIC_PLUGIN(OpAddInIndex, theOpAddInIndex) 00537 OB_STATIC_PLUGIN(OpAddPolarH, theOpAddPolarH) 00538 OB_STATIC_PLUGIN(OpCanonical, theOpCanonical) 00539 OB_STATIC_PLUGIN(OpFillUC, theOpFillUC) 00540 OB_STATIC_PLUGIN(OpEnergy, theOpEnergy) 00541 OB_STATIC_PLUGIN(OpMinimize, theOpMinimize) 00542 OB_STATIC_PLUGIN(OpGen2D, theOpGen2D) 00543 OB_STATIC_PLUGIN(OpGen3D, theOpGen3D) 00544 OB_STATIC_PLUGIN(OpNewS, theOpNewS) 00545 OB_STATIC_PLUGIN(OpPartialCharge, theOpPartialCharge) 00546 OB_STATIC_PLUGIN(OpReadConformers, theOpReadConformers) 00547 OB_STATIC_PLUGIN(OpSort, theOpSort) 00548 OB_STATIC_PLUGIN(OpExtraOut, theOpExtraOut) 00549 #ifdef HAVE_STATIC_INCHI 00550 OB_STATIC_PLUGIN(OpUnique, theOpUnique) 00551 #endif 00552 #ifdef HAVE_EIGEN 00553 OB_STATIC_PLUGIN(OpConformer, theOpConformer) 00554 #endif 00555 00556 // charges 00557 OB_STATIC_PLUGIN(GasteigerCharges, theGasteigerCharges) 00558 OB_STATIC_PLUGIN(MMFF94Charges, theMMFF94Charges) 00559 #ifdef HAVE_EIGEN 00560 OB_STATIC_PLUGIN(QEqCharges, theQEqCharges) 00561 OB_STATIC_PLUGIN(QTPIECharges, theQTPIECharges) 00562 #endif 00563 00564 OBAPI std::vector<std::string> EnableStaticPlugins(); 00565 00566 #endif // USING_DYNAMIC_LIBS 00567 00568 #endif // SWIG 00569 00570 } // end namespce 00571 00572 #endif