Field::getID() support

This commit is contained in:
Matej Sekoranja
2012-07-31 10:32:33 +02:00
parent e74f2cdb2a
commit 619d1013d0
2 changed files with 15 additions and 11 deletions

View File

@@ -386,8 +386,11 @@ void formatNTTable(StringBuilder buffer, PVStructure *pvStruct)
{
PVStringArrayPtr labels = static_pointer_cast<PVStringArray>(pvStruct->getScalarArrayField("labels", pvString));
if (labels.get() == 0)
{
std::cout << "no 'labels' column" << std::endl;
return; // TODO
}
int numColumns = labels->getLength();
//int count = pvStruct->getNumberFields();
// TODO if (count < #numColumns)
@@ -400,8 +403,8 @@ void formatNTTable(StringBuilder buffer, PVStructure *pvStruct)
for (int i = 0; i < numColumns; i++)
{
DoubleArrayData values;
// TODO we relay on field ordering here (normativeType, labels, <columns>)
PVDoubleArrayPtr arrayField = static_pointer_cast<PVDoubleArray>(fields[i+2]);
// TODO we relay on field ordering here (labels, <columns>)
PVDoubleArrayPtr arrayField = static_pointer_cast<PVDoubleArray>(fields[i+1]);
int count = arrayField->get(0, arrayField->getLength(), values);
if (count > maxValues) maxValues = count;
columnData.push_back(&values.data);
@@ -439,11 +442,12 @@ void toNTString(StringBuilder buffer, PVField *pv,int notFirst)
{
PVStructure* pvStruct = static_cast<PVStructure*>(pv);
// TODO type check, getStringField is verbose
PVStringPtr ntType = static_pointer_cast<PVString>(pvStruct->getSubField("normativeType"));
if (ntType.get())
// PVStringPtr ntType = static_pointer_cast<PVString>(pvStruct->getSubField("normativeType"));
// if (ntType.get())
{
String value = ntType->get();
// String value = ntType->get();
String value = pvStruct->getField()->getID();
if (value == "NTTable")
{
formatNTTable(buffer, pvStruct);

View File

@@ -416,8 +416,8 @@ class MockChannelRPC : public ChannelRPC
int totalFields = 1 + 1 + atoi(columns->get().c_str()); // normativeType, labels, <columns>
StringArray fieldNames(totalFields);
FieldConstPtrArray fields(totalFields);
fieldNames[i] = "normativeType";
fields[i++] = getFieldCreate()->createScalar(pvString);
//fieldNames[i] = "normativeType";
//fields[i++] = getFieldCreate()->createScalar(pvString);
fieldNames[i] = "labels";
fields[i++] = getFieldCreate()->createScalarArray(pvString);
char sbuf[16];
@@ -431,9 +431,9 @@ class MockChannelRPC : public ChannelRPC
}
PVStructure::shared_pointer result(
new PVStructure(getFieldCreate()->createStructure(fieldNames, fields)));
new PVStructure(getFieldCreate()->createStructure("NTTable", fieldNames, fields)));
result->getStringField("normativeType")->put("NTTable");
//result->getStringField("normativeType")->put("NTTable");
static_pointer_cast<PVStringArray>(result->getScalarArrayField("labels", pvString))->put(0, labels.size(), &labels[0], 0);
srand ( time(NULL) );