Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
satoruhiga committed Apr 3, 2012
1 parent 951ed93 commit 035f3fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
17 changes: 12 additions & 5 deletions example-test/src/testApp.cpp
Expand Up @@ -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");
}

{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/ofxValue.cpp
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions src/ofxValue.h
Expand Up @@ -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_; }

Expand All @@ -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)
Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 035f3fd

Please sign in to comment.