From 629c8346d2279169f30a188f64f3b1e8d0da6a47 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 23 May 2013 17:50:12 -0400 Subject: [PATCH] postPut in new array API Call when appropriate (putFrom(), copyIn(), and replace()). Not called by swap(), take(), reuse(), or shareData(). Users of the second set of methods are expected to call one of the methods in the first set, or call postPut() directly. Document when postPut is (not) called. --- pvDataApp/factory/StandardPVField.cpp | 4 ++-- pvDataApp/property/pvEnumerated.cpp | 2 +- pvDataApp/pv/pvData.h | 18 +++++++++++++++++- testApp/pv/testPVScalarArray.cpp | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pvDataApp/factory/StandardPVField.cpp b/pvDataApp/factory/StandardPVField.cpp index 7e3f743..f74f60a 100644 --- a/pvDataApp/factory/StandardPVField.cpp +++ b/pvDataApp/factory/StandardPVField.cpp @@ -61,7 +61,7 @@ PVStructurePtr StandardPVField::enumerated(StringArray const &choices) "choices",pvString); PVStringArray::svector cdata(choices.size()); std::copy(choices.begin(), choices.end(), cdata.begin()); - static_cast(*pvScalarArray).swap(cdata); + static_cast(*pvScalarArray).replace(cdata); return pvStructure; } @@ -74,7 +74,7 @@ PVStructurePtr StandardPVField::enumerated( "value.choices",pvString); PVStringArray::svector cdata(choices.size()); std::copy(choices.begin(), choices.end(), cdata.begin()); - static_cast(*pvScalarArray).swap(cdata); + static_cast(*pvScalarArray).replace(cdata); return pvStructure; } diff --git a/pvDataApp/property/pvEnumerated.cpp b/pvDataApp/property/pvEnumerated.cpp index c108434..9ad557f 100644 --- a/pvDataApp/property/pvEnumerated.cpp +++ b/pvDataApp/property/pvEnumerated.cpp @@ -106,7 +106,7 @@ bool PVEnumerated:: setChoices(const StringArray & choices) if(pvChoices->isImmutable()) return false; PVStringArray::svector data(choices.size()); std::copy(choices.begin(), choices.end(), data.begin()); - pvChoices->swap(data); + pvChoices->replace(data); return true; } diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index e644f28..78bffe9 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -706,6 +706,8 @@ public: * type of the provided data. * If the types do match then a new refernce to the provided * data is kept. + * + * Calls postPut() */ template inline void putFrom(const shared_vector::type>& inp) @@ -719,6 +721,8 @@ public: * Assign the given value after conversion. * * A copy and element-wise conversion is are always performed. + * + * Calls postPut() */ template inline void copyIn(const typename ScalarTypeTraits::type* inp, size_t len) @@ -1128,15 +1132,19 @@ public: virtual const svector& viewUnsafe() const = 0; //! Exchange our contents for the provided. - //! Fails for Immutable arrays + //! Fails for Immutable arrays. + //! Callers must ensure that postPut() is called + //! after the last swap() operation. virtual void swap(svector& other) = 0; //! Discard current contents and replaced with the provided. //! Fails for Immutable arrays + //! calls postPut() virtual void replace(const svector& next) { svector temp(next); this->swap(temp); + this->postPut(); } // Derived operations @@ -1149,6 +1157,7 @@ public: } //! Remove and return the current array data + //! Does @b not call postPut() inline svector take() { svector result; @@ -1157,6 +1166,7 @@ public: } //! take() with an implied make_unique() + //! Does @b not call postPut() inline svector reuse() { svector result; @@ -1189,6 +1199,7 @@ public: * @param from The new values to put into the array. * @param fromOffset The offset in from. * @return The number of elements put into the array. + * calls postPut() */ std::size_t put(std::size_t offset, std::size_t length, const_pointer from, std::size_t fromOffset) USAGE_DEPRECATED @@ -1204,6 +1215,7 @@ public: std::copy(from, from + length, temp.begin() + offset); this->swap(temp); + this->postPut(); return length; } @@ -1216,6 +1228,7 @@ public: * @param value The data to share. * @param capacity The capacity of the array. * @param length The length of the array. + * Does @b not call postPut() */ void shareData( shared_vector const & value, @@ -1299,6 +1312,7 @@ public: this->swap(result); } + this->postPut(); } virtual void copyIn(ScalarType id, const void* ptr, size_t len) @@ -1308,6 +1322,7 @@ public: data.resize(len); castUnsafeV(len, typeCode, (void*)data.data(), id, ptr); this->swap(data); + this->postPut(); } virtual void assign(PVScalarArray& pv) @@ -1318,6 +1333,7 @@ public: pv.getAs(typeCode, temp); svector next(static_shared_vector_cast(temp)); this->swap(next); + this->postPut(); } protected: diff --git a/testApp/pv/testPVScalarArray.cpp b/testApp/pv/testPVScalarArray.cpp index f4c24cb..3d6b23c 100644 --- a/testApp/pv/testPVScalarArray.cpp +++ b/testApp/pv/testPVScalarArray.cpp @@ -108,6 +108,7 @@ static void testBasic() testOk1(!arr1->viewUnsafe().unique()); arr2->swap(data); + arr2->postPut(); testOk1(arr2->getLength()==0); testOk1(data.size()==arr1->getLength());