FBXParser.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 FBXParser.h
  34. * @brief FBX parsing code
  35. */
  36. #ifndef INCLUDED_AI_FBX_PARSER_H
  37. #define INCLUDED_AI_FBX_PARSER_H
  38. #include <vector>
  39. #include <map>
  40. #include <string>
  41. #include <boost/shared_ptr.hpp>
  42. #include "LogAux.h"
  43. #include "FBXCompileConfig.h"
  44. #include "FBXTokenizer.h"
  45. namespace Assimp {
  46. namespace FBX {
  47. class Scope;
  48. class Parser;
  49. class Element;
  50. // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03
  51. typedef std::vector< Scope* > ScopeList;
  52. typedef std::fbx_unordered_multimap< std::string, Element* > ElementMap;
  53. # define new_Scope new Scope
  54. # define new_Element new Element
  55. /** FBX data entity that consists of a key:value tuple.
  56. *
  57. * Example:
  58. * @verbatim
  59. * AnimationCurve: 23, "AnimCurve::", "" {
  60. * [..]
  61. * }
  62. * @endverbatim
  63. *
  64. * As can be seen in this sample, elements can contain nested #Scope
  65. * as their trailing member. **/
  66. class Element
  67. {
  68. public:
  69. Element(TokenPtr key_token, Parser& parser);
  70. ~Element();
  71. public:
  72. const Scope* Compound() const {
  73. return compound.get();
  74. }
  75. TokenPtr KeyToken() const {
  76. return key_token;
  77. }
  78. const TokenList& Tokens() const {
  79. return tokens;
  80. }
  81. private:
  82. TokenPtr key_token;
  83. TokenList tokens;
  84. boost::scoped_ptr<Scope> compound;
  85. };
  86. /** FBX data entity that consists of a 'scope', a collection
  87. * of not necessarily unique #Element instances.
  88. *
  89. * Example:
  90. * @verbatim
  91. * GlobalSettings: {
  92. * Version: 1000
  93. * Properties70:
  94. * [...]
  95. * }
  96. * @endverbatim */
  97. class Scope
  98. {
  99. public:
  100. Scope(Parser& parser, bool topLevel = false);
  101. ~Scope();
  102. public:
  103. const Element* operator[] (const std::string& index) const {
  104. ElementMap::const_iterator it = elements.find(index);
  105. return it == elements.end() ? NULL : (*it).second;
  106. }
  107. const ElementMap& Elements() const {
  108. return elements;
  109. }
  110. private:
  111. ElementMap elements;
  112. };
  113. /** FBX parsing class, takes a list of input tokens and generates a hierarchy
  114. * of nested #Scope instances, representing the fbx DOM.*/
  115. class Parser
  116. {
  117. public:
  118. /** Parse given a token list. Does not take ownership of the tokens -
  119. * the objects must persist during the entire parser lifetime */
  120. Parser (const TokenList& tokens);
  121. ~Parser();
  122. public:
  123. const Scope& GetRootScope() const {
  124. return *root.get();
  125. }
  126. private:
  127. friend class Scope;
  128. friend class Element;
  129. TokenPtr AdvanceToNextToken();
  130. TokenPtr LastToken() const;
  131. TokenPtr CurrentToken() const;
  132. private:
  133. const TokenList& tokens;
  134. TokenPtr last, current;
  135. TokenList::const_iterator cursor;
  136. boost::scoped_ptr<Scope> root;
  137. };
  138. /* token parsing - this happens when building the DOM out of the parse-tree*/
  139. uint64_t ParseTokenAsID(const Token& t, const char*& err_out);
  140. uint64_t ParseTokenAsDim(const Token& t, const char*& err_out);
  141. float ParseTokenAsFloat(const Token& t, const char*& err_out);
  142. int ParseTokenAsInt(const Token& t, const char*& err_out);
  143. std::string ParseTokenAsString(const Token& t, const char*& err_out);
  144. } // ! FBX
  145. } // ! Assimp
  146. #endif // ! INCLUDED_AI_FBX_PARSER_H