FBXTokenizer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_COMMA,
  55. // blubb:
  56. TokenType_KEY
  57. };
  58. /** Represents a single token in a FBX file. Tokens are
  59. * classified by the #TokenType enumerated types.
  60. *
  61. * Offers iterator protocol. Tokens are immutable. */
  62. class Token
  63. {
  64. public:
  65. Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column);
  66. ~Token();
  67. public:
  68. std::string StringContents() const {
  69. return std::string(begin(),end());
  70. }
  71. public:
  72. const char* begin() const {
  73. return sbegin;
  74. }
  75. const char* end() const {
  76. return send;
  77. }
  78. TokenType Type() const {
  79. return type;
  80. }
  81. unsigned int Line() const {
  82. return line;
  83. }
  84. unsigned int Column() const {
  85. return column;
  86. }
  87. private:
  88. #ifdef DEBUG
  89. // full string copy for the sole purpose that it nicely appears
  90. // in msvc's debugger window.
  91. const std::string contents;
  92. #endif
  93. const char* const sbegin;
  94. const char* const send;
  95. const TokenType type;
  96. const unsigned int line, column;
  97. };
  98. // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03
  99. typedef const Token* TokenPtr;
  100. typedef std::vector< TokenPtr > TokenList;
  101. #define new_Token new Token
  102. /** Main FBX tokenizer function. Transform input buffer into a list of preprocessed tokens.
  103. *
  104. * Skips over comments and generates line and column numbers.
  105. *
  106. * @param output_tokens Receives a list of all tokens in the input data.
  107. * @param input_buffer Textual input buffer to be processed, 0-terminated.
  108. * @throw DeadlyImportError if something goes wrong */
  109. void Tokenize(TokenList& output_tokens, const char* input);
  110. } // ! FBX
  111. } // ! Assimp
  112. #endif // ! INCLUDED_AI_FBX_PARSER_H