summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-01-02 19:30:39 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-01-02 19:30:39 +0000
commit4b97b062f55f4e176ab844e0a339e7db77e05db3 (patch)
treea5f308f47293d09f020567d32a4ffa79d73e6ace
parentAdd missing override attribute (diff)
downloadslicer-4b97b062f55f4e176ab844e0a339e7db77e05db3.tar.bz2
slicer-4b97b062f55f4e176ab844e0a339e7db77e05db3.tar.xz
slicer-4b97b062f55f4e176ab844e0a339e7db77e05db3.zip
Fix support for model part types of optional converted
-rw-r--r--slicer/slicer/modelPartsTypes.h4
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h4
-rw-r--r--slicer/test/optionals.ice2
-rw-r--r--slicer/tool/parser.cpp37
-rw-r--r--slicer/tool/parser.h1
5 files changed, 31 insertions, 17 deletions
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index f159191..a27ad66 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -56,7 +56,7 @@ namespace Slicer {
static const ModelPartType type;
};
- template<typename T, typename M, T M::* MV>
+ template<typename T, typename MT, typename M, MT M::* MV>
class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -66,7 +66,7 @@ namespace Slicer {
virtual void SetValue(ValueSourcePtr s) override;
virtual void GetValue(ValueTargetPtr s) override;
};
-
+
class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart {
public:
virtual void OnEachChild(const ChildHandler & ch) override;
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index b19f937..fe38863 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -150,8 +150,8 @@ namespace Slicer {
}
// ModelPartForConverted
- template<typename T, typename M, T M::* MV>
- ModelPartForConverted<T, M, MV>::ModelPartForConverted(T & h) :
+ template<typename T, typename MT, typename M, MT M::* MV>
+ ModelPartForConverted<T, MT, M, MV>::ModelPartForConverted(T & h) :
ModelPartModel<T>(h)
{
}
diff --git a/slicer/test/optionals.ice b/slicer/test/optionals.ice
index 63476ad..720e7c3 100644
--- a/slicer/test/optionals.ice
+++ b/slicer/test/optionals.ice
@@ -12,6 +12,8 @@ module TestModule {
optional(2) ClassType optClass;
optional(3) Classes optSeq;
optional(4) ClassMap optDict;
+ [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ]
+ optional(5) string optConverted;
};
};
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index c2c98d0..818cd7e 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -51,11 +51,8 @@ namespace Slicer {
}
if (!conversions.empty()) {
fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n");
- fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >::SetValue(ValueSourcePtr vsp)\n",
- Slice::typeToString(type),
- c->scoped(),
- dm->scoped());
- fprintbf(cpp, "{\n");
+ createModelPartForConverted(type, c->scoped(), dm);
+ fprintbf(cpp, "::SetValue(ValueSourcePtr vsp)\n{\n");
for (const auto & conversion : conversions) {
fprintbf(cpp, "\tif (auto vspt = dynamic_cast<TValueSource< %s > *>(vsp.get())) {\n",
@@ -82,11 +79,8 @@ namespace Slicer {
fprintbf(cpp, "}\n\n");
fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n");
- fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >::GetValue(ValueTargetPtr vtp)\n",
- Slice::typeToString(type),
- c->scoped(),
- dm->scoped());
- fprintbf(cpp, "{\n");
+ createModelPartForConverted(type, c->scoped(), dm);
+ fprintbf(cpp, "::GetValue(ValueTargetPtr vtp)\n{\n");
for (const auto & conversion : conversions) {
fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n",
@@ -463,14 +457,31 @@ namespace Slicer {
}
void
+ Slicer::createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const
+ {
+ fprintbf(cpp, "ModelPartForConverted< %s, ",
+ Slice::typeToString(type));
+ if (dm->optional()) {
+ fprintbf(cpp, "IceUtil::Optional< %s >",
+ Slice::typeToString(type));
+ }
+ else {
+ fprintbf(cpp, "%s",
+ Slice::typeToString(type));
+ }
+ fprintbf(cpp, ", %s, &%s >",
+ container,
+ dm->scoped());
+ }
+
+ void
Slicer::createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm, const Slice::StringList & md) const
{
auto conversions = getConversions(md);
if (dm && !conversions.empty()) {
- fprintbf(cpp, "ModelPartForConverted< %s, %s, &%s >",
- Slice::typeToString(type),
+ createModelPartForConverted(type,
boost::algorithm::trim_right_copy_if(dm->container()->thisScope(), ispunct),
- dm->scoped());
+ dm);
}
else if (auto cmp = metaDataValue("slicer:custommodelpart:", md)) {
fprintbf(cpp, "%s",
diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h
index 9495607..02c7dfe 100644
--- a/slicer/tool/parser.h
+++ b/slicer/tool/parser.h
@@ -55,6 +55,7 @@ namespace Slicer {
virtual void visitModuleEnd(const Slice::ModulePtr & m) override;
private:
+ void createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const;
void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const;
std::string getBasicModelPart(const Slice::TypePtr & type) const;
void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const;