00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * NAME: UT_JSONValueMap.h ( UT Library, C++) 00014 * 00015 * COMMENTS: The order is maintained as objects are added to the map 00016 */ 00017 00018 #ifndef __UT_JSONValueMap__ 00019 #define __UT_JSONValueMap__ 00020 00021 #include "UT_API.h" 00022 #include "UT_PtrArray.h" 00023 #include "UT_SymbolTable.h" 00024 #include <SYS/SYS_AtomicInt.h> 00025 #include <SYS/SYS_AtomicIntImpl.h> 00026 00027 class UT_JSONValue; 00028 class UT_JSONWriter; 00029 class UT_StringArray; 00030 00031 /// @brief UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects 00032 /// 00033 /// UT_JSONValueMap stores a map of UT_JSONValue objects. Unlike a standard 00034 /// Houdini UT_SymbolTable, this object maintains the sort order in which 00035 /// objects were added. 00036 /// 00037 /// @see UT_JSONValue, UT_JSONValueArray 00038 class UT_API UT_JSONValueMap { 00039 public: 00040 UT_JSONValueMap(); 00041 ~UT_JSONValueMap(); 00042 00043 /// Reference count (for shared maps). 00044 void bumpRef(int d) 00045 { 00046 if (!myRef.add(d)) 00047 delete this; 00048 } 00049 /// Get the number of references to this map. 00050 int getRef() const { return myRef; } 00051 00052 /// Save to an output stream 00053 bool save(UT_JSONWriter &os) const; 00054 00055 /// Get the list of keys 00056 int64 getKeys(UT_StringArray &keys) const; 00057 00058 /// Get a list of the keys. However, rather than duplicating the string 00059 /// values, this method simply keeps shallow references. While it's more 00060 /// efficient, it's also relies on the fact that the map will not change 00061 /// while the string array exists. 00062 int64 getKeyReferences(UT_StringArray &keys) const; 00063 00064 /// Return the number of entries in the map 00065 int64 entries() const { return myArray.entries(); } 00066 00067 /// Access const entry by index 00068 const UT_JSONValue *operator()(int64 i) const { return get(i); } 00069 /// Access entry by index 00070 UT_JSONValue *operator()(int64 i) { return get(i); } 00071 /// Access const entry by name (may be NULL pointer if k is not a key) 00072 const UT_JSONValue *operator()(const char *k) const { return get(k); } 00073 /// Access entry by name (may be NULL pointer if k is not a key) 00074 UT_JSONValue *operator()(const char *k) { return get(k); } 00075 00076 /// Access const entry by index 00077 const UT_JSONValue *operator[](int64 i) const { return get(i); } 00078 /// Access entry by index 00079 UT_JSONValue *operator[](int64 i) { return get(i); } 00080 /// Access const entry by name (may be NULL pointer if k is not a key) 00081 const UT_JSONValue *operator[](const char *k) const { return get(k); } 00082 /// Access entry by name (may be NULL pointer if k is not a key) 00083 UT_JSONValue *operator[](const char *k) { return get(k); } 00084 00085 /// Access a const entry by index 00086 const UT_JSONValue *get(int64 i) const { return myArray(i); } 00087 /// Access an entry by index 00088 UT_JSONValue *get(int64 i) { return myArray(i); } 00089 /// Access const entry by name (may be NULL pointer if k is not a key) 00090 const UT_JSONValue *get(const char *k) const; 00091 /// Access entry by name (may be NULL pointer if k is not a key) 00092 UT_JSONValue *get(const char *k); 00093 00094 /// Add key/value pair to the map. If the key already exists, the previous 00095 /// value will be deleted. 00096 int64 append(const char *key, UT_JSONValue *v); 00097 private: 00098 UT_PtrArray<UT_JSONValue *> myArray; 00099 UT_SymbolTable myMap; 00100 SYS_AtomicInt32 myRef; 00101 }; 00102 00103 #endif 00104
1.5.9