add proper attribution to janssonxx.h
[jansson.git] / janssonxx.h
index 49975bf..6039646 100644 (file)
@@ -1,3 +1,11 @@
+// janssonxx - C++ wrapper for jansson
+//
+// author: Sean Middleditch <sean@middleditch.us>
+//
+// janssonxx is free software; you can redistribute it and/or modify
+// it under the terms of the MIT license. See LICENSE for details.
+
+
 #if !defined(JANSSONXX_H)
 #define JANSSONXX_H 1
 
@@ -75,7 +83,7 @@ public:
        static Value null() { return Value::_take(json_null()); }
 
        // get the underlying json_t
-       json_t* as_json_t() const { return _value; }
+       json_t* as_json() const { return _value; }
 
        // check value type
        bool is_undefined() const { return _value == 0; }
@@ -149,13 +157,7 @@ public:
 
        // set an object property (converts value to object is not one already)
        Value& set_key(const char* key, const Value& value) {
-               if (!is_object()) {
-                       json_decref(_value);
-                       _value = json_object();
-               }
-
-               json_object_set(_value, key, value.as_json_t());
-
+               json_object_set(_value, key, value.as_json());
                return *this;
        }
 
@@ -165,16 +167,10 @@ public:
 
        // set an array index (converts value to object is not one already)
        Value& set_at(unsigned int index, const Value& value) {
-               if (!is_array()) {
-                       json_decref(_value);
-                       _value = json_array();
-               }
-
                if (index == size())
-                       json_array_append(_value, value.as_json_t());
+                       json_array_append(_value, value.as_json());
                else
-                       json_array_set(_value, index, value.as_json_t());
-
+                       json_array_set(_value, index, value.as_json());
                return *this;
        }
 
@@ -199,12 +195,12 @@ class Iterator {
 public:
        // construct a new iterator for a given object
        Iterator(const Value& value) : _object(value), _iter(0) {
-               _iter = json_object_iter(_object.as_json_t());
+               _iter = json_object_iter(_object.as_json());
        }
 
        // increment iterator
        void next() {
-               _iter = json_object_iter_next(_object.as_json_t(), _iter);
+               _iter = json_object_iter_next(_object.as_json(), _iter);
        }
 
        Iterator& operator++() { next(); return *this; }