/src/assimp/code/AssetLib/FBX/FBXUtil.h
Line | Count | Source |
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::FBX::Util { |
53 | | |
54 | | /** helper for std::for_each to delete all heap-allocated items in a container */ |
55 | | template<typename T> |
56 | | struct delete_fun |
57 | | { |
58 | 0 | void operator()(const volatile T* del) { |
59 | 0 | delete del; |
60 | 0 | } Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiMesh>::operator()(aiMesh const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiMaterial>::operator()(aiMaterial const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiAnimation>::operator()(aiAnimation const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiLight>::operator()(aiLight const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiCamera>::operator()(aiCamera const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiTexture>::operator()(aiTexture const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiBone>::operator()(aiBone const volatile*) Unexecuted instantiation: Assimp::FBX::Util::delete_fun<aiNodeAnim>::operator()(aiNodeAnim const volatile*) |
61 | | }; |
62 | | |
63 | | /** helper for std::for_each to call the destructor on all items in a container without freeing their heap*/ |
64 | | template <typename T> |
65 | | struct destructor_fun { |
66 | 0 | void operator()(const volatile T* del) { |
67 | 0 | if (del) { |
68 | 0 | del->~T(); |
69 | 0 | } |
70 | 0 | } |
71 | | }; |
72 | | |
73 | | /** Get a string representation for a #TokenType. */ |
74 | | const char* TokenTypeString(TokenType t); |
75 | | |
76 | | /** Format log/error messages using a given offset in the source binary file |
77 | | * |
78 | | * @param offset offset within the file |
79 | | * @return A string of the following format: " (offset 0x{offset}) "*/ |
80 | | std::string GetOffsetText(size_t offset); |
81 | | |
82 | | /** Format log/error messages using a given line location in the source file. |
83 | | * |
84 | | * @param line Line index, 1-based |
85 | | * @param column Column index, 1-based |
86 | | * @return A string of the following format: " (line {line}, col {column}) "*/ |
87 | | std::string GetLineAndColumnText(unsigned int line, unsigned int column); |
88 | | |
89 | | /** Format log/error messages using a given cursor token. |
90 | | * |
91 | | * @param tok Token where parsing/processing stopped |
92 | | * @return A string of the following format: " ({token-type}, line {line}, col {column}) "*/ |
93 | | std::string GetTokenText(const Token* tok); |
94 | | |
95 | | /** Decode a single Base64-encoded character. |
96 | | * |
97 | | * @param ch Character to decode (from base64 to binary). |
98 | | * @return decoded byte value*/ |
99 | | uint8_t DecodeBase64(char ch); |
100 | | |
101 | | /** Compute decoded size of a Base64-encoded string |
102 | | * |
103 | | * @param in Characters to decode. |
104 | | * @param inLength Number of characters to decode. |
105 | | * @return size of the decoded data (number of bytes)*/ |
106 | | size_t ComputeDecodedSizeBase64(const char* in, size_t inLength); |
107 | | |
108 | | /** Decode a Base64-encoded string |
109 | | * |
110 | | * @param in Characters to decode. |
111 | | * @param inLength Number of characters to decode. |
112 | | * @param out Pointer where we will store the decoded data. |
113 | | * @param maxOutLength Size of output buffer. |
114 | | * @return size of the decoded data (number of bytes)*/ |
115 | | size_t DecodeBase64(const char* in, size_t inLength, uint8_t* out, size_t maxOutLength); |
116 | | |
117 | | char EncodeBase64(char byte); |
118 | | |
119 | | /** Encode bytes in base64-encoding |
120 | | * |
121 | | * @param data Binary data to encode. |
122 | | * @param inLength Number of bytes to encode. |
123 | | * @return base64-encoded string*/ |
124 | | std::string EncodeBase64(const char* data, size_t length); |
125 | | |
126 | | } |
127 | | |
128 | | #endif // ! INCLUDED_AI_FBX_UTIL_H |