vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/FBXTokenizer.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,190 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file FBXTokenizer.h 1.45 + * @brief FBX lexer 1.46 + */ 1.47 +#ifndef INCLUDED_AI_FBX_TOKENIZER_H 1.48 +#define INCLUDED_AI_FBX_TOKENIZER_H 1.49 + 1.50 +#include <boost/shared_ptr.hpp> 1.51 + 1.52 +#include "FBXCompileConfig.h" 1.53 + 1.54 +namespace Assimp { 1.55 +namespace FBX { 1.56 + 1.57 +/** Rough classification for text FBX tokens used for constructing the 1.58 + * basic scope hierarchy. */ 1.59 +enum TokenType 1.60 +{ 1.61 + // { 1.62 + TokenType_OPEN_BRACKET = 0, 1.63 + 1.64 + // } 1.65 + TokenType_CLOSE_BRACKET, 1.66 + 1.67 + // '"blablubb"', '2', '*14' - very general token class, 1.68 + // further processing happens at a later stage. 1.69 + TokenType_DATA, 1.70 + 1.71 + // 1.72 + TokenType_BINARY_DATA, 1.73 + 1.74 + // , 1.75 + TokenType_COMMA, 1.76 + 1.77 + // blubb: 1.78 + TokenType_KEY 1.79 +}; 1.80 + 1.81 + 1.82 +/** Represents a single token in a FBX file. Tokens are 1.83 + * classified by the #TokenType enumerated types. 1.84 + * 1.85 + * Offers iterator protocol. Tokens are immutable. */ 1.86 +class Token 1.87 +{ 1.88 + 1.89 +private: 1.90 + 1.91 + static const unsigned int BINARY_MARKER = static_cast<unsigned int>(-1); 1.92 + 1.93 +public: 1.94 + 1.95 + /** construct a textual token */ 1.96 + Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column); 1.97 + 1.98 + /** construct a binary token */ 1.99 + Token(const char* sbegin, const char* send, TokenType type, unsigned int offset); 1.100 + 1.101 + ~Token(); 1.102 + 1.103 +public: 1.104 + 1.105 + std::string StringContents() const { 1.106 + return std::string(begin(),end()); 1.107 + } 1.108 + 1.109 +public: 1.110 + 1.111 + bool IsBinary() const { 1.112 + return column == BINARY_MARKER; 1.113 + } 1.114 + 1.115 + const char* begin() const { 1.116 + return sbegin; 1.117 + } 1.118 + 1.119 + const char* end() const { 1.120 + return send; 1.121 + } 1.122 + 1.123 + TokenType Type() const { 1.124 + return type; 1.125 + } 1.126 + 1.127 + unsigned int Offset() const { 1.128 + ai_assert(IsBinary()); 1.129 + return offset; 1.130 + } 1.131 + 1.132 + unsigned int Line() const { 1.133 + ai_assert(!IsBinary()); 1.134 + return line; 1.135 + } 1.136 + 1.137 + unsigned int Column() const { 1.138 + ai_assert(!IsBinary()); 1.139 + return column; 1.140 + } 1.141 + 1.142 +private: 1.143 + 1.144 +#ifdef DEBUG 1.145 + // full string copy for the sole purpose that it nicely appears 1.146 + // in msvc's debugger window. 1.147 + const std::string contents; 1.148 +#endif 1.149 + 1.150 + 1.151 + const char* const sbegin; 1.152 + const char* const send; 1.153 + const TokenType type; 1.154 + 1.155 + union { 1.156 + const unsigned int line; 1.157 + unsigned int offset; 1.158 + }; 1.159 + const unsigned int column; 1.160 +}; 1.161 + 1.162 +// XXX should use C++11's unique_ptr - but assimp's need to keep working with 03 1.163 +typedef const Token* TokenPtr; 1.164 +typedef std::vector< TokenPtr > TokenList; 1.165 + 1.166 +#define new_Token new Token 1.167 + 1.168 + 1.169 +/** Main FBX tokenizer function. Transform input buffer into a list of preprocessed tokens. 1.170 + * 1.171 + * Skips over comments and generates line and column numbers. 1.172 + * 1.173 + * @param output_tokens Receives a list of all tokens in the input data. 1.174 + * @param input_buffer Textual input buffer to be processed, 0-terminated. 1.175 + * @throw DeadlyImportError if something goes wrong */ 1.176 +void Tokenize(TokenList& output_tokens, const char* input); 1.177 + 1.178 + 1.179 +/** Tokenizer function for binary FBX files. 1.180 + * 1.181 + * Emits a token list suitable for direct parsing. 1.182 + * 1.183 + * @param output_tokens Receives a list of all tokens in the input data. 1.184 + * @param input_buffer Binary input buffer to be processed. 1.185 + * @param length Length of input buffer, in bytes. There is no 0-terminal. 1.186 + * @throw DeadlyImportError if something goes wrong */ 1.187 +void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int length); 1.188 + 1.189 + 1.190 +} // ! FBX 1.191 +} // ! Assimp 1.192 + 1.193 +#endif // ! INCLUDED_AI_FBX_PARSER_H