use new API

make copying explicit and replace some
use of PVValueArray<T>::put and get
This commit is contained in:
Michael Davidsaver
2013-05-08 15:16:58 -04:00
parent e843779555
commit 992ac73068
6 changed files with 21 additions and 32 deletions

View File

@@ -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<pvString>(&from[fromOffset], length, offset);
pv->copyIn<pvString>(&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<pvString>(&to[toOffset], length, offset);
pv->copyOut<pvString>(&to[toOffset], length);
return length;
}

View File

@@ -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<PVStringArray *>(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<PVStringArray&>(*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<PVStringArray *>(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<PVStringArray&>(*pvScalarArray).swap(cdata);
return pvStructure;
}

View File

@@ -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<pvString>(&temp[0], temp.size());
shared_vector<String> temp;
pv.getAs<pvString>(temp);
S() << pv.getScalarArray()->getID() << " "
<< pv.getFieldName() << " [";

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<numChoices; i++ ) fprintf(fd," %s",(*choices)[i].c_str());
for(int i=0; i<numChoices; i++ ) fprintf(fd," %s",choices[i].c_str());
fprintf(fd,"\n");
}
pvEnumerated.setIndex(2);