void NTNDArrayRecord::setAttributes() { // Get the attribute field PVStructureArrayPtr attributeField = ndarray->getAttribute(); // Create a shared vector or reuse PVStructureArray::svector attributes(attributeField->reuse()); attributes.reserve(1); // Create an attribute for the Color Mode // name: ColorMode // value: variant union stores a PVInt with value 0 // descriptor: "Color mode" // source: "" // sourceType = 0 PVStructurePtr attribute = getPVDataCreate()->createPVStructure(attributeField->getStructureArray()->getStructure()); NTNDArrayAttributePtr ntattribute = NTNDArrayAttribute::wrap(attribute); ntattribute->getName()->put("ColorMode"); PVInt::shared_pointer pvColorMode = getPVDataCreate()->createPVScalar<PVInt>(); pvColorMode->put(0); ntattribute->getValue()->set(pvColorMode); ntattribute->getDescriptor()->put("Color mode"); ntattribute->getSourceType()->put(0); ntattribute->getSource()->put(""); attributes.push_back(attribute); // Replace the attribute fields stored attributeField->replace(freeze(attributes)); }
size_t fromString(PVStructureArrayPtr 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 numberOfStructures; istringstream iss(from[fromStartIndex]); iss >> numberOfStructures; // 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++; PVStructureArray::svector pvStructures; pvStructures.reserve(numberOfStructures); PVDataCreatePtr pvDataCreate = getPVDataCreate(); for (size_t i = 0; i < numberOfStructures; ++i) { PVStructurePtr pvStructure = pvDataCreate->createPVStructure(pv->getStructureArray()->getStructure()); size_t count = fromString(pvStructure, from, fromStartIndex); processed += count; fromStartIndex += count; pvStructures.push_back(pvStructure); } pv->replace(freeze(pvStructures)); return processed; }
void NTNDArrayRecord::setDimension(const int32_t * dims, size_t ndims) { // Get the dimension field PVStructureArrayPtr dimField = ndarray->getDimension(); // create a shared_vector or try to reuse the dimension field's one PVStructureArray::svector dimVector(dimField->reuse()); // resize/reserve the number of elements dimVector.resize(ndims); // Iterate over the number of dimensions, creating and adding the // appropriate dimension structures. for (size_t i = 0; i < ndims; i++) { PVStructurePtr d = dimVector[i]; if (!d || !d.unique()) d = dimVector[i] = getPVDataCreate()->createPVStructure(dimField->getStructureArray()->getStructure()); d->getSubField<PVInt>("size")->put(dims[i]); d->getSubField<PVInt>("offset")->put(0); d->getSubField<PVInt>("fullSize")->put(dims[i]); d->getSubField<PVInt>("binning")->put(1); d->getSubField<PVBoolean>("reverse")->put(false); } // replace the dimensions field's shared_vector // (Remember to freeze first) dimField->replace(freeze(dimVector)); }