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 
51 namespace OpenVolumeMesh {
52 
53 namespace IO {
54 
62 class FileManager {
63 public:
64 
66  FileManager();
67 
69  ~FileManager();
70 
71 
76  void setVerbosityLevel(int _level) { verbosity_level_ = _level;}
77 
94  template <class MeshT>
95  bool readStream(std::istream &_istream, MeshT& _mesh,
96  bool _topologyCheck = true,
97  bool _computeBottomUpIncidences = true) const;
98 
115  template <class MeshT>
116  bool readFile(const std::string& _filename, MeshT& _mesh,
117  bool _topologyCheck = true,
118  bool _computeBottomUpIncidences = true) const;
119 
120 
127  template <class MeshT>
128  void writeStream(std::ostream &_ostream, const MeshT& _mesh) const;
129 
140  template <class MeshT>
141  bool writeFile(const std::string& _filename, const MeshT& _mesh) const;
142 
146  bool isHexahedralMesh(const std::string& _filename) const;
147 
151  bool isTetrahedralMesh(const std::string& _filename) const;
152 
153 
154 
155 private:
156 
157  // Read property
158  template <class MeshT>
159  void readProperty(std::istream& _iff, MeshT& _mesh) const;
160 
161  template <class PropT, class MeshT>
162  void generateGenericProperty(const std::string& _entity_t, const std::string& _name,
163  std::istream& _iff, MeshT& _mesh) const;
164 
165  // Write props
166  template<class IteratorT>
167  void writeProps(std::ostream& _ostr, const IteratorT& _begin, const IteratorT& _end) const;
168 
169  // Remove leading and trailing whitespaces
170  void trimString(std::string& _string) const;
171 
172  // Get quoted text out of a string
173  void extractQuotedText(std::string& _string) const;
174 
175  // Get a whole line from file
176  bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const;
177 
178 
179  int verbosity_level_ = 3;
180 };
181 
182 } // Namespace IO
183 
184 } // Namespace FileManager
185 
186 #if defined(INCLUDE_TEMPLATES) && !defined(FILEMANAGERT_CC)
187 #include "FileManagerT_impl.hh"
188 #endif
189 
190 #endif /* FILEMANAGER_HH_ */
~FileManager()
Default destructor.
Definition: FileManager.cc:68
bool readStream(std::istream &_istream, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from an std::istream.
bool readFile(const std::string &_filename, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from a file.
bool isHexahedralMesh(const std::string &_filename) const
Test whether given file contains a hexahedral mesh.
Definition: FileManager.cc:141
FileManager()
Default constructor.
Definition: FileManager.cc:62
void writeStream(std::ostream &_ostream, const MeshT &_mesh) const
Write a mesh to an std::ostream.
Read/Write mesh data from/to files.
Definition: FileManager.hh:62
void setVerbosityLevel(int _level)
set minimum level for errors that are printed to std::cerr
Definition: FileManager.hh:76
bool isTetrahedralMesh(const std::string &_filename) const
Test whether given file contains a tetrahedral mesh.
Definition: FileManager.cc:187
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.