Open Babel  3.0
format.h
Go to the documentation of this file.
1 /**********************************************************************
2 obconversion.cpp - Declarations for OBFormat
3 
4 Copyright (C) 2004-2007 by Chris Morley
5 Some portions Copyright (C) 2005-2007 by Geoffrey Hutchison
6 
7 This file is part of the Open Babel project.
8 For more information, see <http://openbabel.org/>
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 ***********************************************************************/
19 #ifndef OB_FORMAT_H
20 #define OB_FORMAT_H
21 #include <openbabel/babelconfig.h>
22 #include <openbabel/plugin.h>
23 #include <typeinfo>
24 
25 namespace OpenBabel
26 {
27  class OBBase;
28  class OBConversion;
29 
31 #define NOTREADABLE 0x01
32 #define READONEONLY 0x02
33 #define READBINARY 0x04
34 #define ZEROATOMSOK 0x08
35 #define NOTWRITABLE 0x10
36 #define WRITEONEONLY 0x20
37 #define WRITEBINARY 0x40
38 #define READXML 0x80
39 #define DEPICTION2D 0x100
40 #define DEFAULTFORMAT 0x4000
41 
43  // class introduction in obconversion.cpp
44 class OBCONV OBFormat : public OBPlugin
45  {
46  //Macro to include functions to handle plugin operations
48 
49  public:
50 
53 
54  const char* TypeID(){ return "formats"; }
55 
57 
61  virtual bool ReadMolecule(OBBase* /*pOb*/, OBConversion* /*pConv*/)
62  { std::cerr << "HIER" << std::endl;
63 std::cerr << "Not a valid input format"; return false;}
64 
66 
70  virtual bool ReadChemObject(OBConversion* /*pConv*/)
71  { std::cerr << "Not a valid input format"; return false;}
72 
74 
79  virtual bool WriteMolecule(OBBase* /*pOb*/, OBConversion* /*pConv*/)
80  { std::cerr << "Not a valid output format"; return false;}
81 
83 
87  virtual bool WriteChemObject(OBConversion* /*pConv*/)
88  { std::cerr << "Not a valid output format"; return false;}
89 
91 
95  virtual const char* Description()=0;
96 
98 
100  virtual const char* TargetClassDescription();
101 
103 
106  virtual const std::type_info& GetType();
107 
109  virtual const char* SpecificationURL() { return ""; }
110 
112  virtual const char* GetMIMEType() { return pMime; }
113 
115 
119  virtual unsigned int Flags() { return 0;};
120 
122 
124  virtual int SkipObjects(int /*n*/, OBConversion* /*pConv*/)
125  {
126  return 0; //shows not implemented in the format class
127  };
128 
130 
135  {
136  return NULL; //shows not implemented in the format class
137  }
138 
139  //New functions since OBFormat is derived from OBPlugin
140  //\brief Called from, and an alternative to, OBConversion::RegisterFormat();
141  int RegisterFormat(const char* ID, const char* MIME = NULL);
142 
147  virtual bool Display(std::string& txt, const char* param, const char* ID=NULL);
148 
149  static OBFormat* FormatFromMIME(const char* MIME);
150 
151 private:
152  static PluginMapType &FormatsMIMEMap()
153  {
154  static PluginMapType m;
155  return m;
156  }
157 
158  const char* pMime;
159 /* Functions provided by the MAKE_PLUGIN macro
160 
162  Not currently used for formats
163  OBFormat(const char* ID, bool IsDefault=false);
164 
166  static OBFormat* FindType(const char* ID);
167 
168 */};
169 
170 }//namespace
171 #endif
172 
virtual OBFormat * MakeNewInstance()
Definition: format.h:134
std::map< const char *, OBPlugin *, CharPtrLess > PluginMapType
Definition: plugin.h:59
Base class for all types of dynamic classes discovered at runtime.
Definition: plugin.h:52
Class to convert from one format to another.
Definition: obconversion.h:59
virtual const char * SpecificationURL()
Web address where the format is defined.
Definition: format.h:109
virtual bool WriteChemObject(OBConversion *)
The "Convert" interface Write function.
Definition: format.h:87
virtual bool ReadChemObject(OBConversion *)
The "Convert" interface Read function.
Definition: format.h:70
virtual int SkipObjects(int, OBConversion *)
Skip past first n objects in input stream (or current one with n=0)
Definition: format.h:124
virtual bool ReadMolecule(OBBase *, OBConversion *)
The "API" interface Read function.
Definition: format.h:61
virtual const char * GetMIMEType()
Chemical MIME type associated with this file type (if any)
Definition: format.h:112
#define MAKE_PLUGIN(BaseClass)
Definition: plugin.h:195
Simplify &#39;plugin&#39; classes to be discovered and/or loaded at runtime.
virtual unsigned int Flags()
Decribes the capabilities of the format (Read only etc.)
Definition: format.h:119
const char * TypeID()
Redefined by each plugin type: "formats", "fingerprints", etc.
Definition: format.h:54
OBFormat()
Default constructor. Registration via RegisterFormat(), not via constructor as in other plugins...
Definition: format.h:52
Base class for file formats.
Definition: format.h:44
Base Class.
Definition: base.h:239
virtual bool WriteMolecule(OBBase *, OBConversion *)
The "API" interface Write function.
Definition: format.h:79
Global namespace for all Open Babel code.
Definition: alias.h:22