OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
OBJParser.hpp
1 /*
2  * Copyright 2016 Steven T Sell (ssell@vertexfragment.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __H__OBJ_PARSER__H__
18 #define __H__OBJ_PARSER__H__
19 
20 #include "OBJState.hpp"
21 
22 //------------------------------------------------------------------------------------------
23 // Optional Defines
24 //------------------------------------------------------------------------------------------
25 
26 // If defined, the parser will use boost memory mapped files for loading files.
27 // This may drastically speed up file I/O but requires IOStream library dependency.
28 
29 //#define OBJ_PARSER_USE_MEM_MAP
30 
31 //------------------------------------------------------------------------------------------
32 // OBJ Parser
33 //------------------------------------------------------------------------------------------
34 
46 class OBJParser
47 {
48 public:
49 
53  enum class Result
54  {
55  Success = 0,
60  };
61 
62  //--------------------------------------------------------------------
63 
64  OBJParser();
65  ~OBJParser();
66 
67  //--------------------------------------------------------------------
68 
80  Result parseOBJFile(std::string const& path);
81 
87 
91  std::string const& getLastError() const;
92 
93 protected:
94 
95  Result parseOBJFilefstream(std::string const& path);
96  Result parseOBJFileMemMap(std::string const& path);
97 
98  Result parseMTLFilefstream(std::string const& path);
99  Result parseMTLFileMemMap(std::string const& path);
100 
101  std::string buildRelativeMTLPath(std::string const& objPath, std::string const& mtlPath);
102 
103  std::string extractLastLine(const char* str);
104  std::string extractLastLine(std::ifstream& stream);
105 
106  //--------------------------------------------------------------------
107 
109 
110  std::string m_LastError;
111 
112 private:
113 };
114 
115 //------------------------------------------------------------------------------------------
116 
117 #endif
Failed to open and/or read OBJ file.
Failed to open and/or read MTL file.
Error encountered during OBJ parsing, see getLastError.
std::string const & getLastError() const
Definition: OBJParser.cpp:66
No errors encountered during parsing.
OBJState * getOBJState()
Definition: OBJParser.cpp:61
OBJState m_OBJState
Internal OBJ state.
Definition: OBJParser.hpp:108
Definition: OBJParser.hpp:46
Result parseOBJFile(std::string const &path)
Definition: OBJParser.cpp:46
Result
Definition: OBJParser.hpp:53
std::string m_LastError
String representation of last error.
Definition: OBJParser.hpp:110
Definition: OBJState.hpp:37
Error encountered during MTL parsing, see getLastError.