OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
map_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 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 #ifndef OST_IO_MAP_IO_PLUGIN_H
21 #define OST_IO_MAP_IO_PLUGIN_H
22 
23 #include <boost/shared_ptr.hpp>
24 #include <boost/filesystem/operations.hpp>
25 #include <ost/io/module_config.hh>
26 #include <ost/img/map.hh>
29 #include <ost/io/io_utils.hh>
30 
31 namespace ost { namespace io {
32 
33 class DLLEXPORT_OST_IO MapIOHandler {
34 public:
35  virtual ~MapIOHandler() {};
36  virtual void Import(img::MapHandle& surf, const boost::filesystem::path& loc, const ImageFormatBase& formatstruct) = 0;
37  virtual void Import(img::MapHandle& surf, std::istream& stream,const ImageFormatBase& formatstruct) = 0;
38  virtual void Export(const img::MapHandle& ent, const boost::filesystem::path& loc,const ImageFormatBase& formatstruct) const = 0;
39  virtual void Export(const img::MapHandle& ent, std::ostream& stream,const ImageFormatBase& formatstruct) const = 0;
40 };
41 
42 typedef boost::shared_ptr<MapIOHandler> MapIOHandlerPtr;
43 
44 class DLLEXPORT_OST_IO MapIOHandlerFactoryBase {
45 public:
47  virtual bool MatchContent(unsigned char* header) const = 0;
48  virtual bool MatchType(const ImageFormatBase& type) const = 0;
49  virtual bool MatchSuffix(const String& loc) const =0 ;
50  virtual MapIOHandlerPtr Create() const = 0 ;
51  virtual String GetFormatName() const =0;
52  virtual String GetFormatDescription() const =0;
53  virtual bool ProvidesImport() const = 0;
54  virtual bool ProvidesExport() const = 0;
55 };
56 
57 typedef boost::shared_ptr<MapIOHandlerFactoryBase> MapIOHandlerFactoryBasePtr;
58 
59 template <class HANDLER>
60 class MapIOHandlerFactory: public MapIOHandlerFactoryBase
61 {
62 
63  virtual bool MatchContent(unsigned char* header) const {
64  return HANDLER::MatchContent(header);
65  }
66 
67  virtual bool MatchType(const ImageFormatBase& type) const {
68  return HANDLER::MatchType(type);
69  }
70 
71  virtual bool MatchSuffix(const String& loc) const {
72  return HANDLER::MatchSuffix(loc);
73  }
74 
75  virtual String GetFormatName() const {
76  return HANDLER::GetFormatName();
77  }
78 
79  virtual String GetFormatDescription() const {
80  return HANDLER::GetFormatDescription();
81  }
82  virtual bool ProvidesImport() const
83  {
84  return HANDLER::ProvidesImport();
85  }
86 
87  virtual bool ProvidesExport() const
88  {
89  return HANDLER::ProvidesExport();
90  }
91 
92  virtual MapIOHandlerPtr Create() const {
93  return MapIOHandlerPtr(new HANDLER);
94  }
95 };
96 
97 
98 }} // ns
99 
100 #endif
std::string String
Definition: base.hh:54
boost::shared_ptr< MapIOHandlerFactoryBase > MapIOHandlerFactoryBasePtr
boost::shared_ptr< MapIOHandler > MapIOHandlerPtr
#define DLLEXPORT_OST_IO
Manage shared instances of images.