OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
IOManager.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 748 $ *
38  * $Date: 2012-10-15 15:52:32 +0200 (Mo, 15 Okt 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 //=============================================================================
43 //
44 // Implements the OpenMesh IOManager singleton
45 //
46 //=============================================================================
47 
48 #ifndef __IOMANAGER_HH__
49 #define __IOMANAGER_HH__
50 
51 
52 //=== INCLUDES ================================================================
53 
54 
55 // STL
56 #include <iostream>
57 #include <sstream>
58 #include <string>
59 #include <set>
60 
61 // OpenMesh
62 #include <OpenMesh/Core/System/config.h>
63 #include <OpenMesh/Core/IO/Options.hh>
64 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
65 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
66 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
67 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
68 #include <OpenMesh/Core/Utils/SingletonT.hh>
69 
70 
71 //== NAMESPACES ===============================================================
72 
73 
74 namespace OpenMesh {
75 namespace IO {
76 
77 
78 //=== IMPLEMENTATION ==========================================================
79 
80 
100 class OPENMESHDLLEXPORT _IOManager_
101 {
102 private:
103 
104  _IOManager_() {}
105  friend OPENMESHDLLEXPORT _IOManager_& IOManager();
106 
107 
108 public:
109 
110 
117  bool read(const std::string& _filename,
118  BaseImporter& _bi,
119  Options& _opt);
120 
127  bool read(std::istream& _filename,
128  const std::string& _ext,
129  BaseImporter& _bi,
130  Options& _opt);
131 
132 
139  bool write(const std::string& _filename,
140  BaseExporter& _be,
142  std::streamsize _precision = 6);
143 
150  bool write(std::ostream& _filename,
151  const std::string& _ext,
152  BaseExporter& _be,
154  std::streamsize _precision = 6);
155 
156 
158  bool can_read( const std::string& _format ) const;
159 
161  bool can_write( const std::string& _format ) const;
162 
163 
164  size_t binary_size(const std::string& _format,
165  BaseExporter& _be,
166  Options _opt = Options::Default)
167  {
168  const BaseWriter *bw = find_writer(_format);
169  return bw ? bw->binary_size(_be,_opt) : 0;
170  }
171 
172 
173 
174 public: //-- QT convenience function ------------------------------------------
175 
176 
181  const std::string& qt_read_filters() const { return read_filters_; }
182 
183 
188  const std::string& qt_write_filters() const { return write_filters_; }
189 
190 
191 
192 private:
193 
194  // collect all readable file extensions
195  void update_read_filters();
196 
197 
198  // collect all writeable file extensions
199  void update_write_filters();
200 
201 
202 
203 public: //-- SYSTEM PART------------------------------------------------------
204 
205 
209  bool register_module(BaseReader* _bl)
210  {
211  reader_modules_.insert(_bl);
212  update_read_filters();
213  return true;
214  }
215 
216 
217 
221  bool register_module(BaseWriter* _bw)
222  {
223  writer_modules_.insert(_bw);
224  update_write_filters();
225  return true;
226  }
227 
228 
229 private:
230 
231  const BaseWriter *find_writer(const std::string& _format);
232 
233  // stores registered reader modules
234  std::set<BaseReader*> reader_modules_;
235 
236  // stores registered writer modules
237  std::set<BaseWriter*> writer_modules_;
238 
239  // input filters (e.g. for Qt file dialog)
240  std::string read_filters_;
241 
242  // output filters (e.g. for Qt file dialog)
243  std::string write_filters_;
244 };
245 
246 
247 //=============================================================================
248 
249 
250 extern _IOManager_* __IOManager_instance;
251 
252 OPENMESHDLLEXPORT _IOManager_& IOManager();
253 
254 
255 
256 //=============================================================================
257 } // namespace IO
258 } // namespace OpenMesh
259 //=============================================================================
260 #endif
261 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .