summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelParts.h7
-rw-r--r--slicer/slicer/modelPartsTypes.h39
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h70
-rw-r--r--slicer/tool/parser.cpp14
4 files changed, 58 insertions, 72 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index c9a0995..d3e56db 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -167,6 +167,13 @@ namespace Slicer {
static const std::string & ToModelTypeName(const std::string &);
};
+ template<typename T>
+ class DLL_PUBLIC ModelPartModel {
+ protected:
+ ModelPartModel(T & m) : Model(m) { }
+ T & Model;
+ };
+
template<typename T> inline ModelPartPtr ModelPartFor(T & t) __attribute__ ((deprecated));
template<typename T> inline ModelPartPtr ModelPartFor(T & t) { return ModelPart::CreateFor(t); }
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index 8af3653..d5e687d 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -15,7 +15,7 @@ namespace Slicer {
};
template<typename T>
- class DLL_PUBLIC ModelPartForSimple : public ModelPartForSimpleBase {
+ class DLL_PUBLIC ModelPartForSimple : public ModelPartForSimpleBase, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -23,9 +23,6 @@ namespace Slicer {
virtual void SetValue(ValueSourcePtr s) override;
virtual void GetValue(ValueTargetPtr s) override;
-
- private:
- T & Member;
};
class DLL_PUBLIC ModelPartForConvertedBase : public ModelPart {
@@ -39,7 +36,7 @@ namespace Slicer {
};
template<typename T, typename M, T M::* MV>
- class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase {
+ class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -47,13 +44,10 @@ namespace Slicer {
virtual void SetValue(ValueSourcePtr s) override;
virtual void GetValue(ValueTargetPtr s) override;
-
- private:
- T & Member;
};
template<typename T>
- class DLL_PUBLIC ModelPartForOptional : public ModelPart {
+ class DLL_PUBLIC ModelPartForOptional : public ModelPart, protected ModelPartModel<IceUtil::Optional<typename T::element_type> > {
public:
ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h);
virtual void OnEachChild(const ChildHandler & ch) override;
@@ -72,8 +66,7 @@ namespace Slicer {
virtual const Metadata & GetMetadata() const override;
- private:
- IceUtil::Optional< typename T::element_type > & OptionalMember;
+ protected:
ModelPartPtr modelPart;
};
@@ -140,7 +133,7 @@ namespace Slicer {
};
template<typename T>
- class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex<typename T::element_type> {
+ class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex<typename T::element_type>, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -159,13 +152,10 @@ namespace Slicer {
virtual IceUtil::Optional<std::string> GetTypeIdProperty() const override;
static const std::string typeIdProperty;
-
- private:
- T & ModelObject;
};
template<typename T>
- class DLL_PUBLIC ModelPartForStruct : public ModelPartForComplex<T> {
+ class DLL_PUBLIC ModelPartForStruct : public ModelPartForComplex<T>, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -174,9 +164,6 @@ namespace Slicer {
T * GetModel() override;
virtual bool HasValue() const override;
-
- private:
- T & ModelObject;
};
class DLL_PUBLIC ModelPartForEnumBase : public ModelPart {
@@ -190,7 +177,7 @@ namespace Slicer {
};
template<typename T>
- class DLL_PUBLIC ModelPartForEnum : public ModelPartForEnumBase {
+ class DLL_PUBLIC ModelPartForEnum : public ModelPartForEnumBase, protected ModelPartModel<T> {
public:
typedef T element_type;
typedef boost::bimap<T, std::string> Enumerations;
@@ -207,9 +194,6 @@ namespace Slicer {
static const Enumerations enumerations;
DLL_PUBLIC static const std::string & lookup(T);
DLL_PUBLIC static T lookup(const std::string &);
-
- private:
- T & modelPart;
};
class DLL_PUBLIC ModelPartForSequenceBase : public ModelPart {
@@ -220,7 +204,7 @@ namespace Slicer {
};
template<typename T>
- class DLL_PUBLIC ModelPartForSequence : public ModelPartForSequenceBase {
+ class DLL_PUBLIC ModelPartForSequence : public ModelPartForSequenceBase, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -239,8 +223,6 @@ namespace Slicer {
private:
ModelPartPtr elementModelPart(typename T::value_type &) const;
-
- T & sequence;
};
template<typename T>
@@ -264,7 +246,7 @@ namespace Slicer {
};
template<typename T>
- class DLL_PUBLIC ModelPartForDictionary : public ModelPartForDictionaryBase {
+ class DLL_PUBLIC ModelPartForDictionary : public ModelPartForDictionaryBase, protected ModelPartModel<T> {
public:
typedef T element_type;
@@ -280,9 +262,6 @@ namespace Slicer {
static const Metadata metadata;
static const std::string pairName;
-
- private:
- T & dictionary;
};
}
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index 201e90f..e38d307 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -64,43 +64,43 @@ namespace Slicer {
// ModelPartForSimple
template<typename T>
ModelPartForSimple<T>::ModelPartForSimple(T & h) :
- Member(h)
+ ModelPartModel<T>(h)
{
}
template<typename T>
void ModelPartForSimple<T>::SetValue(ValueSourcePtr s)
{
- s->set(Member);
+ s->set(this->Model);
}
template<typename T>
void ModelPartForSimple<T>::GetValue(ValueTargetPtr s)
{
- s->get(Member);
+ s->get(this->Model);
}
// ModelPartForConverted
template<typename T, typename M, T M::* MV>
ModelPartForConverted<T, M, MV>::ModelPartForConverted(T & h) :
- Member(h)
+ ModelPartModel<T>(h)
{
}
// ModelPartForOptional
template<typename T>
ModelPartForOptional<T>::ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h) :
- OptionalMember(h)
+ ModelPartModel<IceUtil::Optional< typename T::element_type> >(h)
{
- if (OptionalMember) {
- modelPart = new T(*OptionalMember);
+ if (this->Model) {
+ modelPart = new T(*this->Model);
}
}
template<typename T>
void ModelPartForOptional<T>::OnEachChild(const ChildHandler & ch)
{
- if (OptionalMember) {
+ if (this->Model) {
modelPart->OnEachChild(ch);
}
}
@@ -108,7 +108,7 @@ namespace Slicer {
template<typename T>
void ModelPartForOptional<T>::Complete()
{
- if (OptionalMember) {
+ if (this->Model) {
modelPart->Complete();
}
}
@@ -116,9 +116,9 @@ namespace Slicer {
template<typename T>
void ModelPartForOptional<T>::Create()
{
- if (!OptionalMember) {
- OptionalMember = typename T::element_type();
- modelPart = new T(*OptionalMember);
+ if (!this->Model) {
+ this->Model = typename T::element_type();
+ modelPart = new T(*this->Model);
modelPart->Create();
}
}
@@ -126,7 +126,7 @@ namespace Slicer {
template<typename T>
ChildRefPtr ModelPartForOptional<T>::GetAnonChildRef(const HookFilter & flt)
{
- if (OptionalMember) {
+ if (this->Model) {
return modelPart->GetAnonChildRef(flt);
}
return NULL;
@@ -135,7 +135,7 @@ namespace Slicer {
template<typename T>
ChildRefPtr ModelPartForOptional<T>::GetChildRef(const std::string & name, const HookFilter & flt)
{
- if (OptionalMember) {
+ if (this->Model) {
return modelPart->GetChildRef(name, flt);
}
return NULL;
@@ -144,7 +144,7 @@ namespace Slicer {
template<typename T>
void ModelPartForOptional<T>::SetValue(ValueSourcePtr s)
{
- if (OptionalMember) {
+ if (this->Model) {
modelPart->SetValue(s);
}
}
@@ -152,9 +152,9 @@ namespace Slicer {
template<typename T>
void ModelPartForOptional<T>::GetValue(ValueTargetPtr s)
{
- if (!OptionalMember) {
- OptionalMember = typename T::element_type();
- modelPart = new T(*OptionalMember);
+ if (!this->Model) {
+ this->Model = typename T::element_type();
+ modelPart = new T(*this->Model);
}
modelPart->GetValue(s);
}
@@ -162,7 +162,7 @@ namespace Slicer {
template<typename T>
bool ModelPartForOptional<T>::HasValue() const
{
- return OptionalMember && modelPart->HasValue();
+ return this->Model && modelPart->HasValue();
}
template<typename T>
@@ -224,20 +224,20 @@ namespace Slicer {
// ModelPartForClass
template<typename T>
ModelPartForClass<T>::ModelPartForClass(T & h) :
- ModelObject(h)
+ ModelPartModel<T>(h)
{
}
template<typename T>
void ModelPartForClass<T>::Create()
{
- ModelObject = new typename T::element_type();
+ this->Model = new typename T::element_type();
}
template<typename T>
typename T::element_type * ModelPartForClass<T>::GetModel()
{
- return ModelObject.get();
+ return this->Model.get();
}
template<typename T>
@@ -247,13 +247,13 @@ namespace Slicer {
if (ref == classRefMap()->end()) {
throw UnknownType(name);
}
- return ref->second(&this->ModelObject);
+ return ref->second(&this->Model);
}
template<typename T>
bool ModelPartForClass<T>::HasValue() const
{
- return ModelObject;
+ return this->Model;
}
template<typename T>
@@ -265,14 +265,14 @@ namespace Slicer {
// ModelPartForStruct
template<typename T>
ModelPartForStruct<T>::ModelPartForStruct(T & o) :
- ModelObject(o)
+ ModelPartModel<T>(o)
{
}
template<typename T>
T * ModelPartForStruct<T>::GetModel()
{
- return &ModelObject;
+ return &this->Model;
}
template<typename T>
@@ -284,7 +284,7 @@ namespace Slicer {
// ModelPartForEnum
template<typename T>
ModelPartForEnum<T>::ModelPartForEnum(T & s) :
- modelPart(s)
+ ModelPartModel<T>(s)
{
}
@@ -297,14 +297,14 @@ namespace Slicer {
// ModelPartForSequence
template<typename T>
ModelPartForSequence<T>::ModelPartForSequence(T & s) :
- sequence(s)
+ ModelPartModel<T>(s)
{
}
template<typename T>
void ModelPartForSequence<T>::OnEachChild(const ChildHandler & ch)
{
- for(auto & element : sequence) {
+ for(auto & element : this->Model) {
ch(elementName, elementModelPart(element), NULL);
}
}
@@ -312,8 +312,8 @@ namespace Slicer {
template<typename T>
ChildRefPtr ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &)
{
- sequence.push_back(typename element_type::value_type());
- return new ImplicitChildRef(ModelPart::CreateFor(sequence.back()));
+ this->Model.push_back(typename element_type::value_type());
+ return new ImplicitChildRef(ModelPart::CreateFor(this->Model.back()));
}
template<typename T>
@@ -359,14 +359,14 @@ namespace Slicer {
// ModelPartForDictionary
template<typename T>
ModelPartForDictionary<T>::ModelPartForDictionary(T & d) :
- dictionary(d)
+ ModelPartModel<T>(d)
{
}
template<typename T>
void ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch)
{
- for (auto & pair : dictionary) {
+ for (auto & pair : this->Model) {
ch(pairName, new ModelPartForStruct<typename T::value_type>(pair), NULL);
}
}
@@ -374,7 +374,7 @@ namespace Slicer {
template<typename T>
ChildRefPtr ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &)
{
- return new ImplicitChildRef(new ModelPartForDictionaryElementInserter<T>(dictionary));
+ return new ImplicitChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model));
}
template<typename T>
@@ -383,7 +383,7 @@ namespace Slicer {
if (name != pairName) {
throw IncorrectElementName(name);
}
- return new ImplicitChildRef(new ModelPartForDictionaryElementInserter<T>(dictionary));
+ return new ImplicitChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model));
}
template<typename T>
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 56fe4cd..425e688 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -63,7 +63,7 @@ namespace Slicer {
fprintbf(cpp, "\t\t%s tmp;\n",
conversion.ExchangeType);
fprintbf(cpp, "\t\tvspt->set(tmp);\n");
- fprintbf(cpp, "\t\tMember = %s(tmp);\n",
+ fprintbf(cpp, "\t\tModel = %s(tmp);\n",
conversion.ConvertToModelFunc);
fprintbf(cpp, "\t\treturn;\n");
fprintbf(cpp, "\t}\n");
@@ -72,7 +72,7 @@ namespace Slicer {
if (!dm->hasMetaData("slicer:nodefaultconversion")) {
fprintbf(cpp, "\tif (auto vspt = dynamic_cast<TValueSource< %s > *>(vsp.get())) {\n",
Slice::typeToString(type));
- fprintbf(cpp, "\t\tvspt->set(Member);\n");
+ fprintbf(cpp, "\t\tvspt->set(Model);\n");
fprintbf(cpp, "\t\treturn;\n");
fprintbf(cpp, "\t}\n");
}
@@ -91,7 +91,7 @@ namespace Slicer {
for (const auto & conversion : conversions) {
fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n",
conversion.ExchangeType);
- fprintbf(cpp, "\t\tvtpt->get(%s(Member));\n",
+ fprintbf(cpp, "\t\tvtpt->get(%s(Model));\n",
conversion.ConvertToExchangeFunc);
fprintbf(cpp, "\t\treturn;\n");
fprintbf(cpp, "\t}\n");
@@ -100,7 +100,7 @@ namespace Slicer {
if (!dm->hasMetaData("slicer:nodefaultconversion")) {
fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n",
Slice::typeToString(type));
- fprintbf(cpp, "\t\tvtpt->get(Member);\n");
+ fprintbf(cpp, "\t\tvtpt->get(Model);\n");
fprintbf(cpp, "\t\treturn;\n");
fprintbf(cpp, "\t}\n");
}
@@ -222,7 +222,7 @@ namespace Slicer {
fprintbf(cpp, "template<> DLL_PUBLIC\nTypeId\nModelPartForClass< %s >::GetTypeId() const\n{\n",
typeToString(decl));
- fprintbf(cpp, "\tauto id = ModelObject->ice_id();\n");
+ fprintbf(cpp, "\tauto id = this->Model->ice_id();\n");
fprintbf(cpp, "\treturn (id == \"%s\") ? TypeId() : ModelPart::ToExchangeTypeName(id);\n}\n\n",
c->scoped());
@@ -352,11 +352,11 @@ namespace Slicer {
fprintbf(cpp, "template<> DLL_PUBLIC\nvoid ModelPartForEnum< %s >::SetValue(ValueSourcePtr s) {\n\
std::string val;\n\
s->set(val);\n\
- modelPart = lookup(val);\n\
+ this->Model = lookup(val);\n\
}\n\n",
e->scoped());
fprintbf(cpp, "template<> DLL_PUBLIC\nvoid ModelPartForEnum< %s >::GetValue(ValueTargetPtr s) {\n\
- s->get(lookup(modelPart));\n\
+ s->get(lookup(this->Model));\n\
}\n\n",
e->scoped());