FIReader.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, 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 FIReader.hpp
  34. /// \brief Reader for Fast Infoset encoded binary XML files.
  35. /// \date 2017
  36. /// \author Patrick Daehne
  37. #ifndef INCLUDED_AI_FI_READER_H
  38. #define INCLUDED_AI_FI_READER_H
  39. #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
  40. //#include <wchar.h>
  41. #include <string>
  42. #include <memory>
  43. #include <cerrno>
  44. #include <cwchar>
  45. #include <vector>
  46. //#include <stdio.h>
  47. //#include <cstdint>
  48. #ifdef ASSIMP_USE_HUNTER
  49. # include <irrXML/irrXML.h>
  50. #else
  51. # include <irrXML.h>
  52. #endif
  53. namespace Assimp {
  54. struct FIValue {
  55. virtual const std::string &toString() const = 0;
  56. virtual ~FIValue() {}
  57. };
  58. struct FIStringValue: public FIValue {
  59. std::string value;
  60. static std::shared_ptr<FIStringValue> create(std::string &&value);
  61. };
  62. struct FIByteValue: public FIValue {
  63. std::vector<uint8_t> value;
  64. };
  65. struct FIHexValue: public FIByteValue {
  66. static std::shared_ptr<FIHexValue> create(std::vector<uint8_t> &&value);
  67. };
  68. struct FIBase64Value: public FIByteValue {
  69. static std::shared_ptr<FIBase64Value> create(std::vector<uint8_t> &&value);
  70. };
  71. struct FIShortValue: public FIValue {
  72. std::vector<int16_t> value;
  73. static std::shared_ptr<FIShortValue> create(std::vector<int16_t> &&value);
  74. };
  75. struct FIIntValue: public FIValue {
  76. std::vector<int32_t> value;
  77. static std::shared_ptr<FIIntValue> create(std::vector<int32_t> &&value);
  78. };
  79. struct FILongValue: public FIValue {
  80. std::vector<int64_t> value;
  81. static std::shared_ptr<FILongValue> create(std::vector<int64_t> &&value);
  82. };
  83. struct FIBoolValue: public FIValue {
  84. std::vector<bool> value;
  85. static std::shared_ptr<FIBoolValue> create(std::vector<bool> &&value);
  86. };
  87. struct FIFloatValue: public FIValue {
  88. std::vector<float> value;
  89. static std::shared_ptr<FIFloatValue> create(std::vector<float> &&value);
  90. };
  91. struct FIDoubleValue: public FIValue {
  92. std::vector<double> value;
  93. static std::shared_ptr<FIDoubleValue> create(std::vector<double> &&value);
  94. };
  95. struct FIUUIDValue: public FIByteValue {
  96. static std::shared_ptr<FIUUIDValue> create(std::vector<uint8_t> &&value);
  97. };
  98. struct FICDATAValue: public FIStringValue {
  99. static std::shared_ptr<FICDATAValue> create(std::string &&value);
  100. };
  101. struct FIDecoder {
  102. virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) = 0;
  103. virtual ~FIDecoder() {}
  104. };
  105. struct FIQName {
  106. const char *name;
  107. const char *prefix;
  108. const char *uri;
  109. };
  110. struct FIVocabulary {
  111. const char **restrictedAlphabetTable;
  112. size_t restrictedAlphabetTableSize;
  113. const char **encodingAlgorithmTable;
  114. size_t encodingAlgorithmTableSize;
  115. const char **prefixTable;
  116. size_t prefixTableSize;
  117. const char **namespaceNameTable;
  118. size_t namespaceNameTableSize;
  119. const char **localNameTable;
  120. size_t localNameTableSize;
  121. const char **otherNCNameTable;
  122. size_t otherNCNameTableSize;
  123. const char **otherURITable;
  124. size_t otherURITableSize;
  125. const std::shared_ptr<const FIValue> *attributeValueTable;
  126. size_t attributeValueTableSize;
  127. const std::shared_ptr<const FIValue> *charactersTable;
  128. size_t charactersTableSize;
  129. const std::shared_ptr<const FIValue> *otherStringTable;
  130. size_t otherStringTableSize;
  131. const FIQName *elementNameTable;
  132. size_t elementNameTableSize;
  133. const FIQName *attributeNameTable;
  134. size_t attributeNameTableSize;
  135. };
  136. class IOStream;
  137. class FIReader: public irr::io::IIrrXMLReader<char, irr::io::IXMLBase> {
  138. public:
  139. virtual ~FIReader();
  140. virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(int idx) const = 0;
  141. virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(const char *name) const = 0;
  142. virtual void registerDecoder(const std::string &algorithmUri, std::unique_ptr<FIDecoder> decoder) = 0;
  143. virtual void registerVocabulary(const std::string &vocabularyUri, const FIVocabulary *vocabulary) = 0;
  144. static std::unique_ptr<FIReader> create(IOStream *stream);
  145. };// class IFIReader
  146. inline
  147. FIReader::~FIReader() {
  148. // empty
  149. }
  150. }// namespace Assimp
  151. #endif // #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
  152. #endif // INCLUDED_AI_FI_READER_H