HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_JSONValueArray.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_JSONValueArray.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_JSONValueArray__
12 #define __UT_JSONValueArray__
13 
14 #include "UT_API.h"
15 #include "UT_Array.h"
16 #include "UT_StringArray.h"
17 #include "UT_VectorTypes.h"
18 #include <SYS/SYS_AtomicInt.h>
19 #include <SYS/SYS_Inline.h>
20 #include <SYS/SYS_Hash.h>
21 
22 class UT_JSONValue;
23 class UT_JSONWriter;
24 class UT_JSONValueMap;
25 
26 /// @brief UT_JSONValueArray stores a list of UT_JSONValue objects
27 ///
28 /// UT_JSONValueArray stores a list of UT_JSONValue objects.
29 ///
30 /// @see UT_JSONValue, UT_JSONValueMap
32 public:
35 
36  /// Reference count (for shared arrays).
37  void bumpRef(int d)
38  {
39  if (!myRef.add(d))
40  delete this;
41  }
42  /// Get the number of references to this array
43  SYS_FORCE_INLINE int getRef() const { return myRef.relaxedLoad(); }
44 
45  /// Save to an output stream
46  bool save(UT_JSONWriter &os) const;
47 
48  /// Dump to stdout (same as save to std::cout)
49  void dump() const;
50 
51  SYS_HashType hash() const;
52  /// @{
53  /// Check equality
54  bool operator==(const UT_JSONValueArray &arr) const;
55  bool operator!=(const UT_JSONValueArray &arr) const
56  { return !(*this == arr); }
57  /// @}
58 
59  /// Return size of the array
60  SYS_FORCE_INLINE int64 size() const { return myArray.size(); }
61  /// Return the number of entries in the array
62  SYS_FORCE_INLINE int64 entries() const { return myArray.size(); }
63  /// Access a const entry by index
64  SYS_FORCE_INLINE const UT_JSONValue *operator()(int64 i) const { return myArray[i]; }
65  /// Access an entry by index
66  SYS_FORCE_INLINE UT_JSONValue *operator()(int64 i) { return myArray[i]; }
67  /// Access a const entry by index
68  SYS_FORCE_INLINE const UT_JSONValue *operator[](int64 i) const { return myArray[i]; }
69  /// Access an entry by index
70  SYS_FORCE_INLINE UT_JSONValue *operator[](int64 i) { return myArray[i]; }
71 
72  /// Access a const entry by index
73  SYS_FORCE_INLINE const UT_JSONValue *get(int64 i) const { return myArray[i]; }
74  /// Access an entry by index
75  SYS_FORCE_INLINE UT_JSONValue *get(int64 i) { return myArray[i]; }
76 
77  /// Import an array of integer values (fails if the array size is too small
78  /// or if one of the elements of the array cannot be interpreted as an
79  /// integer).
80  bool import(int64 *result, int64 size) const;
81  /// Import an array of float values (fails if the array size is too small
82  /// or if one of the elements of the array cannot be interpreted as an
83  /// integer).
84  bool import(fpreal64 *result, int64 size) const;
85 
86  /// Import an array of integer values (fails if the elements of the array
87  /// cannot be interpreted as an integer).
88  bool import(UT_Array<int64> &array) const;
89  /// Import an array of real values (fails if the elements of the array
90  /// cannot be interpreted as such).
91  bool import(UT_Array<fpreal64> &array) const;
92  /// Import an array of string values (fails if the elements of the array
93  /// cannot be interpreted as such).
94  bool import(UT_StringArray &array) const;
95 
96  /// Add an element to the array
97  int64 append(UT_JSONValue *v) { return myArray.append(v); }
98 
99  /// Remove and delete an element by index.
100  void remove(int64 index);
101 
102  /// Remove and delete an element.
103  void remove(UT_JSONValue *v);
104 
105  /// Remove and delete the last added element.
106  void removeLast();
107 
108  /// Remove and delete all elements.
109  void clear();
110 
111  /// Inserts a value v before the given element after_value.
112  void insertBefore(UT_JSONValue* v, UT_JSONValue* after_value);
113 
114  /// Adds a new array child to this map.
115  UT_JSONValueArray *appendArrayChild();
116 
117  /// Adds a new map child to this map.
118  UT_JSONValueMap *appendMapChild();
119 
120 private:
121  template <typename ARRAY_T>
122  bool importArray(ARRAY_T &array) const;
123 
124 private:
125  UT_Array<UT_JSONValue *> myArray;
126  SYS_AtomicInt32 myRef;
127 };
128 
129 #endif
void bumpRef(int d)
Reference count (for shared arrays).
GLsizeiptr size
Definition: glew.h:1681
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLuint index
Definition: glew.h:1814
UT_JSONValueArray stores a list of UT_JSONValue objects.
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
#define UT_API
Definition: UT_API.h:13
SYS_FORCE_INLINE const UT_JSONValue * operator()(int64 i) const
Access a const entry by index.
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
const GLdouble * v
Definition: glew.h:1391
bool operator!=(const UT_JSONValueArray &arr) const
SYS_FORCE_INLINE const UT_JSONValue * operator[](int64 i) const
Access a const entry by index.
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:111
double fpreal64
Definition: SYS_Types.h:196
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE int64 entries() const
Return the number of entries in the array.
SYS_FORCE_INLINE UT_JSONValue * operator[](int64 i)
Access an entry by index.
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:76
GLuint64EXT * result
Definition: glew.h:14007
GLenum array
Definition: glew.h:9066
SYS_FORCE_INLINE UT_JSONValue * operator()(int64 i)
Access an entry by index.
int64 append(UT_JSONValue *v)
Add an element to the array.
SYS_FORCE_INLINE int getRef() const
Get the number of references to this array.
SYS_FORCE_INLINE int64 size() const
Return size of the array.