size_t fromString(PVUnionArrayPtr const &pv, StringArray const & from, size_t fromStartIndex = 0) { int processed = 0; size_t fromValueCount = from.size(); // first get count if (fromStartIndex >= fromValueCount) throw std::runtime_error("not enough of values"); size_t numberOfUnions; istringstream iss(from[fromStartIndex]); iss >> numberOfUnions; // not fail and entire value is parsed (e.g. to detect 1.2 parsing to 1) if (iss.fail() || !iss.eof()) throw runtime_error("failed to parse element count value (uint) of field '" + pv->getFieldName() + "' from string value '" + from[fromStartIndex] + "'"); fromStartIndex++; processed++; PVUnionArray::svector pvUnions; pvUnions.reserve(numberOfUnions); PVDataCreatePtr pvDataCreate = getPVDataCreate(); for (size_t i = 0; i < numberOfUnions; ++i) { PVUnionPtr pvUnion = pvDataCreate->createPVUnion(pv->getUnionArray()->getUnion()); size_t count = fromString(pvUnion, from, fromStartIndex); processed += count; fromStartIndex += count; pvUnions.push_back(pvUnion); } pv->replace(freeze(pvUnions)); return processed; }
PVFieldPtr PVDataCreate::createPVField(PVFieldPtr const & fieldToClone) { switch(fieldToClone->getField()->getType()) { case scalar: { PVScalarPtr pvScalar = static_pointer_cast<PVScalar>(fieldToClone); return createPVScalar(pvScalar); } case scalarArray: { PVScalarArrayPtr pvScalarArray = static_pointer_cast<PVScalarArray>(fieldToClone); return createPVScalarArray(pvScalarArray); } case structure: { PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(fieldToClone); StringArray const & fieldNames = pvStructure->getStructure()->getFieldNames(); PVFieldPtrArray const & pvFieldPtrArray = pvStructure->getPVFields(); return createPVStructure(fieldNames,pvFieldPtrArray); } case structureArray: { PVStructureArrayPtr from = static_pointer_cast<PVStructureArray>(fieldToClone); StructureArrayConstPtr structureArray = from->getStructureArray(); PVStructureArrayPtr to = createPVStructureArray( structureArray); to->copyUnchecked(*from); return to; } case union_: { PVUnionPtr pvUnion = static_pointer_cast<PVUnion>(fieldToClone); return createPVUnion(pvUnion); } case unionArray: { PVUnionArrayPtr from = static_pointer_cast<PVUnionArray>(fieldToClone); UnionArrayConstPtr unionArray = from->getUnionArray(); PVUnionArrayPtr to = createPVUnionArray(unionArray); to->copyUnchecked(*from); return to; } } throw std::logic_error("PVDataCreate::createPVField should never get here"); }