OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
IOManager.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2011 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: 362 $ *
38  * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ *
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 
101 {
102 private:
103 
104  _IOManager_() {}
105  friend _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 
149  bool write(std::ostream& _filename,
150  const std::string& _ext,
151  BaseExporter& _be,
153 
154 
156  bool can_read( const std::string& _format ) const;
157 
159  bool can_write( const std::string& _format ) const;
160 
161 
162  size_t binary_size(const std::string& _format,
163  BaseExporter& _be,
164  Options _opt = Options::Default)
165  {
166  const BaseWriter *bw = find_writer(_format);
167  return bw ? bw->binary_size(_be,_opt) : 0;
168  }
169 
170 
171 
172 public: //-- QT convenience function ------------------------------------------
173 
174 
179  const std::string& qt_read_filters() const { return read_filters_; }
180 
181 
186  const std::string& qt_write_filters() const { return write_filters_; }
187 
188 
189 
190 private:
191 
192  // collect all readable file extensions
193  void update_read_filters();
194 
195 
196  // collect all writeable file extensions
197  void update_write_filters();
198 
199 
200 
201 public: //-- SYSTEM PART------------------------------------------------------
202 
203 
208  {
209  reader_modules_.insert(_bl);
210  update_read_filters();
211  return true;
212  }
213 
214 
215 
220  {
221  writer_modules_.insert(_bw);
222  update_write_filters();
223  return true;
224  }
225 
226 
227 private:
228 
229  const BaseWriter *find_writer(const std::string& _format);
230 
231  // stores registered reader modules
232  std::set<BaseReader*> reader_modules_;
233 
234  // stores registered writer modules
235  std::set<BaseWriter*> writer_modules_;
236 
237  // input filters (e.g. for Qt file dialog)
238  std::string read_filters_;
239 
240  // output filters (e.g. for Qt file dialog)
241  std::string write_filters_;
242 };
243 
244 
245 //=============================================================================
246 
247 
248 extern _IOManager_* __IOManager_instance;
249 
250 _IOManager_& IOManager();
251 
252 
253 
254 //=============================================================================
255 } // namespace IO
256 } // namespace OpenMesh
257 //=============================================================================
258 #endif
259 //=============================================================================

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