summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/Value.h
blob: 242ec8781b8baa858c0508870fe03c79a5f3f812 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2014-2015 Kim Kulling

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.
-----------------------------------------------------------------------------------------------*/
#pragma once

#include <openddlparser/OpenDDLCommon.h>

#include <string>

BEGIN_ODDLPARSER_NS

struct ValueAllocator;

///------------------------------------------------------------------------------------------------
///	@brief  This class implements a value.
///
///	Values are used to store data types like boolean, integer, floats, double and many mode. To get
///	an overview please check the enum VylueType ( @see Value::ValueType ).
/// Values can be single items or lists of items. They are implemented as linked lists.
///------------------------------------------------------------------------------------------------
class DLL_ODDLPARSER_EXPORT Value {
    friend struct ValueAllocator;

public:
    ///	@brief  This class implements an iterator through a Value list.
    ///
    /// When getting a new value you need to know how to iterate through it. The Value::Iterator
    /// will help you here:
    ///	@code
    /// Value *val = node->getValue();
    /// Value::Iterator it( val );
    /// while( it.hasNext() ) {
    ///     Value v( it.getNext );
    /// }
    /// @endcode
    class DLL_ODDLPARSER_EXPORT Iterator {
    public:
        ///	@brief  The default class constructor.
        Iterator();

        ///	@brief  The class constructor with the start value.
        /// @param  start   [in] The first value for iteration,
        Iterator( Value *start );

        Iterator( const Iterator &rhs );

        ///	@brief  The class destructor.
        ~Iterator();

        ///	@brief  Will return true, if another value is in the list.
        /// @return true if another value is there.
        bool hasNext() const;

        ///	@brief  Returns the next item and moves the iterator to it.
        ///	@return The next value, is ddl_nullptr in case of being the last item.
        Value *getNext();

        ///	@brief  The post-increment operator.
        const Iterator operator++( int );

        ///	@brief  The pre-increment operator.
        Iterator &operator++( );

        ///	@brief  The compare operator.
        /// @param  rhs [in] The instance to compare.
        /// @return true if equal.
        bool operator == ( const Iterator &rhs ) const;

        /// @brief  The * operator.
        /// @return The instance or ddl_nullptr if end of list is reached.
        Value *operator->( ) const;

    private:
        Value *m_start;
        Value *m_current;

    private:
        Iterator &operator = ( const Iterator & );
    };

    ///	@brief  This enum describes the data type stored in the value.
    enum ValueType {
        ddl_none = -1,          ///< Nothing specified
        ddl_bool = 0,           ///< A boolean type
        ddl_int8,               ///< Integer type, 8 bytes
        ddl_int16,              ///< Integer type, 16 bytes
        ddl_int32,              ///< Integer type, 32 bytes
        ddl_int64,              ///< Integer type, 64 bytes
        ddl_unsigned_int8,      ///< Unsigned integer type, 8 bytes
        ddl_unsigned_int16,     ///< Unsigned integer type, 16 bytes
        ddl_unsigned_int32,     ///< Unsigned integer type, 32 bytes
        ddl_unsigned_int64,     ///< Unsigned integer type, 64 bytes
        ddl_half,               ///< Half data type.
        ddl_float,              ///< float data type
        ddl_double,             ///< Double data type.
        ddl_string,             ///< String data type.
        ddl_ref,                ///< Reference, used to define references to other data definitions.
        ddl_types_max           ///< Upper limit.
    };

    ///	@brief  The class constructor.
    /// @param  type        [in] The value type.
    Value( ValueType type );

    ///	@brief  The class destructor.
    ~Value();

    ///	@brief  Assigns a boolean to the value.
    /// @param  value       [in9 The value.
    void setBool( bool value );

    ///	@brief  Returns the boolean value.
    /// @return The boolean value.
    bool getBool();

    ///	@brief  Assigns a int8 to the value.
    /// @param  value       [in] The value.
    void setInt8( int8 value );

    ///	@brief  Returns the int8 value.
    /// @return The int8 value.
    int8 getInt8();

    ///	@brief  Assigns a int16 to the value.
    /// @param  value       [in] The value.
    void setInt16( int16 value );

    ///	@brief  Returns the int16 value.
    /// @return The int16 value.
    int16 getInt16();

    ///	@brief  Assigns a int32 to the value.
    /// @param  value       [in] The value.
    void setInt32( int32 value );

    ///	@brief  Returns the int16 value.
    /// @return The int32 value.
    int32 getInt32();

    ///	@brief  Assigns a int64 to the value.
    /// @param  value       [in] The value.
    void setInt64( int64 value );

    ///	@brief  Returns the int16 value.
    /// @return The int64 value.
    int64 getInt64();

    ///	@brief  Assigns a unsigned int8 to the value.
    /// @param  value       [in] The value.
    void setUnsignedInt8( uint8 value );

    ///	@brief  Returns the unsigned int8 value.
    /// @return The unsigned int8 value.
    uint8 getUnsignedInt8() const;

    ///	@brief  Assigns a unsigned int16 to the value.
    /// @param  value       [in] The value.
    void setUnsignedInt16( uint16 value );

    ///	@brief  Returns the unsigned int16 value.
    /// @return The unsigned int16 value.
    uint16 getUnsignedInt16() const;

    ///	@brief  Assigns a unsigned int32 to the value.
    /// @param  value       [in] The value.
    void setUnsignedInt32( uint32 value );

    ///	@brief  Returns the unsigned int8 value.
    /// @return The unsigned int32 value.
    uint32 getUnsignedInt32() const;

    ///	@brief  Assigns a unsigned int64 to the value.
    /// @param  value       [in] The value.
    void setUnsignedInt64( uint64 value );

    ///	@brief  Returns the unsigned int64 value.
    /// @return The unsigned int64 value.
    uint64 getUnsignedInt64() const;

    ///	@brief  Assigns a float to the value.
    /// @param  value       [in] The value.
    void setFloat( float value );

    ///	@brief  Returns the float value.
    /// @return The float value.
    float getFloat() const;

    ///	@brief  Assigns a double to the value.
    /// @param  value       [in] The value.
    void setDouble( double value );

    ///	@brief  Returns the double value.
    /// @return The double value.
    double getDouble() const;

    ///	@brief  Assigns a std::string to the value.
    /// @param  value       [in] The value.
    void setString( const std::string &str );

    ///	@brief  Returns the std::string value.
    /// @return The std::string value.
    const char *getString() const;

    /// @brief  Set the reference.
    /// @param  ref     [in] Pointer showing to the reference.
    void setRef( Reference *ref );

    /// @brief  Returns the pointer showing to the reference.
    /// @return Pointer showing to the reference.
    Reference *getRef() const;

    ///	@brief  Dumps the value.
    void dump();

    ///	@brief  Assigns the next value.
    ///	@param  next        [n] The next value.
    void setNext( Value *next );

    ///	@brief  Returns the next value.
    /// @return The next value.s
    Value *getNext() const;

    /// @brief  Gets the length of the array.
    /// @return The number of items in the array.
    size_t size();

    ValueType m_type;
    size_t m_size;
    unsigned char *m_data;
    Value *m_next;

private:
    Value &operator =( const Value & ) ddl_no_copy;
    Value( const Value  & ) ddl_no_copy;
};

///------------------------------------------------------------------------------------------------
///	@brief  This class implements the value allocator.
///------------------------------------------------------------------------------------------------
struct DLL_ODDLPARSER_EXPORT ValueAllocator {
    static Value *allocPrimData( Value::ValueType type, size_t len = 1 );
    static void releasePrimData( Value **data );

private:
    ValueAllocator() ddl_no_copy;
    ValueAllocator( const ValueAllocator  & ) ddl_no_copy;
    ValueAllocator &operator = ( const ValueAllocator & ) ddl_no_copy;
};

END_ODDLPARSER_NS