OpenStructure
entity_io_handler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_IO_ENTITY_IO_PLUGIN_H
20 #define OST_IO_ENTITY_IO_PLUGIN_H
21 
22 #include <boost/shared_ptr.hpp>
23 #include <boost/filesystem/operations.hpp>
24 
25 
26 #include <ost/io/module_config.hh>
27 #include <ost/io/io_utils.hh>
28 #include <ost/mol/mol.hh>
29 
30 namespace ost { namespace io {
31 
33 class DLLEXPORT_OST_IO EntityIOHandler {
34 public:
35  virtual ~EntityIOHandler() {}
36 
37  // import data from file into provided entity handle
38  /*
39  the handler is expected to convert atom names to IUPAC standard
40  */
41  virtual void Import(mol::EntityHandle& ent,
42  const boost::filesystem::path& loc)=0;
43  // export data from entity view to provided file
44  virtual void Export(const mol::EntityView& ent,
45  const boost::filesystem::path& loc) const = 0;
46  // import data from provided stream
47  virtual void Import(mol::EntityHandle& ent,
48  std::istream& stream)=0;
49  // export data from entity view to provided stream
50  virtual void Export(const mol::EntityView& ent,
51  std::ostream& stream) const=0;
52  virtual bool RequiresBuilder() const=0;
53 };
54 
55 typedef boost::shared_ptr<EntityIOHandler> EntityIOHandlerP;
56 
57 
59 class DLLEXPORT_OST_IO EntityIOHandlerFactoryBase {
60 public:
62  virtual bool ProvidesImport(const boost::filesystem::path& loc, const String& type) const = 0;
63  virtual bool ProvidesExport(const boost::filesystem::path& loc, const String& type) const = 0;
64  virtual EntityIOHandlerP Create() const = 0;
65  virtual String GetFormatName() const =0;
66  virtual String GetFormatDescription() const =0;
67 };
68 
69 typedef boost::shared_ptr<EntityIOHandlerFactoryBase> EntityIOHandlerFactoryBaseP;
70 
71 template <class HANDLER>
72 class EntityIOHandlerFactory: public EntityIOHandlerFactoryBase
73 {
74  virtual bool ProvidesImport(const boost::filesystem::path& loc, const String& type) const {
75  return HANDLER::ProvidesImport(loc,type);
76  }
77 
78  virtual bool ProvidesExport(const boost::filesystem::path& loc, const String& type) const {
79  return HANDLER::ProvidesExport(loc,type);
80  }
81 
82  virtual String GetFormatName() const {
83  return HANDLER::GetFormatName();
84  }
85 
86  virtual String GetFormatDescription() const {
87  return HANDLER::GetFormatDescription();
88  }
89 
90  virtual EntityIOHandlerP Create() const {
91  return EntityIOHandlerP(new HANDLER);
92  }
93 };
94 
95 
96 
97 }} // ns
98 
99 #endif