vrshoot

view libs/assimp/FBXTokenizer.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file FBXTokenizer.h
42 * @brief FBX lexer
43 */
44 #ifndef INCLUDED_AI_FBX_TOKENIZER_H
45 #define INCLUDED_AI_FBX_TOKENIZER_H
47 #include <boost/shared_ptr.hpp>
49 #include "FBXCompileConfig.h"
51 namespace Assimp {
52 namespace FBX {
54 /** Rough classification for text FBX tokens used for constructing the
55 * basic scope hierarchy. */
56 enum TokenType
57 {
58 // {
59 TokenType_OPEN_BRACKET = 0,
61 // }
62 TokenType_CLOSE_BRACKET,
64 // '"blablubb"', '2', '*14' - very general token class,
65 // further processing happens at a later stage.
66 TokenType_DATA,
68 //
69 TokenType_BINARY_DATA,
71 // ,
72 TokenType_COMMA,
74 // blubb:
75 TokenType_KEY
76 };
79 /** Represents a single token in a FBX file. Tokens are
80 * classified by the #TokenType enumerated types.
81 *
82 * Offers iterator protocol. Tokens are immutable. */
83 class Token
84 {
86 private:
88 static const unsigned int BINARY_MARKER = static_cast<unsigned int>(-1);
90 public:
92 /** construct a textual token */
93 Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column);
95 /** construct a binary token */
96 Token(const char* sbegin, const char* send, TokenType type, unsigned int offset);
98 ~Token();
100 public:
102 std::string StringContents() const {
103 return std::string(begin(),end());
104 }
106 public:
108 bool IsBinary() const {
109 return column == BINARY_MARKER;
110 }
112 const char* begin() const {
113 return sbegin;
114 }
116 const char* end() const {
117 return send;
118 }
120 TokenType Type() const {
121 return type;
122 }
124 unsigned int Offset() const {
125 ai_assert(IsBinary());
126 return offset;
127 }
129 unsigned int Line() const {
130 ai_assert(!IsBinary());
131 return line;
132 }
134 unsigned int Column() const {
135 ai_assert(!IsBinary());
136 return column;
137 }
139 private:
141 #ifdef DEBUG
142 // full string copy for the sole purpose that it nicely appears
143 // in msvc's debugger window.
144 const std::string contents;
145 #endif
148 const char* const sbegin;
149 const char* const send;
150 const TokenType type;
152 union {
153 const unsigned int line;
154 unsigned int offset;
155 };
156 const unsigned int column;
157 };
159 // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03
160 typedef const Token* TokenPtr;
161 typedef std::vector< TokenPtr > TokenList;
163 #define new_Token new Token
166 /** Main FBX tokenizer function. Transform input buffer into a list of preprocessed tokens.
167 *
168 * Skips over comments and generates line and column numbers.
169 *
170 * @param output_tokens Receives a list of all tokens in the input data.
171 * @param input_buffer Textual input buffer to be processed, 0-terminated.
172 * @throw DeadlyImportError if something goes wrong */
173 void Tokenize(TokenList& output_tokens, const char* input);
176 /** Tokenizer function for binary FBX files.
177 *
178 * Emits a token list suitable for direct parsing.
179 *
180 * @param output_tokens Receives a list of all tokens in the input data.
181 * @param input_buffer Binary input buffer to be processed.
182 * @param length Length of input buffer, in bytes. There is no 0-terminal.
183 * @throw DeadlyImportError if something goes wrong */
184 void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int length);
187 } // ! FBX
188 } // ! Assimp
190 #endif // ! INCLUDED_AI_FBX_PARSER_H