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  /// Access a const object by index
77  SYS_NO_DISCARD_RESULT const UT_JSONValueMap* getObject(int64 i) const;
78  /// Access an object by index
80 
81  /// Import an array of integer 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(int64 *result, int64 size) const;
85  /// Import an array of float values (fails if the array size is too small
86  /// or if one of the elements of the array cannot be interpreted as an
87  /// integer).
88  bool import(fpreal64 *result, int64 size) const;
89 
90  /// Import an array of integer values (fails if the elements of the array
91  /// cannot be interpreted as an integer).
92  bool import(UT_Array<int64> &array) const;
93  /// Import an array of real values (fails if the elements of the array
94  /// cannot be interpreted as such).
95  bool import(UT_Array<fpreal64> &array) const;
96  /// Import an array of string values (fails if the elements of the array
97  /// cannot be interpreted as such).
98  bool import(UT_StringArray &array) const;
99 
100  /// Add an element to the array
101  int64 append(UT_JSONValue *v) { return myArray.append(v); }
102 
103  /// Remove and delete an element by index.
104  void remove(int64 index);
105 
106  /// Remove and delete an element.
107  void remove(UT_JSONValue *v);
108 
109  /// Remove and delete the last added element.
110  void removeLast();
111 
112  /// Remove and delete all elements.
113  void clear();
114 
115  /// Inserts a value v before the given element after_value.
116  void insertBefore(UT_JSONValue* v, UT_JSONValue* after_value);
117 
118  /// Adds a new array child to this map.
119  UT_JSONValueArray *appendArrayChild();
120 
121  /// Adds a new map child to this map.
122  UT_JSONValueMap *appendMapChild();
123 
124 private:
125  template <typename ARRAY_T>
126  bool importArray(ARRAY_T &array) const;
127 
128 private:
129  UT_Array<UT_JSONValue *> myArray;
130  SYS_AtomicInt32 myRef;
131 };
132 
133 #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:34
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.
double fpreal64
Definition: SYS_Types.h:201
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:93
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:77
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.