Permalink
Browse files

small fix

  • Loading branch information...
satoruhiga committed Apr 3, 2012
1 parent 951ed93 commit 035f3fd4288481c3b876a802029e40aa9741569c
Showing with 23 additions and 15 deletions.
  1. +12 −5 example-test/src/testApp.cpp
  2. +2 −2 src/ofxValue.cpp
  3. +9 −8 src/ofxValue.h
@@ -57,6 +57,12 @@ void testApp::setup()
v = ofxValue();
assert(v.isNull());
+
+ v = 42.0f;
+ assert(v.as<long>() == 42);
+ assert(v.as<int>() == 42);
+ assert(v.as<double>() == 42);
+ assert(v.as<string>() == "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;
View
@@ -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;
View
@@ -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<string> keys() const;
inline vector<ofxValue> values() const;
-
// operators
friend inline bool operator==(const ofxValue& v1, const ofxValue& v2)
@@ -118,10 +119,10 @@ class ofxValue
template<typename T>
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:

0 comments on commit 035f3fd

Please sign in to comment.