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 
21 class UT_JSONValue;
22 class UT_JSONWriter;
23 class UT_JSONValueMap;
24 
25 /// @brief UT_JSONValueArray stores a list of UT_JSONValue objects
26 ///
27 /// UT_JSONValueArray stores a list of UT_JSONValue objects.
28 ///
29 /// @see UT_JSONValue, UT_JSONValueMap
31 public:
34 
35  /// Reference count (for shared arrays).
36  void bumpRef(int d)
37  {
38  if (!myRef.add(d))
39  delete this;
40  }
41  /// Get the number of references to this array
42  SYS_FORCE_INLINE int getRef() const { return myRef.relaxedLoad(); }
43 
44  /// Save to an output stream
45  bool save(UT_JSONWriter &os) const;
46 
47  /// Dump to stdout (same as save to std::cout)
48  void dump() const;
49 
50  /// Return size of the array
51  SYS_FORCE_INLINE int64 size() const { return myArray.size(); }
52  /// Return the number of entries in the array
53  SYS_FORCE_INLINE int64 entries() const { return myArray.size(); }
54  /// Access a const entry by index
55  SYS_FORCE_INLINE const UT_JSONValue *operator()(int64 i) const { return myArray[i]; }
56  /// Access an entry by index
58  /// Access a const entry by index
59  SYS_FORCE_INLINE const UT_JSONValue *operator[](int64 i) const { return myArray[i]; }
60  /// Access an entry by index
62 
63  /// Access a const entry by index
64  SYS_FORCE_INLINE const UT_JSONValue *get(int64 i) const { return myArray[i]; }
65  /// Access an entry by index
66  SYS_FORCE_INLINE UT_JSONValue *get(int64 i) { return myArray[i]; }
67 
68  /// Import an array of integer values (fails if the array size is too small
69  /// or if one of the elements of the array cannot be interpreted as an
70  /// integer).
71  bool import(int64 *result, int64 size) const;
72  /// Import an array of float values (fails if the array size is too small
73  /// or if one of the elements of the array cannot be interpreted as an
74  /// integer).
75  bool import(fpreal64 *result, int64 size) const;
76 
77  /// Import an array of integer values (fails if the elements of the array
78  /// cannot be interpreted as an integer).
79  bool import(UT_Array<int64> &array) const;
80  /// Import an array of real values (fails if the elements of the array
81  /// cannot be interpreted as such).
82  bool import(UT_Array<fpreal64> &array) const;
83  /// Import an array of string values (fails if the elements of the array
84  /// cannot be interpreted as such).
85  bool import(UT_StringArray &array) const;
86 
87  /// Add an element to the array
88  int64 append(UT_JSONValue *v) { return myArray.append(v); }
89 
90  /// Remove and delete an element by index.
91  void remove(int64 index);
92 
93  /// Remove and delete an element.
94  void remove(UT_JSONValue *v);
95 
96  /// Remove and delete the last added element.
97  void removeLast();
98 
99  /// Remove and delete all elements.
100  void clear();
101 
102  /// Inserts a value v before the given element after_value.
103  void insertBefore(UT_JSONValue* v, UT_JSONValue* after_value);
104 
105  /// Adds a new array child to this map.
106  UT_JSONValueArray *appendArrayChild();
107 
108  /// Adds a new map child to this map.
109  UT_JSONValueMap *appendMapChild();
110 
111 private:
112  template <typename ARRAY_T>
113  bool importArray(ARRAY_T &array) const;
114 
115 private:
116  UT_Array<UT_JSONValue *> myArray;
117  SYS_AtomicInt32 myRef;
118 };
119 
120 #endif
void bumpRef(int d)
Reference count (for shared arrays).
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
const GLdouble * v
Definition: glcorearb.h:836
UT_JSONValueArray stores a list of UT_JSONValue objects.
#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
png_uint_32 i
Definition: png.h:2877
SYS_FORCE_INLINE const UT_JSONValue * operator[](int64 i) const
Access a const entry by index.
GLsizeiptr size
Definition: glcorearb.h:663
long long int64
Definition: SYS_Types.h:107
double fpreal64
Definition: SYS_Types.h:192
#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.
GLuint index
Definition: glcorearb.h:785
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:75
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.