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 
45 //=============================================================================
46 //
47 // Implements the baseclass for IOManager file access modules
48 //
49 //=============================================================================
50 
51 
52 #ifndef __BASEREADER_HH__
53 #define __BASEREADER_HH__
54 
55 
56 //=== INCLUDES ================================================================
57 
58 
59 // STD C++
60 #include <iosfwd>
61 #include <string>
62 #include <cctype>
63 #include <functional>
64 #include <algorithm>
65 
66 // OpenMesh
67 #include <OpenMesh/Core/System/config.h>
68 #include <OpenMesh/Core/IO/Options.hh>
69 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
70 #include <OpenMesh/Core/Utils/SingletonT.hh>
71 
72 
73 //== NAMESPACES ===============================================================
74 
75 
76 namespace OpenMesh {
77 namespace IO {
78 
79 
80 //=== IMPLEMENTATION ==========================================================
81 
82 
89 class OPENMESHDLLEXPORT BaseReader
90 {
91 public:
92 
94  virtual ~BaseReader() {};
95 
97  virtual std::string get_description() const = 0;
98 
102  virtual std::string get_extensions() const = 0;
103 
105  virtual std::string get_magic() const { return std::string(""); }
106 
107 
115  virtual bool read(const std::string& _filename,
116  BaseImporter& _bi,
117  Options& _opt) = 0;
118 
125  virtual bool read(std::istream& _is,
126  BaseImporter& _bi,
127  Options& _opt) = 0;
128 
129 
135  virtual bool can_u_read(const std::string& _filename) const;
136 
137 
138 protected:
139 
140  // case insensitive search for _ext in _fname.
141  bool check_extension(const std::string& _fname,
142  const std::string& _ext) const;
143 };
144 
145 
153 static inline std::string &left_trim(std::string &_string) {
154 
155  // Find out if the compiler supports CXX11
156  #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
157  // as with CXX11 we can use lambda expressions
158  _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), [](int i)->int { return ! std::isspace(i); }));
159  #else
160  // we do what we did before
161  _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
162  #endif
163 
164  return _string;
165 }
166 
174 static inline std::string &right_trim(std::string &_string) {
175 
176  // Find out if the compiler supports CXX11
177  #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
178  // as with CXX11 we can use lambda expressions
179  _string.erase(std::find_if(_string.rbegin(), _string.rend(), [](int i)->int { return ! std::isspace(i); } ).base(), _string.end());
180  #else
181  // we do what we did before
182  _string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
183  #endif
184 
185 
186 
187  return _string;
188 }
189 
197 static inline std::string &trim(std::string &_string) {
198  return left_trim(right_trim(_string));
199 }
200 
201 
202 
203 //=============================================================================
204 } // namespace IO
205 } // namespace OpenMesh
206 //=============================================================================
207 #endif
208 //=============================================================================
Base class for reader modules.
Definition: BaseReader.hh:89
virtual std::string get_magic() const
Return magic bits used to determine file format.
Definition: BaseReader.hh:105
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Set options for reader/writer modules.
Definition: Options.hh:90
virtual ~BaseReader()
Destructor.
Definition: BaseReader.hh:94
Base class for importer modules.
Definition: BaseImporter.hh:83

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