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 <string> 00024 #include <iostream> 00025 #include <vector> 00026 #include <map> 00027 #include <sstream> 00028 #include <cstring> 00029 00030 #ifndef OBERROR 00031 #define OBERROR 00032 #endif 00033 00034 namespace OpenBabel 00035 { 00038 00040 struct OBERROR CharPtrLess : public std::binary_function<const char*,const char*, bool> 00041 { 00042 bool operator()(const char* p1,const char* p2) const 00043 { return strcasecmp(p1,p2)<0; } 00044 }; 00045 00051 class OBERROR OBPlugin 00052 { 00053 public: 00054 00055 //Maps of thistype are used to store 00056 // (a)a list of the plugin types in OBPlugin, and 00057 // (b)a list of the sub-types in each type class derived from OBPlugin. 00058 typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType; 00059 typedef PluginMapType::const_iterator PluginIterator; 00060 00062 virtual ~OBPlugin(){}; 00063 00065 virtual const char* Description() { return NULL;} ; 00066 00068 virtual const char* TypeID(){ return "plugins"; } 00069 00075 virtual bool Display(std::string&txt, const char* param, const char* ID=NULL); 00076 00081 virtual OBPlugin* MakeInstance(const std::vector<std::string>&){return NULL;} 00082 00085 virtual void Init(){}; 00086 00089 static OBPlugin* GetPlugin(const char* Type, const char* ID); 00090 00092 const char* GetID()const{return _id;}; 00093 00097 static bool ListAsVector(const char* PluginID, const char* param, std::vector<std::string>& vlist); 00098 00100 static void List(const char* PluginID, const char* param=NULL, std::ostream* os=&std::cout); 00101 00103 static std::string ListAsString(const char* PluginID, const char* param=NULL); 00104 00106 static std::string FirstLine(const char* txt); 00107 00110 static PluginIterator Begin(const char* PluginID) 00111 { 00112 if( !strcmp(PluginID, "plugins") || GetTypeMap(PluginID)!=PluginMap()) 00113 return GetTypeMap(PluginID).begin(); 00114 else 00115 return PluginMap().end(); 00116 } 00117 00118 static PluginIterator End(const char* PluginID) 00119 { 00120 return GetTypeMap(PluginID).end(); 00121 } 00122 00124 virtual PluginMapType& GetMap() const =0; 00125 00126 protected: 00129 static PluginMapType& PluginMap() 00130 { 00131 static PluginMapType m; 00132 return m; 00133 } 00134 00136 static PluginMapType& GetTypeMap(const char* PluginID); 00137 00140 static OBPlugin* BaseFindType(PluginMapType& Map, const char* ID); 00141 00142 protected: 00143 const char* _id; 00144 }; 00145 00146 #if defined(__CYGWIN__) || defined(__MINGW32__) 00147 00148 //Macro to be added to definition of the base class 00149 #define MAKE_PLUGIN(BaseClass)\ 00150 protected:\ 00151 static PluginMapType& Map();\ 00152 virtual PluginMapType& GetMap()const{return Map();}\ 00153 public:\ 00154 static BaseClass*& Default(){static BaseClass* d;return d;}\ 00155 BaseClass(const char* ID, bool IsDefault=false)\ 00156 {_id=ID;if(ID&&*ID){if(IsDefault || Map().empty()) Default() = this;\ 00157 Map()[ID]=this;PluginMap()[TypeID()] =this;}}\ 00158 static BaseClass* FindType(const char* ID)\ 00159 {if(!ID || *ID==0 || *ID==' ') return Default();\ 00160 return static_cast<BaseClass*>(BaseFindType(Map(),ID));} 00161 00162 #define PLUGIN_CPP_FILE(BaseClass)\ 00163 OBPlugin::PluginMapType& BaseClass::Map()\ 00164 { static OBPlugin::PluginMapType map; return map; } 00165 00166 #else // __CYGWIN__ || __MINGW32__ 00167 00168 //Macro to be added to definition of the base class 00169 #define MAKE_PLUGIN(BaseClass)\ 00170 protected:\ 00171 static PluginMapType& Map(){static PluginMapType m;return m;}\ 00172 virtual PluginMapType& GetMap()const{return Map();}\ 00173 public:\ 00174 static BaseClass*& Default(){static BaseClass* d;return d;}\ 00175 BaseClass(const char* ID, bool IsDefault=false)\ 00176 {_id=ID;if(ID&&*ID){if(IsDefault || Map().empty()) Default() = this;\ 00177 Map()[ID]=this;PluginMap()[TypeID()] =this;}}\ 00178 static BaseClass* FindType(const char* ID)\ 00179 {if(!ID || *ID==0 || *ID==' ') return Default();\ 00180 return static_cast<BaseClass*>(BaseFindType(Map(),ID));} 00181 00182 #endif // __CYGWIN__ || __MINGW32__ 00183 00312 00320 /*\@}*/ 00321 00322 #ifndef SWIG // Skipped by SWIG (for the moment) 00323 00324 #ifndef USING_DYNAMIC_LIBS 00325 00326 #define OB_STATIC_PLUGIN(className,instanceName) \ 00327 class className; \ 00328 OBAPI EXTERN className instanceName; 00329 00330 // formats 00331 OB_STATIC_PLUGIN(ACRFormat, theACRFormat); 00332 OB_STATIC_PLUGIN(ADFOutputFormat, theADFOutputFormat); 00333 OB_STATIC_PLUGIN(ADFInputFormat, theADFInputFormat); 00334 OB_STATIC_PLUGIN(AlchemyFormat, theAlchemyFormat); 00335 OB_STATIC_PLUGIN(AmberPrepFormat, theAmberPrepFormat); 00336 OB_STATIC_PLUGIN(OBAPIInterface, theOBAPIInterface); 00337 OB_STATIC_PLUGIN(BallStickFormat, theBallStickFormat); 00338 OB_STATIC_PLUGIN(BGFFormat, theBGFFormat); 00339 OB_STATIC_PLUGIN(BoxFormat, theBoxFormat); 00340 OB_STATIC_PLUGIN(CacaoFormat, theCacaoFormat); 00341 OB_STATIC_PLUGIN(CacheFormat, theCacheFormat); 00342 OB_STATIC_PLUGIN(CARFormat, theCARFormat); 00343 OB_STATIC_PLUGIN(CCCFormat, theCCCFormat); 00344 OB_STATIC_PLUGIN(CHEM3D1Format, theCHEM3D1Format); 00345 OB_STATIC_PLUGIN(CHEM3D2Format, theCHEM3D2Format); 00346 OB_STATIC_PLUGIN(ChemDrawBinaryFormat, theChemDrawBinaryFormat); 00347 OB_STATIC_PLUGIN(ChemDrawFormat, theChemDrawFormat); 00348 OB_STATIC_PLUGIN(ChemKinFormat, theChemKinFormat); 00349 OB_STATIC_PLUGIN(CHTFormat, theCHTFormat); 00350 OB_STATIC_PLUGIN(CIFFormat, theCIFFormat); 00351 OB_STATIC_PLUGIN(CopyFormat, theCopyFormat); 00352 OB_STATIC_PLUGIN(CRK2DFormat, theCRK2DFormat); 00353 OB_STATIC_PLUGIN(CRK3DFormat, theCRK3DFormat); 00354 OB_STATIC_PLUGIN(CSRFormat, theCSRFormat); 00355 OB_STATIC_PLUGIN(CSSRFormat, theCSSRFormat); 00356 OB_STATIC_PLUGIN(DlpolyConfigFormat, theDlpolyConfigFormat); 00357 OB_STATIC_PLUGIN(DlpolyHISTORYFormat, theDlpolyHISTORYFormat); 00358 OB_STATIC_PLUGIN(DMolFormat, theDMolFormat); 00359 OB_STATIC_PLUGIN(FASTAFormat, theFASTAFormat); 00360 OB_STATIC_PLUGIN(FastSearchFormat, theFastSearchFormat); 00361 OB_STATIC_PLUGIN(FCHKFormat, theFCHKFormat); 00362 OB_STATIC_PLUGIN(FEATFormat, theFEATFormat); 00363 OB_STATIC_PLUGIN(FenskeZmatFormat, theFenskeZmatFormat); 00364 OB_STATIC_PLUGIN(FHIaimsFormat,theFHIaimsFormat); 00365 OB_STATIC_PLUGIN(FingerprintFormat, theFingerprintFormat); 00366 OB_STATIC_PLUGIN(FreeFormFractionalFormat, theFreeFormFractionalFormat); 00367 OB_STATIC_PLUGIN(GAMESSOutputFormat, theGAMESSOutputFormat); 00368 OB_STATIC_PLUGIN(GAMESSInputFormat, theGAMESSInputFormat); 00369 OB_STATIC_PLUGIN(GAMESSUKInputFormat, theGAMESSUKInputFormat); 00370 OB_STATIC_PLUGIN(GAMESSUKOutputFormat, theGAMESSUKOutputFormat); 00371 OB_STATIC_PLUGIN(OBGaussianCubeFormat, theGaussianCubeFormat); 00372 OB_STATIC_PLUGIN(GaussianOutputFormat, theGaussianOutputFormat); 00373 OB_STATIC_PLUGIN(GaussianInputFormat, theGaussianInputFormat); 00374 OB_STATIC_PLUGIN(GaussianZMatrixInputFormat, theGaussianZMatrixInputFormat); 00375 OB_STATIC_PLUGIN(GenBankFormat, theGenBankFormat); 00376 OB_STATIC_PLUGIN(GhemicalFormat, theGhemicalFormat); 00377 OB_STATIC_PLUGIN(GROMOS96Format, theGROMOS96Format); 00378 OB_STATIC_PLUGIN(GULPFormat, theGULPFormat); 00379 OB_STATIC_PLUGIN(HINFormat, theHINFormat); 00380 OB_STATIC_PLUGIN(JaguarOutputFormat, theJaguarOutputFormat); 00381 OB_STATIC_PLUGIN(JaguarInputFormat, theJaguarInputFormat); 00382 OB_STATIC_PLUGIN(MCDLFormat, theMCDLFormat); 00383 OB_STATIC_PLUGIN(MOLFormat, theMOLFormat); 00384 OB_STATIC_PLUGIN(SDFormat, theSDFormat); 00385 OB_STATIC_PLUGIN(OBT41Format, t41Format__); 00386 OB_STATIC_PLUGIN(OBMoldenFormat, moldenFormat__); 00387 OB_STATIC_PLUGIN(mmCIFFormat, themmCIFFormat); 00388 OB_STATIC_PLUGIN(MacroModFormat, theMacroModFormat); 00389 OB_STATIC_PLUGIN(MNAFormat, theMNAFormat); 00390 OB_STATIC_PLUGIN(MOL2Format, theMOL2Format); 00391 OB_STATIC_PLUGIN(MolproOutputFormat, theMolproOutputFormat); 00392 OB_STATIC_PLUGIN(MolproInputFormat, theMolproInputFormat); 00393 OB_STATIC_PLUGIN(MolReportFormat, theMolReportFormat); 00394 OB_STATIC_PLUGIN(MOPACFormat, theMOPACFormat); 00395 OB_STATIC_PLUGIN(MOPACCARTFormat, theMOPACCARTFormat); 00396 OB_STATIC_PLUGIN(MOPACINTFormat, theMOPACINTFormat); 00397 OB_STATIC_PLUGIN(MPDFormat, theMPDFormat); 00398 OB_STATIC_PLUGIN(MPQCFormat, theMPQCFormat); 00399 OB_STATIC_PLUGIN(MPQCInputFormat, theMPQCInputFormat); 00400 OB_STATIC_PLUGIN(MSIFormat, theMSIFormat); 00401 OB_STATIC_PLUGIN(OBMSMSFormat, msmsFormat__); 00402 OB_STATIC_PLUGIN(NulFormat, theNulFormat); 00403 OB_STATIC_PLUGIN(NWChemOutputFormat, theNWChemOutputFormat); 00404 OB_STATIC_PLUGIN(NWChemInputFormat, theNWChemInputFormat); 00405 OB_STATIC_PLUGIN(OBOpenDXCubeFormat, theOpenDXCubeFormat); 00406 OB_STATIC_PLUGIN(OutputFormat, theOutputFormat); 00407 OB_STATIC_PLUGIN(PCModelFormat, thePCModelFormat); 00408 OB_STATIC_PLUGIN(PDBFormat, thePDBFormat); 00409 OB_STATIC_PLUGIN(PDBQTFormat, thePDBQTFormat); 00410 OB_STATIC_PLUGIN(PNGFormat, thePNGFormat); 00411 OB_STATIC_PLUGIN(PovrayFormat, thePovrayFormat); 00412 OB_STATIC_PLUGIN(PQRFormat, thePQRFormat); 00413 OB_STATIC_PLUGIN(PQSFormat, thePQSFormat); 00414 OB_STATIC_PLUGIN(PWscfFormat, thePWscfFormat); 00415 OB_STATIC_PLUGIN(QChemOutputFormat, theQChemOutputFormat); 00416 OB_STATIC_PLUGIN(QChemInputFormat, theQChemInputFormat); 00417 OB_STATIC_PLUGIN(ReportFormat, theReportFormat); 00418 OB_STATIC_PLUGIN(SmiReactFormat, theSmiReactFormat); 00419 OB_STATIC_PLUGIN(RXNFormat, theRXNFormat); 00420 OB_STATIC_PLUGIN(ShelXFormat, theShelXFormat); 00421 OB_STATIC_PLUGIN(SMIFormat, theSMIFormat); 00422 OB_STATIC_PLUGIN(CANSMIFormat, theCANSMIFormat); 00423 OB_STATIC_PLUGIN(FIXFormat, theFIXFormat); 00424 OB_STATIC_PLUGIN(SVGFormat, theSVGFormat); 00425 OB_STATIC_PLUGIN(TextFormat, theTextFormat); 00426 OB_STATIC_PLUGIN(ThermoFormat, theThermoFormat); 00427 OB_STATIC_PLUGIN(TinkerFormat, theTinkerFormat); 00428 OB_STATIC_PLUGIN(TitleFormat, theTitleFormat); 00429 OB_STATIC_PLUGIN(TurbomoleFormat, theTurbomoleFormat); 00430 OB_STATIC_PLUGIN(UniChemFormat, theUniChemFormat); 00431 OB_STATIC_PLUGIN(VASPFormat, theVASPFormat); 00432 OB_STATIC_PLUGIN(ViewMolFormat, theViewMolFormat); 00433 OB_STATIC_PLUGIN(XEDFormat, theXEDFormat); 00434 OB_STATIC_PLUGIN(XTCFormat, theXTCFormat); 00435 OB_STATIC_PLUGIN(XYZFormat, theXYZFormat); 00436 OB_STATIC_PLUGIN(YOBFormat, theYOBFormat); 00437 OB_STATIC_PLUGIN(ZINDOFormat, theZINDOFormat); 00438 OB_STATIC_PLUGIN(ChemDrawXMLFormat, theChemDrawXMLFormat); 00439 OB_STATIC_PLUGIN(CMLFormat, theCMLFormat); 00440 OB_STATIC_PLUGIN(CMLReactFormat, theCMLReactFormat); 00441 OB_STATIC_PLUGIN(PubChemFormat, thePubChemFormat); 00442 OB_STATIC_PLUGIN(XMLFormat, theXMLFormat); 00443 OB_STATIC_PLUGIN(InChIFormat, theInChIFormat); 00444 00445 // descriptors 00446 OB_STATIC_PLUGIN(CanSmiles, theCanSmiles); 00447 OB_STATIC_PLUGIN(CompoundFilter, dummyCmpFilter); 00448 OB_STATIC_PLUGIN(MWFilter, theMWFilter); 00449 OB_STATIC_PLUGIN(SmartsFilter, firstSmartsFilter); 00450 OB_STATIC_PLUGIN(SmartsFilter, secondSmartsFilter); 00451 OB_STATIC_PLUGIN(TitleFilter, theTitleFilter); 00452 OB_STATIC_PLUGIN(FormulaDescriptor, TheFormulaDescriptor); 00453 //OB_STATIC_PLUGIN(FPCount, theFPCount); 00454 OB_STATIC_PLUGIN(InChIFilter, theInChIFilter); 00455 // smarts descriptors 00456 OB_STATIC_PLUGIN(SmartsDescriptor, theHBD); 00457 OB_STATIC_PLUGIN(SmartsDescriptor, theHBA1); 00458 OB_STATIC_PLUGIN(SmartsDescriptor, theHBA2); 00459 OB_STATIC_PLUGIN(SmartsDescriptor, thenF); 00460 // group contribution descriptors 00461 OB_STATIC_PLUGIN(OBGroupContrib, thelogP); 00462 OB_STATIC_PLUGIN(OBGroupContrib, theTPSA); 00463 OB_STATIC_PLUGIN(OBGroupContrib, theMR); 00464 00465 // fingerprints 00466 OB_STATIC_PLUGIN(fingerprint2, thefingerprint2); 00467 OB_STATIC_PLUGIN(PatternFP, FP3PatternFP) 00468 OB_STATIC_PLUGIN(PatternFP, FP4PatternFP) 00469 00470 // forcefields 00471 OB_STATIC_PLUGIN(OBForceFieldGaff, theForceFieldGaff); 00472 OB_STATIC_PLUGIN(OBForceFieldGhemical, theForceFieldGhemical); 00473 OB_STATIC_PLUGIN(OBForceFieldMMFF94, theForceFieldMMFF94); 00474 OB_STATIC_PLUGIN(OBForceFieldMMFF94, theForceFieldMMFF94s); 00475 OB_STATIC_PLUGIN(OBForceFieldUFF, theForceFieldUFF); 00476 00477 // operations 00478 OB_STATIC_PLUGIN(OpAddInIndex, theOpAddInIndex); 00479 OB_STATIC_PLUGIN(OpAddPolarH, theOpAddPolarH); 00480 OB_STATIC_PLUGIN(OpCanonical, theOpCanonical); 00481 OB_STATIC_PLUGIN(OpConformer, theOpConformer); 00482 OB_STATIC_PLUGIN(OpFillUC, theOpFillUC); 00483 OB_STATIC_PLUGIN(OpEnergy, theOpEnergy); 00484 OB_STATIC_PLUGIN(OpMinimize, theOpMinimize); 00485 OB_STATIC_PLUGIN(OpGen2D, theOpGen2D); 00486 OB_STATIC_PLUGIN(OpGen3D, theOpGen3D); 00487 OB_STATIC_PLUGIN(OpNewS, theOpNewS); 00488 OB_STATIC_PLUGIN(OpPartialCharge, theOpPartialCharge); 00489 OB_STATIC_PLUGIN(OpReadConformers, theOpReadConformers); 00490 OB_STATIC_PLUGIN(OpSort, theOpSort); 00491 OB_STATIC_PLUGIN(OpUnique, theOpUnique); 00492 OB_STATIC_PLUGIN(OpExtraOut, theOpExtraOut); 00493 00494 // charges 00495 OB_STATIC_PLUGIN(GasteigerCharges, theGasteigerCharges); 00496 OB_STATIC_PLUGIN(MMFF94Charges, theMMFF94Charges); 00497 OB_STATIC_PLUGIN(QEqCharges, theQEqCharges); 00498 OB_STATIC_PLUGIN(QTPIECharges, theQTPIECharges); 00499 00500 OBAPI std::vector<std::string> EnableStaticPlugins(); 00501 00502 #endif // USING_DYNAMIC_LIBS 00503 00504 #endif // SWIG 00505 00506 } // end namespce 00507 00508 #endif
This file is part of the documentation for Open Babel, version 2.3.