Developer Documentation
FileManager.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh 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  * OpenVolumeMesh 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 OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision$ *
38  * $Date$ *
39  * $LastChangedBy$ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef FILEMANAGER_HH_
44 #define FILEMANAGER_HH_
45 
46 #include <string>
47 #include <fstream>
48 #include <istream>
49 #include <ostream>
50 #include "OpenVolumeMesh/Config/Export.hh"
51 
52 namespace OpenVolumeMesh {
53 
54 namespace IO {
55 
63 class OVM_EXPORT FileManager {
64 public:
65 
67  FileManager();
68 
70  ~FileManager();
71 
72 
77  void setVerbosityLevel(int _level) { verbosity_level_ = _level;}
78 
95  template <class MeshT>
96  bool readStream(std::istream &_istream, MeshT& _mesh,
97  bool _topologyCheck = true,
98  bool _computeBottomUpIncidences = true) const;
99 
116  template <class MeshT>
117  bool readFile(const std::string& _filename, MeshT& _mesh,
118  bool _topologyCheck = true,
119  bool _computeBottomUpIncidences = true) const;
120 
121 
128  template <class MeshT>
129  void writeStream(std::ostream &_ostream, const MeshT& _mesh) const;
130 
141  template <class MeshT>
142  bool writeFile(const std::string& _filename, const MeshT& _mesh) const;
143 
147  bool isHexahedralMesh(const std::string& _filename) const;
148 
152  bool isTetrahedralMesh(const std::string& _filename) const;
153 
154 
155 
156 private:
157 
158  // Read property
159  template <class MeshT>
160  void readProperty(std::istream& _iff, MeshT& _mesh) const;
161 
162  template <class PropT, class MeshT>
163  void generateGenericProperty(const std::string& _entity_t, const std::string& _name,
164  std::istream& _iff, MeshT& _mesh) const;
165 
166  // Write props
167  template<class IteratorT>
168  void writeProps(std::ostream& _ostr, const IteratorT& _begin, const IteratorT& _end) const;
169 
170  // Remove leading and trailing whitespaces
171  void trimString(std::string& _string) const;
172 
173  // Get quoted text out of a string
174  void extractQuotedText(std::string& _string) const;
175 
176  // Get a whole line from file
177  bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const;
178 
179 
180  int verbosity_level_ = 3;
181 };
182 
183 } // Namespace IO
184 
185 } // Namespace FileManager
186 
187 #if defined(INCLUDE_TEMPLATES) && !defined(FILEMANAGERT_CC)
188 #include "FileManagerT_impl.hh"
189 #endif
190 
191 #endif /* FILEMANAGER_HH_ */
Read/Write mesh data from/to files.
Definition: FileManager.hh:63
void setVerbosityLevel(int _level)
set minimum level for errors that are printed to std::cerr
Definition: FileManager.hh:77