You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

191 lines
4.8 KiB

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