-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfbx.hpp
202 lines (165 loc) · 5.66 KB
/
fbx.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* MIT License
*
* Copyright(c) 2018 Jimmie Bergmann
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef FBX_HPP_GUARD
#define FBX_HPP_GUARD
#include <string>
#include <list>
#include <map>
#include <vector>
#include <functional>
namespace Fbx
{
class Property
{
public:
union Value
{
bool boolean;
int16_t integer16;
int32_t integer32;
int64_t integer64;
float float32;
double float64;
};
enum class Type
{
Boolean,
Integer16,
Integer32,
Integer64,
Float32,
Float64,
BooleanArray,
Integer32Array,
Integer64Array,
Float32Array,
Float64Array,
String,
Raw
};
Property(const bool primitive);
Property(const int16_t primitive);
Property(const int32_t primitive);
Property(const int64_t primitive);
Property(const float primitive);
Property(const double primitive);
Property(const bool * array, const uint32_t count);
Property(const int32_t * array, const uint32_t count);
Property(const int64_t * array, const uint32_t count);
Property(float * array, const uint32_t count);
Property(const double * array, const uint32_t count);
Property(const char * string);
Property(const std::string & string);
Property(const uint8_t * raw, const uint32_t size);
Type type() const;
uint8_t code() const;
Value & primitive();
const Value & primitive() const;
std::vector<Value> & array();
const std::vector<Value> & array() const;
std::string string() const;
std::vector<uint8_t> & raw();
const std::vector<uint8_t> & raw() const;
uint32_t size() const;
bool isPrimitive() const;
bool isArray() const;
bool isString() const;
bool isRaw() const;
private:
Type m_type;
Value m_primitive;
std::vector<Value> m_array;
std::vector<uint8_t> m_raw;
};
class PropertyList
{
public:
typedef std::list<Property *>::iterator Iterator;
typedef std::list<Property *>::const_iterator ConstIterator;
PropertyList();
~PropertyList();
size_t size() const;
Iterator insert(Property * property);
Iterator insert(Iterator position, Property * property);
Iterator begin();
ConstIterator begin() const;
Iterator end();
ConstIterator end() const;
Property * front();
const Property * front() const;
Property * back();
const Property * back() const;
Iterator erase(Property * property);
Iterator erase(Iterator position);
void clear();
private:
PropertyList(PropertyList &);
std::list<Property *> m_properties;
};
class Record
{
public:
typedef std::list<Record *>::iterator Iterator;
typedef std::list<Record *>::const_iterator ConstIterator;
Record();
Record(const std::string & name);
Record(const std::string & name, Record * parent);
~Record();
void read(const std::string & filename);
void read(const std::string & filename, std::function<void(std::string, uint32_t)> onHeaderRead);
void write(const std::string & filename) const;
void write(const std::string & filename, const uint32_t version) const;
const std::string & name() const;
void name(const std::string & name);
Record * parent();
const Record * parent() const;
void parent(Record * parent);
PropertyList & properties();
const PropertyList & properties() const;
size_t size() const;
Iterator insert(Record * record);
Iterator insert(Iterator position, Record * record);
Iterator begin();
ConstIterator begin() const;
Iterator end();
ConstIterator end() const;
Record * front();
const Record * front() const;
Record * back();
const Record * back() const;
Iterator find(const std::string & name);
ConstIterator find(const std::string & name) const;
Iterator erase(Record * record);
Iterator erase(Iterator position);
void clear();
private:
Record(const Record &);
std::string m_name;
Record * m_pParent;
PropertyList m_properties;
std::list<Record *> m_nestedList;
};
}
#endif