| 1 | /* |
| 2 | Open Asset Import Library (assimp) |
| 3 | ---------------------------------------------------------------------- |
| 4 | |
| 5 | Copyright (c) 2006-2025, assimp team |
| 6 | |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use of this software in source and binary forms, |
| 10 | with or without modification, are permitted provided that the |
| 11 | following conditions are met: |
| 12 | |
| 13 | * Redistributions of source code must retain the above |
| 14 | copyright notice, this list of conditions and the |
| 15 | following disclaimer. |
| 16 | |
| 17 | * Redistributions in binary form must reproduce the above |
| 18 | copyright notice, this list of conditions and the |
| 19 | following disclaimer in the documentation and/or other |
| 20 | materials provided with the distribution. |
| 21 | |
| 22 | * Neither the name of the assimp team, nor the names of its |
| 23 | contributors may be used to endorse or promote products |
| 24 | derived from this software without specific prior |
| 25 | written permission of the assimp team. |
| 26 | |
| 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | |
| 39 | ---------------------------------------------------------------------- |
| 40 | */ |
| 41 | |
| 42 | /** @file FBXUtil.h |
| 43 | * @brief FBX utility functions for internal use |
| 44 | */ |
| 45 | #ifndef INCLUDED_AI_FBX_UTIL_H |
| 46 | #define INCLUDED_AI_FBX_UTIL_H |
| 47 | |
| 48 | #include "FBXCompileConfig.h" |
| 49 | #include "FBXTokenizer.h" |
| 50 | #include <stdint.h> |
| 51 | |
| 52 | namespace Assimp { |
| 53 | namespace FBX { |
| 54 | |
| 55 | namespace Util { |
| 56 | |
| 57 | /** helper for std::for_each to delete all heap-allocated items in a container */ |
| 58 | template<typename T> |
| 59 | struct delete_fun |
| 60 | { |
| 61 | void operator()(const volatile T* del) { |
| 62 | delete del; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | /** helper for std::for_each to call the destructor on all items in a container without freeing their heap*/ |
| 67 | template <typename T> |
| 68 | struct destructor_fun { |
| 69 | void operator()(const volatile T* del) { |
| 70 | if (del) { |
| 71 | del->~T(); |
| 72 | } |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | /** Get a string representation for a #TokenType. */ |
| 78 | const char* TokenTypeString(TokenType t); |
| 79 | |
| 80 | |
| 81 | |
| 82 | /** Format log/error messages using a given offset in the source binary file |
| 83 | * |
| 84 | * @param offset offset within the file |
| 85 | * @return A string of the following format: " (offset 0x{offset}) "*/ |
| 86 | std::string GetOffsetText(size_t offset); |
| 87 | |
| 88 | /** Format log/error messages using a given line location in the source file. |
| 89 | * |
| 90 | * @param line Line index, 1-based |
| 91 | * @param column Column index, 1-based |
| 92 | * @return A string of the following format: " (line {line}, col {column}) "*/ |
| 93 | std::string GetLineAndColumnText(unsigned int line, unsigned int column); |
| 94 | |
| 95 | /** Format log/error messages using a given cursor token. |
| 96 | * |
| 97 | * @param tok Token where parsing/processing stopped |
| 98 | * @return A string of the following format: " ({token-type}, line {line}, col {column}) "*/ |
| 99 | std::string GetTokenText(const Token* tok); |
| 100 | |
| 101 | /** Decode a single Base64-encoded character. |
| 102 | * |
| 103 | * @param ch Character to decode (from base64 to binary). |
| 104 | * @return decoded byte value*/ |
| 105 | uint8_t DecodeBase64(char ch); |
| 106 | |
| 107 | /** Compute decoded size of a Base64-encoded string |
| 108 | * |
| 109 | * @param in Characters to decode. |
| 110 | * @param inLength Number of characters to decode. |
| 111 | * @return size of the decoded data (number of bytes)*/ |
| 112 | size_t ComputeDecodedSizeBase64(const char* in, size_t inLength); |
| 113 | |
| 114 | /** Decode a Base64-encoded string |
| 115 | * |
| 116 | * @param in Characters to decode. |
| 117 | * @param inLength Number of characters to decode. |
| 118 | * @param out Pointer where we will store the decoded data. |
| 119 | * @param maxOutLength Size of output buffer. |
| 120 | * @return size of the decoded data (number of bytes)*/ |
| 121 | size_t DecodeBase64(const char* in, size_t inLength, uint8_t* out, size_t maxOutLength); |
| 122 | |
| 123 | char EncodeBase64(char byte); |
| 124 | |
| 125 | /** Encode bytes in base64-encoding |
| 126 | * |
| 127 | * @param data Binary data to encode. |
| 128 | * @param inLength Number of bytes to encode. |
| 129 | * @return base64-encoded string*/ |
| 130 | std::string EncodeBase64(const char* data, size_t length); |
| 131 | |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | #endif // ! INCLUDED_AI_FBX_UTIL_H |
| 137 | |