From 3c49cf1a960403d29bd11c61963d1ed7032a3d93 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 14 Mar 2012 21:39:55 +0000 Subject: Port to C++0x (minor tweaks) Use variadic templates in Storers to allow passing extra arguments to script object constructors --- project2/Jamfile.jam | 3 +- project2/common/memoryCache.cpp | 2 +- project2/common/scriptStorage.h | 69 +++++++++++++++++++++++----------------- project2/sql/rdbmsDataSource.cpp | 2 +- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 65a0e49..fd4de5d 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -18,7 +18,8 @@ alias p2parts : : : : project : requirements - debug:"-W -Wall -Werror -Wwrite-strings" + release:"-std=c++0x" + debug:"-W -Wall -Werror -Wwrite-strings -std=c++0x" debug:"-Wl,-z,defs --warn-once" ; diff --git a/project2/common/memoryCache.cpp b/project2/common/memoryCache.cpp index ea7fb84..a24abb3 100644 --- a/project2/common/memoryCache.cpp +++ b/project2/common/memoryCache.cpp @@ -132,7 +132,7 @@ class MemoryCache : public Cache { Key key; key.push_back(n); key.push_back(f); - applyKeys(boost::bind(&Key::push_back, &key, _2), ps); + applyKeys([&key](const std::string &, const VariableType & v) { key.push_back(v); }, ps); return key; } diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h index 14ebe6e..c58711b 100644 --- a/project2/common/scriptStorage.h +++ b/project2/common/scriptStorage.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include SimpleMessageException(StoreFailed); @@ -22,17 +24,19 @@ SimpleMessageException(StoreFailed); std::set > class Storer; +template +class StorerBase; typedef boost::intrusive_ptr StorerPtr; class Storer : public virtual IntrusivePtrBase { public: - template - static StorerPtr into(SINGLE(X) * obj); - template - static StorerPtr into(STORAGEOF(X) * map); - template - static StorerPtr into(ANONSTORAGEOF(X) * set); - template - static StorerPtr into(ANONORDEREDSTORAGEOF(X) * list); + template + static boost::intrusive_ptr > into(SINGLE(X) * obj, const C & ... c); + template + static boost::intrusive_ptr > into(STORAGEOF(X) * map, const C & ... c); + template + static boost::intrusive_ptr > into(ANONSTORAGEOF(X) * set, const C & ... c); + template + static boost::intrusive_ptr > into(ANONORDEREDSTORAGEOF(X) * list, const C & ... c); virtual boost::intrusive_ptr create(ScriptNodePtr) const = 0; virtual bool save(boost::intrusive_ptr, ScriptNodePtr) = 0; @@ -41,8 +45,13 @@ class Storer : public virtual IntrusivePtrBase { template class StorerBase : public Storer { public: + typedef boost::function2, L *, ScriptNodePtr> Creator; + StorerBase(const Creator & c) : + creator(c) + { + } boost::intrusive_ptr create(ScriptNodePtr p) const { - return LoaderBase::getLoader(p->get_name())->createFrom(p); + return creator(LoaderBase::getLoader(p->get_name()).get(), p); } bool save(boost::intrusive_ptr o, ScriptNodePtr name) { boost::intrusive_ptr O = boost::dynamic_pointer_cast(o); @@ -54,6 +63,8 @@ class StorerBase : public Storer { return O; } virtual bool insert(boost::intrusive_ptr) = 0; + private: + Creator creator; }; template @@ -66,7 +77,7 @@ template class StorerImpl : public StorerBase { public: typedef SINGLE(X) Obj; - StorerImpl(SINGLE(X) * o) : obj(o) + StorerImpl(SINGLE(X) * o, const typename StorerBase::Creator & c) : StorerBase(c), obj(o) { } bool insert(boost::intrusive_ptr O) @@ -80,7 +91,7 @@ template class StorerImpl : public StorerBase { public: typedef STORAGEOF(X) Map; - StorerImpl(STORAGEOF(X) * m) : map(m) + StorerImpl(STORAGEOF(X) * m, const typename StorerBase::Creator & c) : StorerBase(c), map(m) { } bool insert(boost::intrusive_ptr O) @@ -93,7 +104,7 @@ template class StorerImpl : public StorerBase { public: typedef ANONSTORAGEOF(X) Map; - StorerImpl(ANONSTORAGEOF(X) * m) : map(m) + StorerImpl(ANONSTORAGEOF(X) * m, const typename StorerBase::Creator & c) : StorerBase(c), map(m) { } bool insert(boost::intrusive_ptr O) @@ -107,7 +118,7 @@ template class StorerImpl : public StorerBase { public: typedef ANONORDEREDSTORAGEOF(X) Map; - StorerImpl(ANONORDEREDSTORAGEOF(X) * m) : map(m) + StorerImpl(ANONORDEREDSTORAGEOF(X) * m, const typename StorerBase::Creator & c) : StorerBase(c), map(m) { } bool insert(boost::intrusive_ptr O) @@ -118,28 +129,28 @@ class StorerImpl : public StorerBase { Map * map; }; -template -StorerPtr -Storer::into(SINGLE(X) * obj) { - return new StorerImpl(obj); +template +boost::intrusive_ptr > +Storer::into(SINGLE(X) * obj, const C & ... c) { + return new StorerImpl(obj, boost::bind(&L::createFrom, _1, _2, c...)); } -template -StorerPtr -Storer::into(STORAGEOF(X) * map) { - return new StorerImpl(map); +template +boost::intrusive_ptr > +Storer::into(STORAGEOF(X) * map, const C & ... c) { + return new StorerImpl(map, boost::bind(&L::createFrom, _1, _2, c...)); } -template -StorerPtr -Storer::into(ANONSTORAGEOF(X) * set) { - return new StorerImpl(set); +template +boost::intrusive_ptr > +Storer::into(ANONSTORAGEOF(X) * set, const C & ... c) { + return new StorerImpl(set, boost::bind(&L::createFrom, _1, _2, c...)); } -template -StorerPtr -Storer::into(ANONORDEREDSTORAGEOF(X) * list) { - return new StorerImpl(list); +template +boost::intrusive_ptr > +Storer::into(ANONORDEREDSTORAGEOF(X) * list, const C & ... c) { + return new StorerImpl(list, boost::bind(&L::createFrom, _1, _2, c...)); } #endif diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 305f1d7..6f3cedb 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -45,7 +45,7 @@ RdbmsDataSource::RdbmsDataSource(ScriptNodePtr p) : preferLocal(p->value("preferlocal", true)) { BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("readonly")) { - roDSNs.insert(ReadonlyDSNs::value_type(node->value("host"), node)); + roDSNs.insert(ReadonlyDSNs::value_type(node->value("host").as(), node)); } } -- cgit v1.2.3