fromString for structure

This commit is contained in:
Matej Sekoranja
2011-06-02 10:11:02 +02:00
parent 91e08ebe90
commit fb2691c2a3
2 changed files with 40 additions and 0 deletions

View File

@@ -124,6 +124,44 @@ void Convert::getString(StringBuilder buf,PVField * pvField)
convertToString(buf,pvField,0);
}
int Convert::fromString(PVStructure *pvStructure, std::vector<String>& from, int fromStartIndex)
{
int processed = 0;
PVFieldPtrArray fieldsData = pvStructure->getPVFields();
if (fieldsData != 0) {
int length = pvStructure->getStructure()->getNumberFields();
for(int i=0; i<length; i++) {
PVField *fieldField = fieldsData[i];
Type type = fieldField->getField()->getType();
if(type==structure) {
int count = fromString(static_cast<PVStructure*>(fieldField), from, fromStartIndex);
processed += count;
fromStartIndex += count;
}
else if(type==scalarArray) {
int count = fromString(static_cast<PVScalarArray*>(fieldField), from.at(fromStartIndex));
processed += count;
fromStartIndex += count;
}
else if(type==scalar) {
fromString(static_cast<PVScalar*>(fieldField), from.at(fromStartIndex++));
processed++;
}
else {
// structureArray not supported
String message("Convert::fromString unsupported fieldType ");
TypeFunc::toString(&message,type);
throw std::logic_error(message);
}
}
}
return processed;
}
void Convert::fromString(PVScalar *pvScalar, String from)
{
ScalarConstPtr scalar = pvScalar->getScalar();

View File

@@ -11,6 +11,7 @@
#include "pvIntrospect.h"
#include "pvData.h"
#include <vector>
namespace epics { namespace pvData {
@@ -46,6 +47,7 @@ public:
bool equals(PVField &a,PVField &b);
void getString(StringBuilder buf,PVField * pvField,int indentLevel);
void getString(StringBuilder buf,PVField *pvField);
int fromString(PVStructure *pv, std::vector<String>& from, int fromStartIndex = 0);
void fromString(PVScalar *pv, String from);
int fromString(PVScalarArray *pv, String from);
int fromStringArray(PVScalarArray *pv, int offset, int length,