diff --git a/pvDataApp/misc/sharedVector.h b/pvDataApp/misc/sharedVector.h index d1442f4..d932b19 100644 --- a/pvDataApp/misc/sharedVector.h +++ b/pvDataApp/misc/sharedVector.h @@ -200,6 +200,9 @@ namespace detail { size_t dataCount() const { return m_count; } size_t dataTotal() const { return m_total; } }; + + + struct _shared_vector_cast_tag {}; } /** @brief A holder for a contigious piece of memory. @@ -297,6 +300,16 @@ public: template shared_vector(const shared_vector& o) :base_t(o) {} + //! @internal + //! Internal for static_shared_vector_cast + template + shared_vector(const shared_vector &src, + typename meta::is_void::type) + :base_t(std::tr1::static_pointer_cast(src.dataPtr()), + src.dataOffset()/sizeof(E), + src.dataCount()/sizeof(E)) + {} + size_t max_size() const{return ((size_t)-1)/sizeof(E);} size_t capacity() const { return this->m_total; } @@ -511,6 +524,17 @@ public: shared_vector(const shared_vector& o) :base_t(o), m_vtype(o.m_vtype) {} + //! @internal + //! Internal for static_shared_vector_cast + template + shared_vector(const shared_vector &src, + typename meta::is_not_void::type) + :base_t(std::tr1::static_pointer_cast(src.dataPtr()), + src.dataOffset()*sizeof(FROM), + src.dataCount()*sizeof(FROM)) + ,m_vtype((ScalarType)ScalarTypeID::value) + {} + shared_vector& operator=(const shared_vector& o) { if(&o!=this) { @@ -541,38 +565,6 @@ public: }; namespace detail { - template - struct shared_vector_caster {}; - - // Cast from non-void to 'void' or 'const void' - template - struct shared_vector_caster, meta::is_not_void >::type - > - { - static inline shared_vector op(const shared_vector& src) { - return shared_vector( - std::tr1::static_pointer_cast(src.dataPtr()), - src.dataOffset()*sizeof(FROM), - src.dataCount()*sizeof(FROM)) - .set_original_type((ScalarType)ScalarTypeID::value); - } - }; - - // Cast from 'void' or 'const void' to non-void - template - struct shared_vector_caster, meta::is_void >::type - > - { - static inline shared_vector op(const shared_vector& src) { - return shared_vector( - std::tr1::static_pointer_cast(src.dataPtr()), - src.dataOffset()/sizeof(TO), - src.dataCount()/sizeof(TO)); - } - }; - // Default to type conversion using castUnsafe (C++ type casting) on each element template @@ -601,7 +593,7 @@ namespace detail { > { static FORCE_INLINE shared_vector op(const shared_vector& src) { - return shared_vector_caster::op(src); + return shared_vector(src, detail::_shared_vector_cast_tag()); } }; @@ -617,7 +609,7 @@ namespace detail { dtype = (ScalarType)ScalarTypeID::value; if(stype==dtype) { // no convert needed - return shared_vector_caster::op(src); + return shared_vector(src, detail::_shared_vector_cast_tag()); } else { // alloc and convert shared_vector ret(src.size()/ScalarTypeFunc::elementSize(stype)); @@ -641,11 +633,12 @@ namespace detail { * are integer multiples of the size of the destination type. */ template -static inline +static FORCE_INLINE shared_vector -static_shared_vector_cast(const shared_vector& src) +static_shared_vector_cast(const shared_vector& src, + typename meta::same_const::type = 0) { - return detail::shared_vector_caster::op(src); + return shared_vector(src, detail::_shared_vector_cast_tag()); } /** @brief Allow converting of shared_vector between types @@ -658,7 +651,7 @@ static_shared_vector_cast(const shared_vector& src) * and throws std::runtime_error if this is not valid. */ template -static inline +static FORCE_INLINE shared_vector shared_vector_convert(const shared_vector& src) { @@ -667,7 +660,7 @@ shared_vector_convert(const shared_vector& src) //! Allows casting from const TYPE -> TYPE. template -static inline +static FORCE_INLINE shared_vector const_shared_vector_cast(const shared_vector& src) {