rename the set() methods
authorSean Middleditch <sean@middleditch.us>
Tue, 12 Jan 2010 23:14:57 +0000 (15:14 -0800)
committerSean Middleditch <sean@middleditch.us>
Tue, 12 Jan 2010 23:14:57 +0000 (15:14 -0800)
janssonxx.h
test.cc

index cfc1058..b60e8cf 100644 (file)
@@ -144,7 +144,7 @@ public:
        bool as_boolean() const { return is_true(); }
 
        // set an object property (converts value to object is not one already)
-       Value& set(const char* key, const Value& value) {
+       Value& set_key(const char* key, const Value& value) {
                if (!is_object()) {
                        json_decref(_value);
                        _value = json_object();
@@ -155,8 +155,12 @@ public:
                return *this;
        }
 
+       Value& set_key(const std::string& key, const Value& value) {
+               return set_key(key.c_str(), value);
+       }
+
        // set an array index (converts value to object is not one already)
-       Value& set(unsigned int index, const Value& value) {
+       Value& set_at(unsigned int index, const Value& value) {
                if (!is_array()) {
                        json_decref(_value);
                        _value = json_array();
@@ -170,7 +174,9 @@ public:
                return *this;
        }
 
-       Value& set(int index, const Value& value) { return set(static_cast<unsigned int>(index), value); }
+       Value& set_at(int index, const Value& value) {
+               return set_at(static_cast<unsigned int>(index), value);
+       }
 
 private:
        // take ownership of a json_t (does not increase reference count)
diff --git a/test.cc b/test.cc
index daacbea..66ce7bb 100644 (file)
--- a/test.cc
+++ b/test.cc
@@ -69,39 +69,39 @@ int main() {
        e3 = jansson::Value::null();
        ASSERT_TRUE(e3.is_null(), "e3 is not null after assignment");
 
-       e3.set(0, jansson::Value::from("foobar"));
+       e3.set_at(0, jansson::Value::from("foobar"));
        ASSERT_TRUE(e3.is_array(), "e3 is not an array after index assignment");
        ASSERT_EQ(e3.size(), 1, "e3 has incorrect number of elements after assignment");
        ASSERT_EQ(e3[0].as_string(), "foobar", "e3[0] has incorrect value after assignment");
 
-       e3.set(1, jansson::Value::from("foobar"));
+       e3.set_at(1, jansson::Value::from("foobar"));
        ASSERT_TRUE(e3.is_array(), "e3 is not an array after index assignment");
        ASSERT_EQ(e3.size(), 2, "e3 has incorrect number of elements after assignment");
        ASSERT_EQ(e3[1].as_string(), "foobar", "e3[0] has incorrect value after assignment");
 
-       e3.set(0, jansson::Value::from("barfoo"));
+       e3.set_at(0, jansson::Value::from("barfoo"));
        ASSERT_TRUE(e3.is_array(), "e3 is not an array after index assignment");
        ASSERT_EQ(e3.size(), 2, "e3 has incorrect number of elements after assignment");
        ASSERT_EQ(e3[0].as_string(), "barfoo", "e3[0] has incorrect value after assignment");
 
-       e3.set(100, jansson::Value::null());
+       e3.set_at(100, jansson::Value::null());
        ASSERT_TRUE(e3.is_array(), "e3 is not an array after index assignment");
        ASSERT_EQ(e3.size(), 2, "e3 has incorrect number of elements after assignment");
 
        e3.clear();
        ASSERT_EQ(e3.size(), 0, "e3 has incorrect number of elements after clear");
 
-       e3.set("foo", jansson::Value::from("test"));
+       e3.set_key("foo", jansson::Value::from("test"));
        ASSERT_TRUE(e3.is_object(), "e3 is not an object after property assignment");
        ASSERT_EQ(e3.size(), 1, "e3 has incorrect number of properties after assignment");
        ASSERT_EQ(e3["foo"].as_string(), "test", "e3.foo has incorrect value after assignment");
 
-       e3.set("foo", jansson::Value::from("again"));
+       e3.set_key("foo", jansson::Value::from("again"));
        ASSERT_TRUE(e3.is_object(), "e3 is not an object after property assignment");
        ASSERT_EQ(e3.size(), 1, "e3 has incorrect number of properties after assignment");
        ASSERT_EQ(e3["foo"].as_string(), "again", "e3.foo has incorrect value after assignment");
 
-       e3.set("bar", jansson::Value::from("test"));
+       e3.set_key("bar", jansson::Value::from("test"));
        ASSERT_TRUE(e3.is_object(), "e3 is not an object after property assignment");
        ASSERT_EQ(e3.size(), 2, "e3 has incorrect number of properties after assignment");
        ASSERT_EQ(e3["bar"].as_string(), "test", "e3.foo has incorrect value after assignment");
@@ -110,8 +110,8 @@ int main() {
        ASSERT_EQ(e3.size(), 0, "e3 has incorrect number of properties after clear");
 
        e3 = jansson::Value::object();
-       e3.set("foo", jansson::Value::from("test"));
-       e3.set("bar", jansson::Value::from(3));
+       e3.set_key("foo", jansson::Value::from("test"));
+       e3.set_key("bar", jansson::Value::from(3));
        char* out_cstr = e3.save_string(0);
        string out(out_cstr);
        free(out_cstr);