diff options
author | Petri Lehtinen <petri@digip.org> | 2010-02-04 21:07:02 +0200 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2010-02-04 21:08:42 +0200 |
commit | adb1b586274b920a78ca9dc4d728a9086510c2dd (patch) | |
tree | 497c3381c81074e2e31ca4d3fee21b3a2169dd38 /src | |
parent | b8059a18801ae067d13f1e5d9e872e4cf11bc58f (diff) | |
download | jansson-adb1b586274b920a78ca9dc4d728a9086510c2dd.zip jansson-adb1b586274b920a78ca9dc4d728a9086510c2dd.tar.gz jansson-adb1b586274b920a78ca9dc4d728a9086510c2dd.tar.bz2 |
C++: Add Value::dump_file(), load_file() and loads() that take an std::string
Diffstat (limited to 'src')
-rw-r--r-- | src/jansson.hpp | 3 | ||||
-rw-r--r-- | src/jansson.ipp | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/jansson.hpp b/src/jansson.hpp index de55b75..bf723bd 100644 --- a/src/jansson.hpp +++ b/src/jansson.hpp @@ -128,6 +128,7 @@ namespace json { // write the value to a file 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* dumps(int flags = 0) const; @@ -289,9 +290,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 loads(const char* string, json_error_t* error = 0); + inline Value loads(const std::string& string, json_error_t* error = 0); } // namespace json diff --git a/src/jansson.ipp b/src/jansson.ipp index fcb4a0c..5938f0f 100644 --- a/src/jansson.ipp +++ b/src/jansson.ipp @@ -274,6 +274,11 @@ namespace json { return json_dump_file(_Base::as_json(), path, flags); } + template <typename _Base> + int ValueBase<_Base>::dump_file(const std::string& path, int flags) const { + return dump_file(path.c_str(), flags); + } + // write the value to a string (caller must deallocate with free()!) template <typename _Base> char* ValueBase<_Base>::dumps(int flags) const { @@ -439,11 +444,19 @@ namespace json { return Value::take_ownership(json_load_file(path, error)); } + Value load_file(const std::string& path, json_error_t* error) { + return load_file(path.c_str(), error); + } + // load a string as a JSON value Value loads(const char* string, json_error_t* error) { return Value::take_ownership(json_loads(string, error)); } + Value loads(const std::string& string, json_error_t* error) { + return loads(string.c_str(), error); + } + } // namespace json // stream JSON value out |