OpenMesh
BaseReader.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, 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#pragma once
52
53//=== INCLUDES ================================================================
54
55
56// STD C++
57#include <iosfwd>
58#include <string>
59#include <cctype>
60#include <functional>
61#include <algorithm>
62
63// OpenMesh
64#include <OpenMesh/Core/System/config.h>
65#include <OpenMesh/Core/IO/Options.hh>
66#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
67#include <OpenMesh/Core/Utils/SingletonT.hh>
68
69
70//== NAMESPACES ===============================================================
71
72
73namespace OpenMesh {
74namespace IO {
75
76
77//=== IMPLEMENTATION ==========================================================
78
79
86class OPENMESHDLLEXPORT BaseReader
87{
88public:
89
91 virtual ~BaseReader() {}
92
94 virtual std::string get_description() const = 0;
95
99 virtual std::string get_extensions() const = 0;
100
102 virtual std::string get_magic() const { return std::string(""); }
103
104
112 virtual bool read(const std::string& _filename,
113 BaseImporter& _bi,
114 Options& _opt) = 0;
115
122 virtual bool read(std::istream& _is,
123 BaseImporter& _bi,
124 Options& _opt) = 0;
125
126
132 virtual bool can_u_read(const std::string& _filename) const;
133
134
135protected:
136
137 // case insensitive search for _ext in _fname.
138 bool check_extension(const std::string& _fname,
139 const std::string& _ext) const;
140};
141
142
150static inline std::string &left_trim(std::string &_string) {
151
152 // Find out if the compiler supports CXX11
153 #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
154 // as with CXX11 we can use lambda expressions
155 _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), [](int i)->int { return ! std::isspace(i); }));
156 #else
157 // we do what we did before
158 _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
159 #endif
160
161 return _string;
162}
163
171static inline std::string &right_trim(std::string &_string) {
172
173 // Find out if the compiler supports CXX11
174 #if ( __cplusplus >= 201103L || _MSVC_LANG >= 201103L )
175 // as with CXX11 we can use lambda expressions
176 _string.erase(std::find_if(_string.rbegin(), _string.rend(), [](int i)->int { return ! std::isspace(i); } ).base(), _string.end());
177 #else
178 // we do what we did before
179 _string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
180 #endif
181
182
183
184 return _string;
185}
186
194static inline std::string &trim(std::string &_string) {
195 return left_trim(right_trim(_string));
196}
197
198
199
200//=============================================================================
201} // namespace IO
202} // namespace OpenMesh
203//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Base class for importer modules.
Definition: BaseImporter.hh:84
Set options for reader/writer modules.
Definition: Options.hh:92
Base class for reader modules.
Definition: BaseReader.hh:87
virtual bool read(std::istream &_is, BaseImporter &_bi, Options &_opt)=0
Reads a mesh given by a std::stream.
virtual std::string get_description() const =0
Returns a brief description of the file type that can be parsed.
virtual std::string get_extensions() const =0
Returns a string with the accepted file extensions separated by a whitespace and in small caps.
virtual std::string get_magic() const
Return magic bits used to determine file format.
Definition: BaseReader.hh:102
virtual bool read(const std::string &_filename, BaseImporter &_bi, Options &_opt)=0
Reads a mesh given by a filename.
virtual ~BaseReader()
Destructor.
Definition: BaseReader.hh:91

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .