diff options
author | Jose <jose@zeroc.com> | 2016-01-11 22:44:55 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2016-01-11 22:44:55 +0100 |
commit | d159c9f1574a2e768c947ad697a1e1e2205d194c (patch) | |
tree | 86e784ac7347c1dfa92304be2a9355a7a535dbcc /cpp/include/Ice | |
parent | Add ICE_RESET_EXCEPTION macro to simplify C++ builds (diff) | |
download | ice-d159c9f1574a2e768c947ad697a1e1e2205d194c.tar.bz2 ice-d159c9f1574a2e768c947ad697a1e1e2205d194c.tar.xz ice-d159c9f1574a2e768c947ad697a1e1e2205d194c.zip |
C++11 Value::ice_clone improvements
Diffstat (limited to 'cpp/include/Ice')
-rw-r--r-- | cpp/include/Ice/InterfaceByValue.h | 2 | ||||
-rw-r--r-- | cpp/include/Ice/SlicedData.h | 2 | ||||
-rw-r--r-- | cpp/include/Ice/Value.h | 36 |
3 files changed, 34 insertions, 6 deletions
diff --git a/cpp/include/Ice/InterfaceByValue.h b/cpp/include/Ice/InterfaceByValue.h index 3f042bae2c1..c2be72d3eb9 100644 --- a/cpp/include/Ice/InterfaceByValue.h +++ b/cpp/include/Ice/InterfaceByValue.h @@ -19,7 +19,7 @@ namespace Ice { template<typename T> -class InterfaceByValue : public Value +class InterfaceByValue : public Ice::ValueHelper<Ice::InterfaceByValue<T>, Ice::Value> { public: diff --git a/cpp/include/Ice/SlicedData.h b/cpp/include/Ice/SlicedData.h index 2956e7431f2..f104ceb15f4 100644 --- a/cpp/include/Ice/SlicedData.h +++ b/cpp/include/Ice/SlicedData.h @@ -79,7 +79,7 @@ public: // class ICE_API UnknownSlicedObject #ifdef ICE_CPP11_MAPPING - : public Value + : public ValueHelper<UnknownSlicedObject, Value> #else : virtual public Object, private IceInternal::GCObject #endif diff --git a/cpp/include/Ice/Value.h b/cpp/include/Ice/Value.h index 8aba347abbd..9e3d0449bd1 100644 --- a/cpp/include/Ice/Value.h +++ b/cpp/include/Ice/Value.h @@ -40,16 +40,44 @@ public: virtual const std::string& ice_id() const; static const std::string& ice_staticId(); - virtual ValuePtr ice_clone() const; + std::shared_ptr<Value> ice_clone() const; protected: - + + virtual std::shared_ptr<Value> cloneImpl() const = 0; + virtual void __writeImpl(IceInternal::BasicStream*) const {} virtual void __readImpl(IceInternal::BasicStream*) {} }; -ICE_API void ice_writeObject(const OutputStreamPtr&, const ValuePtr&); -ICE_API void ice_readObject(const InputStreamPtr&, ValuePtr&); +template<typename T, typename Base> class ValueHelper : public Base +{ +public: + + using Base::Base; + + ValueHelper() = default; + + std::shared_ptr<T> ice_clone() const + { + return std::static_pointer_cast<T>(cloneImpl()); + } + + virtual const std::string& ice_id() const override + { + return T::ice_staticId(); + } + +protected: + + virtual std::shared_ptr<Value> cloneImpl() const + { + return std::make_shared<T>(static_cast<const T&>(*this)); + } +}; + +ICE_API void ice_writeObject(const OutputStreamPtr&, const std::shared_ptr<Value>&); +ICE_API void ice_readObject(const InputStreamPtr&, std::shared_ptr<Value>&); } #endif // C++11 mapping end |