diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-22 20:54:47 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-23 11:24:17 +0100 |
commit | e8cab7ab5899507191e1586edd537ed269436fd3 (patch) | |
tree | 86566b95894bf2a7d5cd173e17d91c963ebdc199 | |
parent | IceUtil::Shared should be virtually inheritted (diff) | |
download | slicer-e8cab7ab5899507191e1586edd537ed269436fd3.tar.bz2 slicer-e8cab7ab5899507191e1586edd537ed269436fd3.tar.xz slicer-e8cab7ab5899507191e1586edd537ed269436fd3.zip |
Don't copy (take by const reference) when serializing (although we do cast off the const later, but we promise not to change the object)
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 4 | ||||
-rw-r--r-- | slicer/slicer/slicer.h | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 2121d5d..988d91e 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -14,9 +14,13 @@ template class ModelPartForRoot< IceUtil::Optional<Type> >; \ template<> ModelPartPtr ModelPart::CreateFor<Type>() { return new ModelPartType(nullptr); } \ template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType(&s); } \ + template<> ModelPartPtr ModelPart::CreateFor(const Type & s) { return CreateFor(const_cast<Type &>(s)); } \ template<> ModelPartPtr ModelPart::CreateFor(IceUtil::Optional<Type> & s) { return new ModelPartForOptional<ModelPartType>(&s); } \ + template<> ModelPartPtr ModelPart::CreateFor(const IceUtil::Optional<Type> & s) { return CreateFor(const_cast<IceUtil::Optional<Type> &>(s)); } \ template<> ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) { return new ModelPartForRoot<Type>(&s); } \ template<> ModelPartForRootPtr ModelPart::CreateRootFor(IceUtil::Optional<Type> & s) { return new ModelPartForRoot<IceUtil::Optional<Type> >(&s); } \ + template<> ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) { return CreateRootFor(const_cast<Type &>(s)); } \ + template<> ModelPartForRootPtr ModelPart::CreateRootFor(const IceUtil::Optional<Type> & s) { return CreateRootFor(const_cast<IceUtil::Optional<Type> &>(s)); } \ #define MODELPARTFOR(Type, ModelPartType) \ CUSTOMMODELPARTFOR(Type, ModelPartType<Type>, ModelPartType<Type>) diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index ba233bb..4513ced 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -24,14 +24,14 @@ namespace Slicer { template <typename Object> void - SerializeAnyWith(Object object, SerializerPtr serializer) + SerializeAnyWith(const Object & object, SerializerPtr serializer) { - serializer->Serialize(ModelPart::CreateRootFor<Object>(object)); + serializer->Serialize(ModelPart::CreateRootFor<const Object>(object)); } template <typename Serializer, typename Object, typename ... SerializerParams> void - SerializeAny(Object object, SerializerParams && ... sp) + SerializeAny(const Object & object, SerializerParams && ... sp) { SerializeAnyWith(object, new Serializer(sp ...)); } |