OpenMesh
BaseReader.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 
50 //=============================================================================
51 //
52 // Implements the baseclass for IOManager file access modules
53 //
54 //=============================================================================
55 
56 
57 #ifndef __BASEREADER_HH__
58 #define __BASEREADER_HH__
59 
60 
61 //=== INCLUDES ================================================================
62 
63 
64 // STD C++
65 #include <iosfwd>
66 #include <string>
67 #include <cctype>
68 #include <functional>
69 #include <algorithm>
70 
71 // OpenMesh
72 #include <OpenMesh/Core/System/config.h>
73 #include <OpenMesh/Core/IO/Options.hh>
74 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
75 #include <OpenMesh/Core/Utils/SingletonT.hh>
76 
77 
78 //== NAMESPACES ===============================================================
79 
80 
81 namespace OpenMesh {
82 namespace IO {
83 
84 
85 //=== IMPLEMENTATION ==========================================================
86 
87 
94 class OPENMESHDLLEXPORT BaseReader
95 {
96 public:
97 
99  virtual ~BaseReader() {};
100 
102  virtual std::string get_description() const = 0;
103 
107  virtual std::string get_extensions() const = 0;
108 
110  virtual std::string get_magic() const { return std::string(""); }
111 
112 
120  virtual bool read(const std::string& _filename,
121  BaseImporter& _bi,
122  Options& _opt) = 0;
123 
130  virtual bool read(std::istream& _is,
131  BaseImporter& _bi,
132  Options& _opt) = 0;
133 
134 
140  virtual bool can_u_read(const std::string& _filename) const;
141 
142 
143 protected:
144 
145  // case insensitive search for _ext in _fname.
146  bool check_extension(const std::string& _fname,
147  const std::string& _ext) const;
148 };
149 
150 
158 static inline std::string &left_trim(std::string &_string) {
159 
160  // Find out if the compiler supports CXX11
161  #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
162  // as with CXX11 we can use lambda expressions
163  _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), [](int i)->int { return ! std::isspace(i); }));
164  #else
165  // we do what we did before
166  _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
167  #endif
168 
169  return _string;
170 }
171 
179 static inline std::string &right_trim(std::string &_string) {
180 
181  // Find out if the compiler supports CXX11
182  #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
183  // as with CXX11 we can use lambda expressions
184  _string.erase(std::find_if(_string.rbegin(), _string.rend(), [](int i)->int { return ! std::isspace(i); } ).base(), _string.end());
185  #else
186  // we do what we did before
187  _string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
188  #endif
189 
190 
191 
192  return _string;
193 }
194 
202 static inline std::string &trim(std::string &_string) {
203  return left_trim(right_trim(_string));
204 }
205 
206 
207 
208 //=============================================================================
209 } // namespace IO
210 } // namespace OpenMesh
211 //=============================================================================
212 #endif
213 //=============================================================================
virtual ~BaseReader()
Destructor.
Definition: BaseReader.hh:99
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Base class for reader modules.
Definition: BaseReader.hh:94
virtual std::string get_magic() const
Return magic bits used to determine file format.
Definition: BaseReader.hh:110
Set options for reader/writer modules.
Definition: Options.hh:95
Base class for importer modules.
Definition: BaseImporter.hh:88

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