OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
profile_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 
20 /*
21  Author: Gerardo Tauriello
22  */
23 
24 #ifndef OST_IO_PROFILE_IO_HANDLER_HH
25 #define OST_IO_PROFILE_IO_HANDLER_HH
26 
27 #include <boost/shared_ptr.hpp>
28 #include <boost/filesystem/operations.hpp>
29 
30 #include <ost/io/module_config.hh>
31 #include <ost/io/io_utils.hh>
33 
34 namespace ost { namespace io {
35 
37 class DLLEXPORT_OST_IO ProfileIOHandler {
38 public:
39  virtual ~ProfileIOHandler() {}
40 
41  virtual void Import(seq::ProfileHandle& prof,
42  const boost::filesystem::path& loc) = 0;
43 
44  virtual void ImportFromString(seq::ProfileHandle& prof,
45  const String& data) = 0;
46 
47  virtual void Export(const seq::ProfileHandle& prof,
48  const boost::filesystem::path& loc) const = 0;
49 };
50 
51 typedef boost::shared_ptr<ProfileIOHandler> ProfileIOHandlerPtr;
52 
54 class DLLEXPORT_OST_IO ProfileIOHandlerFactoryBase {
55 public:
57  virtual bool ProvidesImport(const boost::filesystem::path& loc,
58  const String& format="auto") const = 0;
59  virtual bool ProvidesExport(const boost::filesystem::path& loc,
60  const String& format="auto") const = 0;
61  virtual ProfileIOHandlerPtr Create() const = 0;
62  virtual String GetFormatName() const =0;
63  virtual String GetFormatDescription() const =0;
64 };
65 
66 typedef boost::shared_ptr<ProfileIOHandlerFactoryBase> ProfileIOHandlerFactoryBasePtr;
67 
68 template <class HANDLER>
69 class ProfileIOHandlerFactory: public ProfileIOHandlerFactoryBase {
70  virtual bool ProvidesImport(const boost::filesystem::path& loc,
71  const String& format="auto") const {
72  return HANDLER::ProvidesImport(loc, format);
73  }
74 
75  virtual bool ProvidesExport(const boost::filesystem::path& loc,
76  const String& format="auto") const {
77  return HANDLER::ProvidesExport(loc, format);
78  }
79 
80  virtual ProfileIOHandlerPtr Create() const {
81  return ProfileIOHandlerPtr(new HANDLER);
82  }
83 
84  virtual String GetFormatName() const {
85  return HANDLER::GetFormatName();
86  }
87 
88  virtual String GetFormatDescription() const {
89  return HANDLER::GetFormatDescription();
90  }
91 
92 };
93 
94 }} // ns
95 
96 #endif
std::string String
Definition: base.hh:54
boost::shared_ptr< ProfileIOHandlerFactoryBase > ProfileIOHandlerFactoryBasePtr
Provides a profile for a sequence.
#define DLLEXPORT_OST_IO
boost::shared_ptr< ProfileIOHandler > ProfileIOHandlerPtr