diff --git a/example-test/src/testApp.cpp b/example-test/src/testApp.cpp index 6c8f206..b978be9 100644 --- a/example-test/src/testApp.cpp +++ b/example-test/src/testApp.cpp @@ -57,6 +57,12 @@ void testApp::setup() v = ofxValue(); assert(v.isNull()); + + v = 42.0f; + assert(v.as() == 42); + assert(v.as() == 42); + assert(v.as() == 42); + assert(v.as() == "42"); } { @@ -168,6 +174,9 @@ void testApp::setup() v["submap"]["1"] = 10; v["submap"]["2"] = 10; + assert(v.hasKey("submap")); + assert(v["submap"].hasKey("0")); + for (int i = 0; i < 3; i++) { assert(v["submap"][ofToString(i)] == 10); @@ -198,11 +207,9 @@ void testApp::setup() v["array"][4]["test1"] = 70; v["array"][4]["test2"] = 80; - string d = v.toJson(); - cout << d << endl; - - ofxValue s = ofxValue::fromJson(d); - assert(d == s.toJson()); + string d = v.toJSON(); + ofxValue s = ofxValue::fromJSON(d); + assert(d == s.toJSON()); } cout << "TEST PASSED" << endl; diff --git a/src/ofxValue.cpp b/src/ofxValue.cpp index 637cd34..43b09a1 100644 --- a/src/ofxValue.cpp +++ b/src/ofxValue.cpp @@ -62,7 +62,7 @@ static string to_json(ofxValue& v, int indent_level) return ""; } -string ofxValue::toJson() +string ofxValue::toJSON() { return to_json(*this, 0); } @@ -102,7 +102,7 @@ static ofxValue from_json(picojson::value j) return v; } -ofxValue ofxValue::fromJson(string json) +ofxValue ofxValue::fromJSON(string json) { value j; string err; diff --git a/src/ofxValue.h b/src/ofxValue.h index 0c96859..786dca6 100644 --- a/src/ofxValue.h +++ b/src/ofxValue.h @@ -56,8 +56,10 @@ class ofxValue inline bool isString() const { return type == STRING_TYPE; } inline bool isArray() const { return type == ARRAY_TYPE; } inline bool isMap() const { return type == MAP_TYPE; } + + inline const size_t size() const; - // Array utilitys + // Array utilities inline ArrayType& array() { assert(isArray()); return *array_; } @@ -67,20 +69,19 @@ class ofxValue inline ofxValue pop(); inline ofxValue remove(size_t index); - inline const size_t size() const; - inline bool hasKey(const string& key) const; - // Map utilitys + // Map utilities inline MapType& map() { assert(isMap()); return *map_; } inline ofxValue& operator[](const string& key); inline ofxValue remove(const string &key); + inline bool hasKey(const string& key) const; + inline vector keys() const; inline vector values() const; - // operators friend inline bool operator==(const ofxValue& v1, const ofxValue& v2) @@ -118,10 +119,10 @@ class ofxValue template friend inline bool operator<=(const T& o, const ofxValue& v) { return !operator>(o, v); } - // serialization + // json serialization - string toJson(); - static ofxValue fromJson(string json); + string toJSON(); + static ofxValue fromJSON(string json); protected: