Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
void test_builder()
{
    testDiag("test_builder");

    NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    StructureConstPtr structure = builder->
            addTags()->
            addAlarm()->
            addTimeStamp()->
            add("extra",fieldCreate->createScalar(pvString)) ->
            createStructure();
    testOk1(structure.get() != 0);
    if (!structure)
        return;

    testOk1(NTNDArrayAttribute::is_a(structure));
    testOk1(structure->getID() == NTNDArrayAttribute::URI);
    testOk1(structure->getNumberFields() == 9);
    testOk1(structure->getField("name").get() != 0);
    testOk1(structure->getField("value").get() != 0);
    testOk1(structure->getField("tags").get() != 0);
    testOk1(structure->getField("descriptor").get() != 0);
    testOk1(structure->getField("alarm").get() != 0);
    testOk1(structure->getField("timeStamp").get() != 0);
    testOk1(structure->getField("sourceType").get() != 0);
    testOk1(structure->getField("source").get() != 0);

    ScalarConstPtr nameField = structure->getField<Scalar>("name");
    testOk(nameField.get() != 0 && nameField->getScalarType() == pvString,
        "name is string");

    UnionConstPtr valueField = structure->getField<Union>("value");
    testOk(valueField.get() != 0, "value is enum");

    ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags");
    testOk(tagsField.get() != 0 && tagsField->getElementType() == pvString,
        "tags is string[]");

    std::cout << *structure << std::endl;

}
Пример #5
0
    static bool isCompatible(UnionConstPtr const &u)
    {
        if(!u.get()) return false;

        if (u->getID() != Union::defaultId()) return false;
        if (u->isVariant()) return false;

        for (int i = pvBoolean; i != pvString; ++i)
        {
            ScalarType scalarType = static_cast<ScalarType>(i);
            std::string name(ScalarTypeFunc::name(scalarType));
            name += "Value";
            ScalarArrayConstPtr scalarField = u->getField<ScalarArray>(name);
            if (scalarField.get() == 0 ||
                    scalarField->getElementType() != scalarType)
                return false;
        }

        return true;
    }