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