fix bug in PVStructure::appendPVField and PVStructure::appendPVFields
This commit is contained in:
@@ -130,6 +130,30 @@ PVFieldPtr PVStructure::getSubField(size_t fieldOffset) const
|
||||
throw std::logic_error("PVStructure.getSubField: Logic error");
|
||||
}
|
||||
|
||||
void PVStructure::fixParentStructure()
|
||||
{
|
||||
PVStructure *parent = getParent();
|
||||
if(parent==NULL) return;
|
||||
StructureConstPtr parentStructure = parent->structurePtr;
|
||||
String fieldName = getFieldName();
|
||||
size_t index = parentStructure->getFieldIndex(fieldName);
|
||||
StringArray const &fieldNames = parentStructure->getFieldNames();
|
||||
size_t num = fieldNames.size();
|
||||
FieldConstPtrArray fields(num);
|
||||
FieldConstPtrArray const & oldFields = parentStructure->getFields();
|
||||
for(size_t i=0; i< num; i++) {
|
||||
if(i==index) {
|
||||
fields[i] = structurePtr;
|
||||
} else {
|
||||
fields[i] = oldFields[i];
|
||||
}
|
||||
}
|
||||
FieldConstPtr field = getFieldCreate()->createStructure(
|
||||
parentStructure->getID(),fieldNames,fields);
|
||||
parent->replaceField(field);
|
||||
parent->fixParentStructure();
|
||||
}
|
||||
|
||||
void PVStructure::appendPVField(
|
||||
String const &fieldName,
|
||||
PVFieldPtr const & pvField)
|
||||
@@ -146,6 +170,7 @@ void PVStructure::appendPVField(
|
||||
for(size_t i=0; i<newLength; i++) {
|
||||
pvFields[i]->setParentAndName(this,fieldNames[i]);
|
||||
}
|
||||
fixParentStructure();
|
||||
}
|
||||
|
||||
void PVStructure::appendPVFields(
|
||||
@@ -172,6 +197,7 @@ void PVStructure::appendPVFields(
|
||||
for(size_t i=0; i<newLength; i++) {
|
||||
(*xxx)[i]->setParentAndName(this,names[i]);
|
||||
}
|
||||
fixParentStructure();
|
||||
}
|
||||
|
||||
void PVStructure::removePVField(String const &fieldName)
|
||||
|
||||
@@ -816,6 +816,7 @@ public:
|
||||
*/
|
||||
PVStructure(StructureConstPtr const & structure,PVFieldPtrArray const & pvFields);
|
||||
private:
|
||||
void fixParentStructure();
|
||||
static PVFieldPtr nullPVField;
|
||||
static PVBooleanPtr nullPVBoolean;
|
||||
static PVBytePtr nullPVByte;
|
||||
|
||||
@@ -121,6 +121,33 @@ static void testAppendMore(FILE * fd)
|
||||
fprintf(fd,"testAppendMore PASSED\n");
|
||||
}
|
||||
|
||||
static void testAppendStructures(FILE * fd)
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppendStructures\n");
|
||||
PVFieldPtrArray fields;
|
||||
StringArray names;
|
||||
PVStructurePtr pvParent = pvDataCreate->createPVStructure(names,fields);
|
||||
PVFieldPtrArray topFields;
|
||||
StringArray topNames;
|
||||
PVStructurePtr pvTop = pvDataCreate->createPVStructure(topNames,topFields);
|
||||
pvParent->appendPVField("top",pvTop);
|
||||
PVFieldPtrArray valueFields;
|
||||
StringArray valueNames;
|
||||
PVStructurePtr pvValue = pvDataCreate->createPVStructure(valueNames,valueFields);
|
||||
pvTop->appendPVField("value",pvValue);
|
||||
PVFieldPtrArray indexFields;
|
||||
StringArray indexNames;
|
||||
PVStructurePtr pvIndex = pvDataCreate->createPVStructure(indexNames,indexFields);
|
||||
pvValue->appendPVField("index",pvIndex);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
builder.clear();
|
||||
pvParent->getField()->toString(&builder);
|
||||
if(debug) fprintf(fd,"field\n%s\n",builder.c_str());
|
||||
fprintf(fd,"testAppendStructures PASSED\n");
|
||||
}
|
||||
|
||||
static void append2(PVStructurePtr &pvStructure,
|
||||
const char *oneName,const char *twoName,
|
||||
const char *oneValue,const char *twoValue)
|
||||
@@ -193,6 +220,7 @@ int main(int argc,char *argv[])
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testAppendStructures(fd);
|
||||
testAppendSimple(fd);
|
||||
testAppendMore(fd);
|
||||
testAppends(fd);
|
||||
|
||||
Reference in New Issue
Block a user