bool NTHistogram::isCompatible(StructureConstPtr const &structure) { if(!structure.get()) return false; ScalarArrayConstPtr rangesField = structure->getField<ScalarArray>("ranges"); if(!rangesField.get() || rangesField->getElementType() != pvDouble) return false; ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value"); if(!valueField.get()) return false; ScalarType scalarType = valueField->getElementType(); if (scalarType != pvShort && scalarType != pvInt && scalarType != pvLong) return false; FieldConstPtr field = structure->getField("descriptor"); if(field) { ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor"); if (!descriptorField.get() || descriptorField->getScalarType() != pvString) return false; } field = structure->getField("alarm"); if (field.get() && !ntField->isAlarm(field)) return false; field = structure->getField("timeStamp"); if (field.get() && !ntField->isTimeStamp(field)) return false; return true; }
void test_builder() { testDiag("test_builder"); NTEnumBuilderPtr builder = NTEnum::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> add("valueAlarm",standardField->doubleAlarm()) -> add("extra",fieldCreate->createScalarArray(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTEnum::is_a(structure)); testOk1(structure->getID() == NTEnum::URI); testOk1(structure->getNumberFields() == 6); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); FieldConstPtr valueField = structure->getField("value"); testOk(valueField.get() != 0 && ntField->isEnumerated(valueField), "value is enum"); std::cout << *structure << std::endl; }
bool NTNameValue::isCompatible(StructureConstPtr const & structure) { if (structure.get() == 0) return false; ScalarArrayConstPtr nameField = structure->getField<ScalarArray>("name"); if (nameField.get() == 0 || nameField->getElementType() != pvString) return false; ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value"); if (valueField.get() == 0) return false; FieldConstPtr field = structure->getField("descriptor"); if (field.get()) { ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor"); if (!descriptorField || descriptorField->getScalarType() != pvString) return false; } NTFieldPtr ntField = NTField::get(); field = structure->getField("alarm"); if (field && !ntField->isAlarm(field)) return false; field = structure->getField("timeStamp"); if (field && !ntField->isTimeStamp(field)) return false; return true; }
void Structure::dumpFields(std::ostream& o) const { size_t numberFields = fields.size(); for(size_t i=0; i<numberFields; i++) { FieldConstPtr pfield = fields[i]; o << format::indent() << pfield->getID() << ' ' << fieldNames[i] << std::endl; switch(pfield->getType()) { case scalar: case scalarArray: break; case structure: { Field const *xxx = pfield.get(); Structure const *pstruct = static_cast<Structure const*>(xxx); format::indent_scope s(o); pstruct->dumpFields(o); break; } case structureArray: { format::indent_scope s(o); Field const *xxx = pfield.get(); StructureArray const *pstructureArray = static_cast<StructureArray const*>(xxx); o << *pstructureArray->getStructure(); break; } case union_: { Field const *xxx = pfield.get(); Union const *punion = static_cast<Union const*>(xxx); format::indent_scope s(o); punion->dumpFields(o); break; } case unionArray: { format::indent_scope s(o); Field const *xxx = pfield.get(); UnionArray const *punionArray = static_cast<UnionArray const*>(xxx); o << *punionArray->getUnion(); break; } } } }
bool NTMatrix::isCompatible(StructureConstPtr const & structure) { if (structure.get() == 0) return false; ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value"); if (valueField.get() == 0 || valueField->getElementType() != pvDouble) return false; FieldConstPtr field = structure->getField("dim"); if (field.get()) { ScalarArrayConstPtr dimField = structure->getField<ScalarArray>("dim"); if (dimField.get() == 0 || dimField->getElementType() != pvInt) return false; } field = structure->getField("descriptor"); if (field.get()) { ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor"); if (!descriptorField.get() || descriptorField->getScalarType() != pvString) return false; } NTFieldPtr ntField = NTField::get(); field = structure->getField("alarm"); if (field.get() && !ntField->isAlarm(field)) return false; field = structure->getField("timeStamp"); if (field.get() && !ntField->isTimeStamp(field)) return false; field = structure->getField("display"); if (field.get() && !ntField->isDisplay(field)) return false; return true; }
bool NTScalar::isCompatible(StructureConstPtr const &structure) { if (structure.get() == 0) return false; ScalarConstPtr valueField = structure->getField<Scalar>("value"); if (valueField.get() == 0) return false; FieldConstPtr field = structure->getField("descriptor"); if (field.get()) { ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor"); if (!descriptorField.get() || descriptorField->getScalarType() != pvString) return false; } NTFieldPtr ntField = NTField::get(); field = structure->getField("alarm"); if (field.get() && !ntField->isAlarm(field)) return false; field = structure->getField("timeStamp"); if (field.get() && !ntField->isTimeStamp(field)) return false; field = structure->getField("display"); if (field.get() && !ntField->isDisplay(field)) return false; field = structure->getField("control"); if (field.get() && !ntField->isControl(field)) return false; return true; }
bool NTNDArray::isCompatible(StructureConstPtr const &structure) { if(!structure.get()) return false; UnionConstPtr valueField = structure->getField<Union>("value"); if(!NTValueType::isCompatible(valueField)) return false; StructureConstPtr codecField = structure->getField<Structure>("codec"); if(!NTCodec::isCompatible(codecField)) return false; ScalarConstPtr compressedSizeField = structure->getField<Scalar>("compressedSize"); if (compressedSizeField.get() == 0) return false; if (compressedSizeField->getScalarType() != pvLong) return false; ScalarConstPtr uncompressedSizeField = structure->getField<Scalar>("uncompressedSize"); if (uncompressedSizeField.get() == 0) return false; if (uncompressedSizeField->getScalarType() != pvLong) return false; StructureArrayConstPtr dimensionField = structure->getField<StructureArray>("dimension"); if (dimensionField.get() == 0) return false; StructureConstPtr dimElementStruc = dimensionField->getStructure(); if(!NTDimension::isCompatible(dimElementStruc)) return false; NTFieldPtr ntField = NTField::get(); StructureConstPtr dataTimeStampField = structure->getField<Structure>( "dataTimeStamp"); if (dataTimeStampField.get() == 0 || !ntField->isTimeStamp(dataTimeStampField)) return false; ScalarConstPtr uniqueIdField = structure->getField<Scalar>("uniqueId"); if (uniqueIdField.get() == 0) return false; if (uniqueIdField->getScalarType() != pvInt) return false; StructureArrayConstPtr attributeField = structure->getField<StructureArray>( "attribute"); StructureConstPtr attributeElementStruc = attributeField->getStructure(); if (!NTNDArrayAttribute::isCompatible(attributeElementStruc)) return false; FieldConstPtr field = structure->getField("descriptor"); if (field.get()) { ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor"); if (!descriptorField.get() || descriptorField->getScalarType() != pvString) return false; } field = structure->getField("alarm"); if (field.get() && !ntField->isAlarm(field)) return false; field = structure->getField("timeStamp"); if (field.get() && !ntField->isTimeStamp(field)) return false; field = structure->getField("display"); if (field.get() && !ntField->isDisplay(field)) return false; return true; }