summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-03-14 21:39:55 +0000
committerrandomdan <randomdan@localhost>2012-03-14 21:39:55 +0000
commit3c49cf1a960403d29bd11c61963d1ed7032a3d93 (patch)
treed7f9297f871a3c40f41324b52726a8f47f8e55d5
parentFix error persisting when loadComplete fails (diff)
downloadproject2-3c49cf1a960403d29bd11c61963d1ed7032a3d93.tar.bz2
project2-3c49cf1a960403d29bd11c61963d1ed7032a3d93.tar.xz
project2-3c49cf1a960403d29bd11c61963d1ed7032a3d93.zip
Port to C++0x (minor tweaks)
Use variadic templates in Storers to allow passing extra arguments to script object constructors
-rw-r--r--project2/Jamfile.jam3
-rw-r--r--project2/common/memoryCache.cpp2
-rw-r--r--project2/common/scriptStorage.h69
-rw-r--r--project2/sql/rdbmsDataSource.cpp2
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
- <variant>debug:<cflags>"-W -Wall -Werror -Wwrite-strings"
+ <variant>release:<cflags>"-std=c++0x"
+ <variant>debug:<cflags>"-W -Wall -Werror -Wwrite-strings -std=c++0x"
<variant>debug:<linkflags>"-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 <list>
#include <map>
#include <boost/intrusive_ptr.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
SimpleMessageException(StoreFailed);
@@ -22,17 +24,19 @@ SimpleMessageException(StoreFailed);
std::set<boost::intrusive_ptr<X> >
class Storer;
+template <class X, class L>
+class StorerBase;
typedef boost::intrusive_ptr<Storer> StorerPtr;
class Storer : public virtual IntrusivePtrBase {
public:
- template <class L, class X>
- static StorerPtr into(SINGLE(X) * obj);
- template <class L, class X>
- static StorerPtr into(STORAGEOF(X) * map);
- template <class L, class X>
- static StorerPtr into(ANONSTORAGEOF(X) * set);
- template <class L, class X>
- static StorerPtr into(ANONORDEREDSTORAGEOF(X) * list);
+ template <class L, class X, typename... C>
+ static boost::intrusive_ptr<StorerBase<X, L> > into(SINGLE(X) * obj, const C & ... c);
+ template <class L, class X, typename... C>
+ static boost::intrusive_ptr<StorerBase<X, L> > into(STORAGEOF(X) * map, const C & ... c);
+ template <class L, class X, typename... C>
+ static boost::intrusive_ptr<StorerBase<X, L> > into(ANONSTORAGEOF(X) * set, const C & ... c);
+ template <class L, class X, typename... C>
+ static boost::intrusive_ptr<StorerBase<X, L> > into(ANONORDEREDSTORAGEOF(X) * list, const C & ... c);
virtual boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr) const = 0;
virtual bool save(boost::intrusive_ptr<IntrusivePtrBase>, ScriptNodePtr) = 0;
@@ -41,8 +45,13 @@ class Storer : public virtual IntrusivePtrBase {
template <class X, class L>
class StorerBase : public Storer {
public:
+ typedef boost::function2<boost::intrusive_ptr<IntrusivePtrBase>, L *, ScriptNodePtr> Creator;
+ StorerBase(const Creator & c) :
+ creator(c)
+ {
+ }
boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const {
- return LoaderBase::getLoader<L, NotSupported>(p->get_name())->createFrom(p);
+ return creator(LoaderBase::getLoader<L, NotSupported>(p->get_name()).get(), p);
}
bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr name) {
boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(o);
@@ -54,6 +63,8 @@ class StorerBase : public Storer {
return O;
}
virtual bool insert(boost::intrusive_ptr<X>) = 0;
+ private:
+ Creator creator;
};
template <class X, class M, class L>
@@ -66,7 +77,7 @@ template <class X, class L>
class StorerImpl<X, SINGLE(X), L> : public StorerBase<X, L> {
public:
typedef SINGLE(X) Obj;
- StorerImpl(SINGLE(X) * o) : obj(o)
+ StorerImpl(SINGLE(X) * o, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), obj(o)
{
}
bool insert(boost::intrusive_ptr<X> O)
@@ -80,7 +91,7 @@ template <class X, class L>
class StorerImpl<X, STORAGEOF(X), L> : public StorerBase<X, L> {
public:
typedef STORAGEOF(X) Map;
- StorerImpl(STORAGEOF(X) * m) : map(m)
+ StorerImpl(STORAGEOF(X) * m, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), map(m)
{
}
bool insert(boost::intrusive_ptr<X> O)
@@ -93,7 +104,7 @@ template <class X, class L>
class StorerImpl<X, ANONSTORAGEOF(X), L> : public StorerBase<X, L> {
public:
typedef ANONSTORAGEOF(X) Map;
- StorerImpl(ANONSTORAGEOF(X) * m) : map(m)
+ StorerImpl(ANONSTORAGEOF(X) * m, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), map(m)
{
}
bool insert(boost::intrusive_ptr<X> O)
@@ -107,7 +118,7 @@ template <class X, class L>
class StorerImpl<X, ANONORDEREDSTORAGEOF(X), L> : public StorerBase<X, L> {
public:
typedef ANONORDEREDSTORAGEOF(X) Map;
- StorerImpl(ANONORDEREDSTORAGEOF(X) * m) : map(m)
+ StorerImpl(ANONORDEREDSTORAGEOF(X) * m, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), map(m)
{
}
bool insert(boost::intrusive_ptr<X> O)
@@ -118,28 +129,28 @@ class StorerImpl<X, ANONORDEREDSTORAGEOF(X), L> : public StorerBase<X, L> {
Map * map;
};
-template <class L, class X>
-StorerPtr
-Storer::into(SINGLE(X) * obj) {
- return new StorerImpl<X, SINGLE(X), L>(obj);
+template <class L, class X, typename... C>
+boost::intrusive_ptr<StorerBase<X, L> >
+Storer::into(SINGLE(X) * obj, const C & ... c) {
+ return new StorerImpl<X, SINGLE(X), L>(obj, boost::bind(&L::createFrom, _1, _2, c...));
}
-template <class L, class X>
-StorerPtr
-Storer::into(STORAGEOF(X) * map) {
- return new StorerImpl<X, STORAGEOF(X), L>(map);
+template <class L, class X, typename... C>
+boost::intrusive_ptr<StorerBase<X, L> >
+Storer::into(STORAGEOF(X) * map, const C & ... c) {
+ return new StorerImpl<X, STORAGEOF(X), L>(map, boost::bind(&L::createFrom, _1, _2, c...));
}
-template <class L, class X>
-StorerPtr
-Storer::into(ANONSTORAGEOF(X) * set) {
- return new StorerImpl<X, ANONSTORAGEOF(X), L>(set);
+template <class L, class X, typename... C>
+boost::intrusive_ptr<StorerBase<X, L> >
+Storer::into(ANONSTORAGEOF(X) * set, const C & ... c) {
+ return new StorerImpl<X, ANONSTORAGEOF(X), L>(set, boost::bind(&L::createFrom, _1, _2, c...));
}
-template <class L, class X>
-StorerPtr
-Storer::into(ANONORDEREDSTORAGEOF(X) * list) {
- return new StorerImpl<X, ANONORDEREDSTORAGEOF(X), L>(list);
+template <class L, class X, typename... C>
+boost::intrusive_ptr<StorerBase<X, L> >
+Storer::into(ANONORDEREDSTORAGEOF(X) * list, const C & ... c) {
+ return new StorerImpl<X, ANONORDEREDSTORAGEOF(X), L>(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<std::string>(), node));
}
}