OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sequence_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-2020 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_SEQUENCE_IO_HANDLER_HH
20 #define OST_IO_SEQUENCE_IO_HANDLER_HH
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/seq/sequence_list.hh>
28 #include <ost/io/io_utils.hh>
29 
30 namespace ost { namespace io {
31 
33 class DLLEXPORT_OST_IO SequenceIOHandler {
34 public:
35  virtual ~SequenceIOHandler() {}
36 
37 
38  virtual void Import(seq::SequenceList& sequences,
39  const boost::filesystem::path& loc) = 0;
40 
41  virtual void Export(const seq::ConstSequenceList& ent,
42  const boost::filesystem::path& loc) const = 0;
43 
44  virtual void Import(seq::SequenceList& ent,
45  std::istream& instream)=0;
46 
47  virtual void Export(const seq::ConstSequenceList& ent,
48  std::ostream& ostream) const=0;
49 };
50 
51 typedef boost::shared_ptr<SequenceIOHandler> SequenceIOHandlerPtr;
52 
53 
55 class DLLEXPORT_OST_IO SequenceIOHandlerFactoryBase {
56 public:
58  virtual bool ProvidesImport(const boost::filesystem::path& loc,
59  const String& type) const = 0;
60  virtual bool ProvidesExport(const boost::filesystem::path& loc,
61  const String& type) const = 0;
62  virtual SequenceIOHandlerPtr Create() const = 0;
63  virtual String GetFormatName() const =0;
64  virtual String GetFormatDescription() const =0;
65 };
66 
67 typedef boost::shared_ptr<SequenceIOHandlerFactoryBase> SequenceIOHandlerFactoryBasePtr;
68 
69 template <class HANDLER>
70 class SequenceIOHandlerFactory: public SequenceIOHandlerFactoryBase {
71  virtual bool ProvidesImport(const boost::filesystem::path& loc,
72  const String& type) const {
73  return HANDLER::ProvidesImport(loc,type);
74  }
75 
76  virtual bool ProvidesExport(const boost::filesystem::path& loc,
77  const String& type) const {
78  return HANDLER::ProvidesExport(loc,type);
79  }
80 
81  virtual SequenceIOHandlerPtr Create() const {
82  return SequenceIOHandlerPtr(new HANDLER);
83  }
84 
85  virtual String GetFormatName() const {
86  return HANDLER::GetFormatName();
87  }
88 
89  virtual String GetFormatDescription() const {
90  return HANDLER::GetFormatDescription();
91  }
92 
93 };
94 
95 
96 
97 }} // ns
98 
99 #endif
boost::shared_ptr< SequenceIOHandler > SequenceIOHandlerPtr
std::string String
Definition: base.hh:54
list of immutable sequences.
#define DLLEXPORT_OST_IO
list of sequences.
boost::shared_ptr< SequenceIOHandlerFactoryBase > SequenceIOHandlerFactoryBasePtr