StructureConstPtr NTMatrixBuilder::createStructure() { FieldBuilderPtr builder = getFieldCreate()->createFieldBuilder()-> setId(NTMatrix::URI)-> addArray("value", pvDouble); if (dim) builder->addArray("dim", pvInt); if (descriptor) builder->add("descriptor", pvString); if (alarm) builder->add("alarm", ntField->createAlarm()); if (timeStamp) builder->add("timeStamp", ntField->createTimeStamp()); if (display) builder->add("display", ntField->createDisplay()); size_t extraCount = extraFieldNames.size(); for (size_t i = 0; i< extraCount; i++) builder->add(extraFieldNames[i], extraFields[i]); StructureConstPtr s = builder->createStructure(); reset(); return s; }
StructureConstPtr NTAttributeBuilder::createStructure() { FieldBuilderPtr builder = getFieldCreate()->createFieldBuilder()-> setId(NTAttribute::URI)-> add("name", pvString)-> add("value", getFieldCreate()->createVariantUnion()); if (tags) builder->addArray("tags", pvString); if (descriptor) builder->add("descriptor", pvString); if (alarm) builder->add("alarm", ntField->createAlarm()); if (timeStamp) builder->add("timeStamp", ntField->createTimeStamp()); size_t extraCount = extraFieldNames.size(); for (size_t i = 0; i< extraCount; i++) builder->add(extraFieldNames[i], extraFields[i]); StructureConstPtr s = builder->createStructure(); reset(); return s; }
StructureConstPtr NTTableBuilder::createStructure() { FieldBuilderPtr builder = getFieldCreate()->createFieldBuilder(); FieldBuilderPtr nestedBuilder = builder-> setId(NTTable::URI)-> addArray("labels", pvString)-> addNestedStructure("value"); vector<string>::size_type len = labels.size(); for (vector<string>::size_type i = 0; i < len; i++) nestedBuilder->addArray(labels[i], types[i]); builder = nestedBuilder->endNested(); if (descriptor) builder->add("descriptor", pvString); if (alarm) builder->add("alarm", ntField->createAlarm()); if (timeStamp) builder->add("timeStamp", ntField->createTimeStamp()); StructureConstPtr s = builder->createStructure(); size_t extraCount = extraFieldNames.size(); for (size_t i = 0; i< extraCount; i++) builder->add(extraFieldNames[i], extraFields[i]); reset(); return s; }
StructureConstPtr NTNDArrayBuilder::createStructure() { enum { DISCRIPTOR_INDEX, TIMESTAMP_INDEX, ALARM_INDEX, DISPLAY_INDEX }; const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1; const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES; Lock xx(mutex); static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES]; static UnionConstPtr valueType; static StructureConstPtr codecStruc; static StructureConstPtr dimensionStruc; static StructureConstPtr attributeStruc; StructureConstPtr returnedStruc; size_t index = 0; if (descriptor) index |= 1 << DISCRIPTOR_INDEX; if (timeStamp) index |= 1 << TIMESTAMP_INDEX; if (alarm) index |= 1 << ALARM_INDEX; if (display) index |= 1 << DISPLAY_INDEX; bool isExtended = !extraFieldNames.empty(); if (isExtended || !ntndarrayStruc[index]) { StandardFieldPtr standardField = getStandardField(); FieldBuilderPtr fb = fieldCreate->createFieldBuilder(); if (!valueType) { for (int i = pvBoolean; i < pvString; ++i) { ScalarType st = static_cast<ScalarType>(i); fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st); } valueType = fb->createUnion(); } if (!codecStruc) { codecStruc = fb->setId("codec_t")-> add("name", pvString)-> add("parameters", fieldCreate->createVariantUnion())-> createStructure(); } if (!dimensionStruc) { dimensionStruc = fb->setId("dimension_t")-> add("size", pvInt)-> add("offset", pvInt)-> add("fullSize", pvInt)-> add("binning", pvInt)-> add("reverse", pvBoolean)-> createStructure(); } if (!attributeStruc) { attributeStruc = NTNDArrayAttribute::createBuilder()->createStructure(); } fb->setId(NTNDArray::URI)-> add("value", valueType)-> add("codec", codecStruc)-> add("compressedSize", pvLong)-> add("uncompressedSize", pvLong)-> addArray("dimension", dimensionStruc)-> add("uniqueId", pvInt)-> add("dataTimeStamp", standardField->timeStamp())-> addArray("attribute", attributeStruc); if (descriptor) fb->add("descriptor", pvString); if (alarm) fb->add("alarm", standardField->alarm()); if (timeStamp) fb->add("timeStamp", standardField->timeStamp()); if (display) fb->add("display", standardField->display()); size_t extraCount = extraFieldNames.size(); for (size_t i = 0; i< extraCount; i++) fb->add(extraFieldNames[i], extraFields[i]); returnedStruc = fb->createStructure(); if (!isExtended) ntndarrayStruc[index] = returnedStruc; } else { return ntndarrayStruc[index]; } return returnedStruc; }