summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-10-18 13:19:27 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-10-18 13:19:27 +0100
commit3eb53444a0eb7029787fd52dad34f0fc78057cc2 (patch)
tree6b7eef0b6724f1c488a17afd80cd23cd0a0b5792
parentRemove need to create ChildRefs on heap (diff)
downloadslicer-3eb53444a0eb7029787fd52dad34f0fc78057cc2.tar.bz2
slicer-3eb53444a0eb7029787fd52dad34f0fc78057cc2.tar.xz
slicer-3eb53444a0eb7029787fd52dad34f0fc78057cc2.zip
Simplify hook pointer to unique_ptr
-rw-r--r--slicer/db/sqlCommon.cpp10
-rw-r--r--slicer/db/sqlCommon.h10
-rw-r--r--slicer/db/sqlInsertSerializer.cpp12
-rw-r--r--slicer/db/sqlInsertSerializer.h8
-rw-r--r--slicer/db/sqlSelectDeserializer.cpp2
-rw-r--r--slicer/db/sqlUpdateSerializer.cpp10
-rw-r--r--slicer/slicer/modelParts.h8
-rw-r--r--slicer/slicer/modelPartsTypes.cpp2
-rw-r--r--slicer/slicer/modelPartsTypes.h2
-rw-r--r--slicer/test/compilation.cpp2
-rw-r--r--slicer/tool/parser.cpp30
-rw-r--r--slicer/xml/serializer.cpp2
-rw-r--r--slicer/xml/serializer.h2
13 files changed, 53 insertions, 47 deletions
diff --git a/slicer/db/sqlCommon.cpp b/slicer/db/sqlCommon.cpp
index 5618b29..193285e 100644
--- a/slicer/db/sqlCommon.cpp
+++ b/slicer/db/sqlCommon.cpp
@@ -9,28 +9,28 @@ namespace Slicer {
const std::string md_ignore = "db:ignore";
const std::string md_global_ignore = "ignore";
- bool isPKey(HookCommonPtr h)
+ bool isPKey(const HookCommon * h)
{
return metaDataFlagSet(h->GetMetadata(), md_pkey) && isBind(h);
}
- bool isAuto(HookCommonPtr h)
+ bool isAuto(const HookCommon * h)
{
return metaDataFlagSet(h->GetMetadata(), md_auto) && isBind(h);
}
- bool isNotAuto(HookCommonPtr h)
+ bool isNotAuto(const HookCommon * h)
{
return metaDataFlagNotSet(h->GetMetadata(), md_auto) && isBind(h);
}
- bool isBind(HookCommonPtr h)
+ bool isBind(const HookCommon * h)
{
return metaDataFlagNotSet(h->GetMetadata(), md_global_ignore) &&
metaDataFlagNotSet(h->GetMetadata(), md_ignore);
}
- bool isValue(HookCommonPtr h)
+ bool isValue(const HookCommon * h)
{
return metaDataFlagNotSet(h->GetMetadata(), md_auto) &&
metaDataFlagNotSet(h->GetMetadata(), md_pkey) && isBind(h);
diff --git a/slicer/db/sqlCommon.h b/slicer/db/sqlCommon.h
index 2471d4c..954800a 100644
--- a/slicer/db/sqlCommon.h
+++ b/slicer/db/sqlCommon.h
@@ -5,11 +5,11 @@
#include <modelParts.h>
namespace Slicer {
- bool isPKey(HookCommonPtr);
- bool isAuto(HookCommonPtr);
- bool isNotAuto(HookCommonPtr);
- bool isBind(HookCommonPtr);
- bool isValue(HookCommonPtr);
+ bool isPKey(const HookCommon *);
+ bool isAuto(const HookCommon *);
+ bool isNotAuto(const HookCommon *);
+ bool isBind(const HookCommon *);
+ bool isValue(const HookCommon *);
}
#endif
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp
index 0033c7c..0addf86 100644
--- a/slicer/db/sqlInsertSerializer.cpp
+++ b/slicer/db/sqlInsertSerializer.cpp
@@ -41,7 +41,7 @@ namespace Slicer {
SqlInsertSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const
{
ModifyPtr ins = createInsert(mp->GetContainedModelPart());
- mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, HookCommonPtr) {
+ mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, const HookCommon *) {
bindObjectAndExecute(cmp, ins.get());
});
}
@@ -85,7 +85,7 @@ namespace Slicer {
SqlFetchIdInsertSerializer::bindObjectAndExecute(Slicer::ModelPartPtr cmp, DB::ModifyCommand * ins) const
{
SqlAutoIdInsertSerializer::bindObjectAndExecute(cmp, ins);
- cmp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, HookCommonPtr h) {
+ cmp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, const HookCommon * h) {
if (isAuto(h)) {
cmp->SetValue(IdSave(connection));
}
@@ -93,7 +93,7 @@ namespace Slicer {
}
void
- SqlInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, Slicer::ModelPartPtr cmp, HookCommonPtr h) const
+ SqlInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, Slicer::ModelPartPtr cmp, const HookCommon * h) const
{
if (isBind(h)) {
if (!cmp->GetValue(SqlBinder(*ins, paramNo))) {
@@ -104,7 +104,7 @@ namespace Slicer {
}
void
- SqlAutoIdInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, Slicer::ModelPartPtr cmp, HookCommonPtr h) const
+ SqlAutoIdInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, Slicer::ModelPartPtr cmp, const HookCommon * h) const
{
if (isNotAuto(h)) {
SqlInsertSerializer::bindObjectAndExecuteField(paramNo, ins, cmp, h);
@@ -127,7 +127,7 @@ namespace Slicer {
}
void
- SqlInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, HookCommonPtr h) const
+ SqlInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const
{
if (isBind(h)) {
if (fieldNo++) {
@@ -138,7 +138,7 @@ namespace Slicer {
}
void
- SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, HookCommonPtr h) const
+ SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const
{
if (isNotAuto(h)) {
if (fieldNo++) {
diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h
index c4aa29f..a693301 100644
--- a/slicer/db/sqlInsertSerializer.h
+++ b/slicer/db/sqlInsertSerializer.h
@@ -19,9 +19,9 @@ namespace Slicer {
void SerializeObject(Slicer::ModelPartPtr) const;
void SerializeSequence(Slicer::ModelPartPtr) const;
ModifyPtr createInsert(Slicer::ModelPartPtr) const;
- virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, HookCommonPtr h) const;
+ virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const;
virtual void bindObjectAndExecute(Slicer::ModelPartPtr, DB::ModifyCommand *) const;
- virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, Slicer::ModelPartPtr, HookCommonPtr) const;
+ virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, Slicer::ModelPartPtr, const HookCommon *) const;
DB::Connection * const connection;
const std::string tableName;
@@ -33,8 +33,8 @@ namespace Slicer {
SqlAutoIdInsertSerializer(const P & ... p) : SqlInsertSerializer(p...) { }
protected:
- virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, HookCommonPtr h) const;
- virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, Slicer::ModelPartPtr, HookCommonPtr) const;
+ virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const;
+ virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, Slicer::ModelPartPtr, const HookCommon *) const;
};
class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer {
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp
index 366c4f7..ec64545 100644
--- a/slicer/db/sqlSelectDeserializer.cpp
+++ b/slicer/db/sqlSelectDeserializer.cpp
@@ -96,7 +96,7 @@ namespace Slicer {
for (auto col = 0u; col < columnCount; col += 1) {
const DB::Column & c = cmd[col];
if (!c.isNull()) {
- auto fmpr = rmp->GetAnonChildRef([&c](Slicer::HookCommonPtr h) {
+ auto fmpr = rmp->GetAnonChildRef([&c](const Slicer::HookCommon * h) {
return boost::iequals(c.name, h->name);
});
if (fmpr) {
diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp
index ca9a50c..613a87a 100644
--- a/slicer/db/sqlUpdateSerializer.cpp
+++ b/slicer/db/sqlUpdateSerializer.cpp
@@ -40,7 +40,7 @@ namespace Slicer {
SqlUpdateSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const
{
ModifyPtr ins = createUpdate(mp->GetContainedModelPart());
- mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, HookCommonPtr) {
+ mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, const HookCommon *) {
bindObjectAndExecute(cmp, ins.get());
});
}
@@ -49,7 +49,7 @@ namespace Slicer {
SqlUpdateSerializer::bindObjectAndExecute(Slicer::ModelPartPtr cmp, DB::ModifyCommand * upd)
{
int paramNo = 0;
- cmp->OnEachChild([&upd, &paramNo](const std::string &, ModelPartPtr cmp, HookCommonPtr h) {
+ cmp->OnEachChild([&upd, &paramNo](const std::string &, ModelPartPtr cmp, const HookCommon * h) {
if (isValue(h)) {
if (!cmp->GetValue(SqlBinder(*upd, paramNo))) {
upd->bindNull(paramNo);
@@ -57,7 +57,7 @@ namespace Slicer {
paramNo++;
}
});
- cmp->OnEachChild([&upd, &paramNo](const std::string &, ModelPartPtr cmp, HookCommonPtr h) {
+ cmp->OnEachChild([&upd, &paramNo](const std::string &, ModelPartPtr cmp, const HookCommon * h) {
if (isPKey(h)) {
cmp->GetValue(SqlBinder(*upd, paramNo++));
}
@@ -73,7 +73,7 @@ namespace Slicer {
AdHoc::Buffer update;
update.appendbf("UPDATE %s SET ", tableName);
int fieldNo = 0;
- mp->OnEachChild([&update, &fieldNo]( const std::string & name, ModelPartPtr, HookCommonPtr h) {
+ mp->OnEachChild([&update, &fieldNo]( const std::string & name, ModelPartPtr, const HookCommon * h) {
if (isValue(h)) {
if (fieldNo++) {
update.append(", ");
@@ -83,7 +83,7 @@ namespace Slicer {
});
update.append(" WHERE ", AdHoc::Buffer::Use);
fieldNo = 0;
- mp->OnEachChild([&update, &fieldNo]( const std::string & name, ModelPartPtr, HookCommonPtr h) {
+ mp->OnEachChild([&update, &fieldNo]( const std::string & name, ModelPartPtr, const HookCommon * h) {
if (isPKey(h)) {
if (fieldNo++) {
update.append(" AND ");
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index e659a54..982a010 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -79,13 +79,13 @@ namespace Slicer {
typedef IceUtil::Handle<ModelPart> ModelPartPtr;
typedef IceUtil::Handle<ModelPartForRootBase> ModelPartForRootPtr;
- typedef IceUtil::Handle<HookCommon> HookCommonPtr;
+ typedef std::unique_ptr<HookCommon> HookCommonPtr;
typedef IceUtil::Optional<std::string> TypeId;
- typedef boost::function<void(const std::string &, ModelPartPtr, HookCommonPtr)> ChildHandler;
+ typedef boost::function<void(const std::string &, ModelPartPtr, const HookCommon *)> ChildHandler;
typedef boost::function<ModelPartPtr(void *)> ClassRef;
- typedef boost::function<bool(HookCommonPtr)> HookFilter;
+ typedef boost::function<bool(const HookCommon *)> HookFilter;
typedef std::map<std::string, ClassRef> ClassRefMap;
DLL_PUBLIC ClassRefMap * classRefMap();
typedef boost::bimap<std::string, std::string> ClassNameMap;
@@ -122,7 +122,7 @@ namespace Slicer {
const Metadata & mdr;
};
- class DLL_PUBLIC HookCommon : virtual public IceUtil::Shared {
+ class DLL_PUBLIC HookCommon {
public:
HookCommon(const std::string &);
diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp
index 5bf7f50..c6f72d1 100644
--- a/slicer/slicer/modelPartsTypes.cpp
+++ b/slicer/slicer/modelPartsTypes.cpp
@@ -52,7 +52,7 @@ namespace Slicer {
void ModelPartForRootBase::OnEachChild(const ChildHandler & ch)
{
- ch(GetRootName(), mp, NULL);
+ ch(GetRootName(), mp, nullptr);
}
ModelPartType
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index a1c4409..1af328f 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -141,7 +141,7 @@ namespace Slicer {
virtual ModelPartPtr Get(T * t) const = 0;
virtual const Metadata & GetMetadata() const override;
};
- typedef IceUtil::Handle<HookBase> HookPtr;
+ typedef std::unique_ptr<HookBase> HookPtr;
template <typename MT, typename MP>
class DLL_PRIVATE Hook : public HookBase {
diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp
index 3a0f54e..ba87f06 100644
--- a/slicer/test/compilation.cpp
+++ b/slicer/test/compilation.cpp
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_class )
}
void
-hookHandler(std::vector<std::string> * names, const std::string & name, Slicer::ModelPartPtr mpp, Slicer::HookCommonPtr h)
+hookHandler(std::vector<std::string> * names, const std::string & name, Slicer::ModelPartPtr mpp, const Slicer::HookCommon * h)
{
names->push_back(name);
BOOST_REQUIRE(mpp);
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 49834c0..5424612 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -249,7 +249,9 @@ namespace Slicer {
fprintbf(cpp, "template<> DLL_PUBLIC\n");
fprintbf(cpp, "const ModelPartForComplex< %s >::Hooks ",
it->scoped());
- fprintbf(cpp, "ModelPartForComplex< %s >::hooks {\n",
+ fprintbf(cpp, "ModelPartForComplex< %s >::hooks ([](){\n",
+ it->scoped());
+ fprintbf(cpp, "\t\tModelPartForComplex< %s >::Hooks r;\n",
it->scoped());
for (const auto & dm : dataMembers) {
auto c = Slice::ContainedPtr::dynamicCast(dm->container());
@@ -258,7 +260,7 @@ namespace Slicer {
t = Slice::ClassDefPtr::dynamicCast(dm->container())->declaration();
}
auto name = metaDataValue("slicer:name:", dm->getMetaData());
- fprintbf(cpp, "\t\tnew ");
+ fprintbf(cpp, "\t\tr.push_back(std::make_unique<");
auto type = dm->type();
createNewModelPartPtrFor(it);
if (hasMetadata(dm->getMetaData())) {
@@ -270,16 +272,17 @@ namespace Slicer {
fprintbf(cpp, " %s, ",
Slice::typeToString(type, dm->optional()));
createNewModelPartPtrFor(type, dm, getAllMetadata(dm));
- fprintbf(cpp, " >(&%s, \"%s\"",
+ fprintbf(cpp, " > >(&%s, \"%s\"",
dm->scoped(),
name ? *name : dm->name());
if (hasMetadata(dm->getMetaData())) {
- fprintbf(cpp, ", ");
+ fprintbf(cpp, ", Metadata ");
copyMetadata(dm->getMetaData());
}
- fprintbf(cpp, " ),\n");
+ fprintbf(cpp, " ));\n");
}
- fprintbf(cpp, "\t};\n\n");
+ fprintbf(cpp, "\t\treturn r;\n");
+ fprintbf(cpp, "\t}());\n\n");
}
void
@@ -373,28 +376,31 @@ namespace Slicer {
fprintbf(cpp, "template<> DLL_PUBLIC\n");
fprintbf(cpp, "const ModelPartForComplex< %s::value_type >::Hooks ",
d->scoped());
- fprintbf(cpp, "ModelPartForComplex< %s::value_type >::hooks {\n",
+ fprintbf(cpp, "ModelPartForComplex< %s::value_type >::hooks ([](){\n",
+ d->scoped());
+ fprintbf(cpp, "\t\tModelPartForComplex< %s::value_type >::Hooks r;\n",
d->scoped());
auto kname = metaDataValue("slicer:key:", d->getMetaData());
auto vname = metaDataValue("slicer:value:", d->getMetaData());
fprintbf(cpp, "\t\t");
auto ktype = d->keyType();
- fprintbf(cpp, "new ModelPartForComplex< %s::value_type >::Hook< const %s, ",
+ fprintbf(cpp, "r.push_back(std::make_unique< ModelPartForComplex< %s::value_type >::Hook< const %s, ",
d->scoped(),
Slice::typeToString(ktype));
createNewModelPartPtrFor(ktype);
- fprintbf(cpp, " >(&%s::value_type::first, \"%s\"),\n\t\t",
+ fprintbf(cpp, " > >(&%s::value_type::first, \"%s\"));\n\t\t",
d->scoped(),
kname ? *kname : "key");
auto vtype = d->valueType();
- fprintbf(cpp, "new ModelPartForComplex< %s::value_type >::Hook< %s, ",
+ fprintbf(cpp, "r.push_back(std::make_unique< ModelPartForComplex< %s::value_type >::Hook< %s, ",
d->scoped(),
Slice::typeToString(vtype));
createNewModelPartPtrFor(vtype);
- fprintbf(cpp, " >(&%s::value_type::second, \"%s\"),\n",
+ fprintbf(cpp, " > >(&%s::value_type::second, \"%s\"));\n",
d->scoped(),
vname ? *vname : "value");
- fprintbf(cpp, "\t};\n");
+ fprintbf(cpp, "\t\treturn r;\n");
+ fprintbf(cpp, "\t}());\n");
fprintbf(cpp, "\n");
auto name = metaDataValue("slicer:root:", d->getMetaData());
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index 978c489..f0ef251 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -297,7 +297,7 @@ namespace Slicer {
}
void
- XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartPtr mp, HookCommonPtr hp, const ElementCreator & ec)
+ XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartPtr mp, const HookCommon * hp, const ElementCreator & ec)
{
if (name.empty()) {
return;
diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h
index d41a994..2a50522 100644
--- a/slicer/xml/serializer.h
+++ b/slicer/xml/serializer.h
@@ -13,7 +13,7 @@ namespace Slicer {
class DLL_PUBLIC XmlSerializer : public Serializer {
protected:
typedef boost::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)> ElementCreator;
- static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp, HookCommonPtr hp, const ElementCreator &);
+ static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp, const HookCommon * hp, const ElementCreator &);
static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartPtr mp);
protected: