From 0b89f08d0908099cfce15fc393b4e724ef38851b Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 10 Jun 2013 12:07:27 -0400 Subject: [PATCH] explicit copy and assignment for shared_vector Add explicit copy constructor and assignment operator for shared_vector. --- pvDataApp/misc/sharedVector.h | 23 ++++++++++++++++++++++- testApp/misc/testSharedVector.cpp | 5 ++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pvDataApp/misc/sharedVector.h b/pvDataApp/misc/sharedVector.h index 611b3c9..3aee3db 100644 --- a/pvDataApp/misc/sharedVector.h +++ b/pvDataApp/misc/sharedVector.h @@ -113,6 +113,11 @@ namespace detail { :m_data(d,b), m_offset(o), m_count(c), m_total(c) {_null_input();} + shared_vector_base(const shared_vector_base& O) + :m_data(O.m_data), m_offset(O.m_offset) + ,m_count(O.m_count), m_total(O.m_total) + {} + template shared_vector_base(const shared_vector_base& o) : m_data(vector_implicit_cast::cast(o.m_data)) @@ -131,6 +136,19 @@ namespace detail { return *this; } + //! @brief Copy an existing vector of a related type + template + shared_vector_base& operator=(const shared_vector_base& o) + { + if(&o!=this) { + m_data=vector_implicit_cast::cast(o.m_data); + m_offset=o.m_offset; + m_count=o.m_count; + m_total=o.m_total; + } + return *this; + } + //! @brief Swap the contents of this vector with another void swap(shared_vector_base& o) { if(&o!=this) { @@ -284,7 +302,10 @@ public: shared_vector(A d, B b, size_t o, size_t c) :base_t(d,b,o,c) {} - //! @brief Copy an existing vector of same or related type + //! @brief Copy an existing vector of same type + shared_vector(const shared_vector& o) :base_t(o) {} + + //! @brief Copy an existing vector of a related type template shared_vector(const shared_vector& o) :base_t(o) {} diff --git a/testApp/misc/testSharedVector.cpp b/testApp/misc/testSharedVector.cpp index 6610b41..638c562 100644 --- a/testApp/misc/testSharedVector.cpp +++ b/testApp/misc/testSharedVector.cpp @@ -212,6 +212,9 @@ static void testConst() testOk1(wcr==rocr); + rodata = writable; + testOk1(rodata.data()==writable.data()); + // Data is R/W, but container can't be re-targeted const epics::pvData::shared_vector roref(writable); @@ -381,7 +384,7 @@ static void testNonPOD() MAIN(testSharedVector) { - testPlan(115); + testPlan(116); testDiag("Tests for shared_vector"); testDiag("sizeof(shared_vector)=%lu",