From 992ac730684d580bb14d2a04dbe92e9af1b323b8 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 8 May 2013 15:16:58 -0400 Subject: [PATCH] use new API make copying explicit and replace some use of PVValueArray::put and get --- pvDataApp/factory/Convert.cpp | 5 +++-- pvDataApp/factory/StandardPVField.cpp | 16 ++++++---------- pvDataApp/factory/printer.cpp | 4 ++-- pvDataApp/property/pvEnumerated.cpp | 20 ++++++-------------- pvDataApp/property/pvEnumerated.h | 4 ++-- testApp/property/testProperty.cpp | 4 ++-- 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp index c33af5e..35763ac 100644 --- a/pvDataApp/factory/Convert.cpp +++ b/pvDataApp/factory/Convert.cpp @@ -114,11 +114,12 @@ size_t Convert::fromStringArray(PVScalarArrayPtr const &pv, StringArray const & from, size_t fromOffset) { + assert(offset==0); size_t alen = pv->getLength(); if(fromOffset>alen) return 0; alen -= fromOffset; if(length>alen) length=alen; - pv->putFrom(&from[fromOffset], length, offset); + pv->copyIn(&from[fromOffset], length); return length; } @@ -130,7 +131,7 @@ size_t Convert::toStringArray(PVScalarArrayPtr const & pv, if(offset>alen) return 0; alen -= offset; if(length>alen) length=alen; - pv->getAs(&to[toOffset], length, offset); + pv->copyOut(&to[toOffset], length); return length; } diff --git a/pvDataApp/factory/StandardPVField.cpp b/pvDataApp/factory/StandardPVField.cpp index c497c8e..7e3f743 100644 --- a/pvDataApp/factory/StandardPVField.cpp +++ b/pvDataApp/factory/StandardPVField.cpp @@ -59,11 +59,9 @@ PVStructurePtr StandardPVField::enumerated(StringArray const &choices) PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField( "choices",pvString); - if(pvScalarArray.get()==NULL) { - throw std::logic_error(String("StandardPVField::enumerated")); - } - PVStringArray * pvChoices = static_cast(pvScalarArray.get()); - pvChoices->put(0,choices.size(),get(choices),0); + PVStringArray::svector cdata(choices.size()); + std::copy(choices.begin(), choices.end(), cdata.begin()); + static_cast(*pvScalarArray).swap(cdata); return pvStructure; } @@ -74,11 +72,9 @@ PVStructurePtr StandardPVField::enumerated( PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField( "value.choices",pvString); - if(pvScalarArray.get()==NULL) { - throw std::logic_error(String("StandardPVField::enumerated")); - } - PVStringArray * pvChoices = static_cast(pvScalarArray.get()); - pvChoices->put(0,choices.size(),get(choices),0); + PVStringArray::svector cdata(choices.size()); + std::copy(choices.begin(), choices.end(), cdata.begin()); + static_cast(*pvScalarArray).swap(cdata); return pvStructure; } diff --git a/pvDataApp/factory/printer.cpp b/pvDataApp/factory/printer.cpp index baf6c8a..20dde9d 100644 --- a/pvDataApp/factory/printer.cpp +++ b/pvDataApp/factory/printer.cpp @@ -166,8 +166,8 @@ void PrinterPlain::encodeScalar(const PVScalar& pv) void PrinterPlain::encodeArray(const PVScalarArray& pv) { indentN(S(), ilvl); - StringArray temp(pv.getLength()); // TODO: no copy - pv.getAs(&temp[0], temp.size()); + shared_vector temp; + pv.getAs(temp); S() << pv.getScalarArray()->getID() << " " << pv.getFieldName() << " ["; diff --git a/pvDataApp/property/pvEnumerated.cpp b/pvDataApp/property/pvEnumerated.cpp index ee00601..c108434 100644 --- a/pvDataApp/property/pvEnumerated.cpp +++ b/pvDataApp/property/pvEnumerated.cpp @@ -78,9 +78,8 @@ String PVEnumerated::getChoice() throw std::logic_error(notAttached); } int index = pvIndex->get(); - StringArrayData data; - pvChoices->get(0,pvChoices->getLength(),data); - return data.data[index]; + const PVStringArray::svector& data(pvChoices->viewUnsafe()); + return data[index]; } bool PVEnumerated::choicesMutable() @@ -91,15 +90,6 @@ bool PVEnumerated::choicesMutable() return pvChoices->isImmutable(); } -StringArrayPtr const & PVEnumerated:: getChoices() -{ - if(pvIndex.get()==NULL ) { - throw std::logic_error(notAttached); - } - StringArrayData data; - return pvChoices->getSharedVector(); -} - int32 PVEnumerated::getNumberChoices() { if(pvIndex.get()==NULL ) { @@ -108,13 +98,15 @@ int32 PVEnumerated::getNumberChoices() return pvChoices->getLength(); } -bool PVEnumerated:: setChoices(StringArray & choices) +bool PVEnumerated:: setChoices(const StringArray & choices) { if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } if(pvChoices->isImmutable()) return false; - pvChoices->put(0,choices.size(),get(choices),0); + PVStringArray::svector data(choices.size()); + std::copy(choices.begin(), choices.end(), data.begin()); + pvChoices->swap(data); return true; } diff --git a/pvDataApp/property/pvEnumerated.h b/pvDataApp/property/pvEnumerated.h index 4e2fbe0..7887908 100644 --- a/pvDataApp/property/pvEnumerated.h +++ b/pvDataApp/property/pvEnumerated.h @@ -30,9 +30,9 @@ public: int32 getIndex(); String getChoice(); bool choicesMutable(); - StringArrayPtr const & getChoices(); + inline PVStringArray::const_svector getChoices(){return pvChoices->view();} int32 getNumberChoices(); - bool setChoices(StringArray & choices); + bool setChoices(const StringArray & choices); private: static String notFound; static String notAttached; diff --git a/testApp/property/testProperty.cpp b/testApp/property/testProperty.cpp index 923276c..4d1dc59 100644 --- a/testApp/property/testProperty.cpp +++ b/testApp/property/testProperty.cpp @@ -229,11 +229,11 @@ static void testEnumerated(FILE * fd,FILE */*auxfd*/) assert(result); int32 index = pvEnumerated.getIndex(); String choice = pvEnumerated.getChoice(); - StringArrayPtr const & choices = pvEnumerated.getChoices(); + PVStringArray::const_svector choices = pvEnumerated.getChoices(); int32 numChoices = pvEnumerated.getNumberChoices(); if(debug) { fprintf(fd,"index %d choice %s choices",index,choice.c_str()); - for(int i=0; i