From 36adc76235fb0a38e7042bc751f988b71627e2a0 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 06:13:02 +0000 Subject: Changes to get successful C++11 based build. Code cleanup, dependency upgrades, and const + inline optimizations in components, samples, and app hosting server. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1420007 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/filedb/filedb.hpp | 57 ++++++++++++------------------ 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'sca-cpp/trunk/components/filedb/filedb.hpp') diff --git a/sca-cpp/trunk/components/filedb/filedb.hpp b/sca-cpp/trunk/components/filedb/filedb.hpp index 9c3017d0d8..2855cebfc6 100644 --- a/sca-cpp/trunk/components/filedb/filedb.hpp +++ b/sca-cpp/trunk/components/filedb/filedb.hpp @@ -32,8 +32,8 @@ #include "monad.hpp" #include "fstream.hpp" #include "element.hpp" -#include "xml.hpp" #include "../../modules/scheme/eval.hpp" +#include "../../modules/xml/xml.hpp" #include "../../modules/json/json.hpp" namespace tuscany { @@ -68,30 +68,22 @@ public: debug("filedb::filedb::copy"); } - const FileDB& operator=(const FileDB& c) { - debug("filedb::filedb::operator="); - if(this == &c) - return *this; - owner = false; - name = c.name; - format = c.format; - return *this; - } + FileDB& operator=(const FileDB& c) = delete; ~FileDB() { } private: - bool owner; - string name; - string format; + const bool owner; + const string name; + const string format; friend const failable write(const value& v, ostream& os, const string& format); friend const failable read(istream& is, const string& format); - friend const failable post(const value& key, const value& val, FileDB& db); - friend const failable put(const value& key, const value& val, FileDB& db); - friend const failable get(const value& key, FileDB& db); - friend const failable del(const value& key, FileDB& db); + friend const failable post(const value& key, const value& val, const FileDB& db); + friend const failable put(const value& key, const value& val, const FileDB& db); + friend const failable get(const value& key, const FileDB& db); + friend const failable del(const value& key, const FileDB& db); }; /** @@ -100,7 +92,7 @@ private: const string filename(const list& path, const string& root) { if (isNil(path)) return root; - const string name = root + "/" + (isString(car(path))? (string)car(path) : scheme::writeValue(car(path))); + const string name = root + "/" + (isString(car(path))? (string)car(path) : write(content(scheme::writeValue(car(path))))); return filename(cdr(path), name); } @@ -116,7 +108,7 @@ const string filename(const value& key, const string& root) { const failable mkdirs(const list& path, const string& root) { if (isNil(cdr(path))) return true; - const string dir = root + "/" + (isString(car(path))? (string)car(path) : scheme::writeValue(car(path))); + const string dir = root + "/" + (isString(car(path))? (string)car(path) : write(content(scheme::writeValue(car(path))))); mkdir(c_str(dir), S_IRWXU); return mkdirs(cdr(path), dir); } @@ -126,20 +118,19 @@ const failable mkdirs(const list& path, const string& root) { */ const failable write(const value& v, ostream& os, const string& format) { if (format == "scheme") { - const string vs(scheme::writeValue(v)); + const string vs(write(content(scheme::writeValue(v)))); os << vs; return true; } if (format == "xml") { - failable > s = writeXML(valuesToElements(v)); + failable > s = xml::writeElements(valuesToElements(v)); if (!hasContent(s)) return mkfailure(s); write(content(s), os); return true; } if (format == "json") { - js::JSContext jscx; - failable > s = json::writeJSON(valuesToElements(v), jscx); + failable > s = json::writeValue(v); if (!hasContent(s)) return mkfailure(s); write(content(s), os); @@ -153,27 +144,25 @@ const failable write(const value& v, ostream& os, const string& format) { */ const failable read(istream& is, const string& format) { if (format == "scheme") { - return scheme::readValue(is); + return scheme::readValue(streamList(is)); } if (format == "xml") { - const value v = elementsToValues(readXML(streamList(is))); - return v; - } - if (format == "json") { - js::JSContext jscx; - const failable > fv = json::readJSON(streamList(is), jscx); + const failable > fv = xml::readElements(streamList(is)); if (!hasContent(fv)) return mkfailure(fv); const value v = elementsToValues(content(fv)); return v; } + if (format == "json") { + return json::readValue(streamList(is)); + } return mkfailure(string("Unsupported database format: ") + format); } /** * Post a new item to the database. */ -const failable post(const value& key, const value& val, FileDB& db) { +const failable post(const value& key, const value& val, const FileDB& db) { debug(key, "filedb::post::key"); debug(val, "filedb::post::value"); debug(db.name, "filedb::post::dbname"); @@ -197,7 +186,7 @@ const failable post(const value& key, const value& val, FileDB& db) { /** * Update an item in the database. If the item doesn't exist it is added. */ -const failable put(const value& key, const value& val, FileDB& db) { +const failable put(const value& key, const value& val, const FileDB& db) { debug(key, "filedb::put::key"); debug(val, "filedb::put::value"); debug(db.name, "filedb::put::dbname"); @@ -221,7 +210,7 @@ const failable put(const value& key, const value& val, FileDB& db) { /** * Get an item from the database. */ -const failable get(const value& key, FileDB& db) { +const failable get(const value& key, const FileDB& db) { debug(key, "filedb::get::key"); debug(db.name, "filedb::get::dbname"); @@ -242,7 +231,7 @@ const failable get(const value& key, FileDB& db) { /** * Delete an item from the database */ -const failable del(const value& key, FileDB& db) { +const failable del(const value& key, const FileDB& db) { debug(key, "filedb::delete::key"); debug(db.name, "filedb::delete::dbname"); -- cgit v1.2.3