From 4294710d9ef2c234bd821f41e7d5498cac56005a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 3 Jun 2013 13:43:01 -0400 Subject: [PATCH] make viewUnsafe protected No longer part of the public API of PVValueArray --- pvDataApp/property/pvEnumerated.cpp | 2 +- pvDataApp/pv/pvData.h | 3 ++- testApp/pv/testPVScalarArray.cpp | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pvDataApp/property/pvEnumerated.cpp b/pvDataApp/property/pvEnumerated.cpp index 9ad557f..ce76355 100644 --- a/pvDataApp/property/pvEnumerated.cpp +++ b/pvDataApp/property/pvEnumerated.cpp @@ -78,7 +78,7 @@ String PVEnumerated::getChoice() throw std::logic_error(notAttached); } int index = pvIndex->get(); - const PVStringArray::svector& data(pvChoices->viewUnsafe()); + const PVStringArray::const_svector& data(pvChoices->view()); return data[index]; } diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index 93b8c65..05d77d3 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -1125,10 +1125,11 @@ public: virtual ~PVValueArray() {} // Primative array manipulations - +protected: //! unchecked reference to writable data //! Please consider the view() method instead of viewUnsafe(). virtual const svector& viewUnsafe() const = 0; +public: /** Exchange our contents for the provided. * diff --git a/testApp/pv/testPVScalarArray.cpp b/testApp/pv/testPVScalarArray.cpp index 3d6b23c..67cbd6e 100644 --- a/testApp/pv/testPVScalarArray.cpp +++ b/testApp/pv/testPVScalarArray.cpp @@ -50,13 +50,21 @@ static void testFactory() } } +template +bool hasUniqueVector(const typename PVT::shared_pointer& pv) +{ + typename PVT::svector data; + pv->swap(data); + bool ret = data.unique(); + pv->swap(data); + return ret; +} + template struct basicTestData { static inline void fill(typename PVT::svector& data) { data.resize(100); - for(typename PVT::value_type i=0; - (size_t)iviewUnsafe().unique()); + testOk1(hasUniqueVector(arr1)); arr2->assign(*arr1); testOk1(*arr1==*arr2); - testOk1(!arr1->viewUnsafe().unique()); + testOk1(!hasUniqueVector(arr1)); arr2->swap(data); arr2->postPut(); @@ -123,7 +131,7 @@ static void testBasic() arr1->PVScalarArray::putFrom(idata); - testOk1(castUnsafe(arr1->viewUnsafe()[1])==42); + testOk1(castUnsafe(arr1->view()[1])==42); } static void testShare()