Developer Documentation
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
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  _string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
160  return _string;
161 }
162 
170 static inline std::string &right_trim(std::string &_string) {
171  _string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
172  return _string;
173 }
174 
182 static inline std::string &trim(std::string &_string) {
183  return left_trim(right_trim(_string));
184 }
185 
186 
187 
188 //=============================================================================
189 } // namespace IO
190 } // namespace OpenMesh
191 //=============================================================================
192 #endif
193 //=============================================================================
virtual ~BaseReader()
Destructor.
Definition: BaseReader.hh:99
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