use new API
make copying explicit and replace some use of PVValueArray<T>::put and get
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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() << " [";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user