X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fjansson.hpp;h=c8db40d621b0ca42105c2e44c9312a7cbfeb2289;hb=8b2b12e05fdcb14c19bf2fc31223838b417354cd;hp=020a2771fe4e0d2c6bb67ab77aa4f516706fc123;hpb=2b43e7dbda1726f61b44c535590321dfcddde925;p=jansson.git diff --git a/src/jansson.hpp b/src/jansson.hpp index 020a277..c8db40d 100644 --- a/src/jansson.hpp +++ b/src/jansson.hpp @@ -1,15 +1,21 @@ // Copyright (c) 2010 Sean Middleditch +// Copyright (c) 2010 Petri Lehtinen // // Jansson is free software; you can redistribute it and/or modify // it under the terms of the MIT license. See LICENSE for details. -#if !defined(JANSSON_HPP) -#define JANSSON_HPP 1 +#ifndef JANSSON_HPP +#define JANSSON_HPP #include #include #include #include + +// Included so that standard functions don't end up in namespace json +#include + +// For free() #include namespace json { @@ -20,7 +26,7 @@ namespace json { class Value; // implementation details; do not use directly - namespace _private { + namespace detail { class ElementProxy; class PropertyProxy; @@ -121,10 +127,11 @@ namespace json { inline _Base& insert_at(unsigned int index, const Value& value); // write the value to a file - inline int save_file(const char* path, int flags = 0) const; + inline int dump_file(const char* path, int flags = 0) const; + inline int dump_file(const std::string& path, int flags = 0) const; // write the value to a string (caller must deallocate with free()!) - inline char* save_string(int flags = 0) const; + inline char* dumps(int flags = 0) const; }; // represents any JSON value, private base @@ -159,8 +166,9 @@ namespace json { // proxies an array element class ElementProxy { public: - // constructor - ElementProxy(json_t* array, unsigned int index) : _array(array), _index(index) {} + inline ElementProxy(json_t* array, unsigned int index); + inline ElementProxy(const ElementProxy& other); + inline ~ElementProxy(); // assign to the proxied element inline ElementProxy& operator=(const Value& value); @@ -179,8 +187,9 @@ namespace json { // proxies an object property class PropertyProxy { public: - // constructor - PropertyProxy(json_t* array, const char* key) : _object(array), _key(key) {} + inline PropertyProxy(json_t* object, const char *key); + inline PropertyProxy(const PropertyProxy& other); + inline ~PropertyProxy(); // assign to the proxied element inline PropertyProxy& operator=(const Value& value); @@ -192,14 +201,17 @@ namespace json { // array object we wrap json_t* _object; + // iterator pointing to property + void* _iter; + // key of property - const char* _key; + char* _key; }; - } // namespace json::_private + } // namespace json::detail // represents any JSON value - class Value : public _private::ValueBase<_private::Basic> { + class Value : public detail::ValueBase { public: // construct Value from input explicit inline Value(const char* value); @@ -215,19 +227,19 @@ namespace json { explicit inline Value(double value); // empty constructor - Value() : _private::ValueBase<_private::Basic>() {} + Value() : detail::ValueBase() {} // copy constructor for base - Value(const _private::Basic& value) : _private::ValueBase<_private::Basic>(value) {} + Value(const detail::Basic& value) : detail::ValueBase(value) {} // copy constructor for base - Value(const _private::ValueBase<_private::Basic>& value) : _private::ValueBase<_private::Basic>(value) {} + Value(const detail::ValueBase& value) : detail::ValueBase(value) {} // copy constructor - Value(const Value& value) : _private::ValueBase<_private::Basic>(value) {} + Value(const Value& value) : detail::ValueBase(value) {} // create reference to value - explicit Value(json_t* json) : _private::ValueBase<_private::Basic>(json) {} + explicit Value(json_t* json) : detail::ValueBase(json) {} }; // iterators over a JSON object @@ -237,7 +249,7 @@ namespace json { inline Iterator(const Value& value); // construct a new iterator for a given object - inline Iterator(const _private::ValueBase<_private::PropertyProxy>& value); + inline Iterator(const detail::ValueBase& value); // increment iterator inline void next(); @@ -283,9 +295,11 @@ namespace json { // load a file as a JSON value inline Value load_file(const char* path, json_error_t* error = 0); + inline Value load_file(const std::string& path, json_error_t* error = 0); // load a string as a JSON value - inline Value load_string(const char* string, json_error_t* error = 0); + inline Value loads(const char* string, json_error_t* error = 0); + inline Value loads(const std::string& string, json_error_t* error = 0); } // namespace json @@ -296,8 +310,8 @@ inline std::ostream& operator<<(std::ostream& os, const json::Value& value); inline std::istream& operator>>(std::istream& is, json::Value& value); // include implementation code -#define IN_JANSSON_HPP 1 -#include "jansson-impl.hpp" +#define IN_JANSSON_HPP +#include "jansson.ipp" #undef IN_JANSSON_HPP #endif // defined(JANSSON_HPP)