本文整理汇总了C++中StructureConstPtr::getField方法的典型用法代码示例。如果您正苦于以下问题:C++ StructureConstPtr::getField方法的具体用法?C++ StructureConstPtr::getField怎么用?C++ StructureConstPtr::getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StructureConstPtr
的用法示例。
在下文中一共展示了StructureConstPtr::getField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isCompatible
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;
}
示例2: test_builder
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;
}
示例3: isCompatible
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;
}
示例4: test_nestedStructureArray
void test_nestedStructureArray()
{
testDiag("Test test_nestedStructureArray()");
FieldCreatePtr fieldCreate = getFieldCreate();
string NESTED_ID = "nestedID";
StructureConstPtr s = fieldCreate->createFieldBuilder()->
add("double", pvDouble)->
addNestedStructureArray("nested")->
setId(NESTED_ID)->
add("short", pvShort)->
add("long", pvLong)->
endNested()->
addArray("intArray", pvInt)->
createStructure();
testOk1(s.get() != 0);
testOk1(Structure::DEFAULT_ID == s->getID());
testOk1(3 == s->getFields().size());
FieldConstPtr f0 = s->getField(0);
testOk1(scalar == f0->getType());
testOk1("double" == s->getFieldName(0));
testOk(pvDouble == static_pointer_cast<const Scalar>(f0)->getScalarType(), "f0 scalar type == double");
FieldConstPtr f1 = s->getField(1);
testOk1(structureArray == f1->getType());
testOk1("nested" == s->getFieldName(1));
{
StructureConstPtr s2 = static_pointer_cast<const StructureArray>(f1)->getStructure();
testOk1(s2.get() != 0);
testOk1(NESTED_ID == s2->getID());
testOk1(2 == s2->getFields().size());
FieldConstPtr f20 = s2->getField(0);
testOk1(scalar == f20->getType());
testOk1("short" == s2->getFieldName(0));
testOk(pvShort == static_pointer_cast<const Scalar>(f20)->getScalarType(), "f20 scalar type == short");
FieldConstPtr f21 = s2->getField(1);
testOk1(scalar == f21->getType());
testOk1("long" == s2->getFieldName(1));
testOk(pvLong == static_pointer_cast<const Scalar>(f21)->getScalarType(), "f21 element type == long");
}
FieldConstPtr f2 = s->getField(2);
testOk1(scalarArray == f2->getType());
testOk1("intArray" == s->getFieldName(2));
testOk(pvInt == static_pointer_cast<const ScalarArray>(f2)->getElementType(), "f2 element type == int");
}
示例5: test_structure
void test_structure()
{
testDiag("Test test_structure()");
FieldCreatePtr fieldCreate = getFieldCreate();
FieldBuilderPtr fb = fieldCreate->createFieldBuilder();
// test with simple (non-nested) structure
string ID = "testStructureID";
StructureConstPtr s = fb->setId(ID)->
add("double", pvDouble)->
addArray("intArray", pvInt)->
createStructure();
testOk1(s.get() != 0);
testOk1(ID == s->getID());
testOk1(2 == s->getFields().size());
FieldConstPtr f0 = s->getField(0);
testOk1(scalar == f0->getType());
testOk1("double" == s->getFieldName(0));
testOk(pvDouble == static_pointer_cast<const Scalar>(f0)->getScalarType(), "f0 scalar type == double");
FieldConstPtr f1 = s->getField(1);
testOk1(scalarArray == f1->getType());
testOk1("intArray" == s->getFieldName(1));
testOk(pvInt == static_pointer_cast<const ScalarArray>(f1)->getElementType(), "f1 element type == int");
// test reuse with empty structure
StructureConstPtr emptyStructure = fb->createStructure();
testOk1(emptyStructure.get() != 0);
testOk1(Structure::DEFAULT_ID == emptyStructure->getID());
testOk1(0 == emptyStructure->getFields().size());
// test add/addArray with Field
StructureConstPtr s2 = fb->add("s", s)->
addArray("sArray", s)->
createStructure();
testOk1(s2.get()!=0);
testOk1(Structure::DEFAULT_ID == s2->getID());
testOk1(2 == s2->getFields().size());
f0 = s2->getField(0);
testOk1(structure == f0->getType());
testOk1("s" == s2->getFieldName(0));
testOk1(s.get() == f0.get());
f1 = s2->getField(1);
testOk1(structureArray == f1->getType());
testOk1("sArray" == s2->getFieldName(1));
testOk(s.get() == static_pointer_cast<const StructureArray>(f1)->getStructure().get(), "array element is given structure");
}
示例6: test_builder
void test_builder()
{
testDiag("test_builder");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
value(pvLong)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTHistogram::is_a(structure));
testOk1(structure->getID() == NTHistogram::URI);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("ranges").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("ranges")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("ranges"))->getElementType() == pvDouble, "ranges array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvLong, "value array element type");
std::cout << *structure << std::endl;
// no value set
try
{
structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testFail("no value type set");
} catch (std::runtime_error &) {
testPass("no value type set");
}
}
示例7: test_builder
void test_builder()
{
testDiag("test_builder");
NTTableBuilderPtr builder = NTTable::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTTable::is_a(structure));
testOk1(structure->getID() == NTTable::URI);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("labels").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("extra1").get() != 0);
testOk1(structure->getField("extra2").get() != 0);
StructureConstPtr s = dynamic_pointer_cast<const Structure>(structure->getField("value"));
#define TEST_COLUMN(name, type) \
testOk(s.get() != 0 && \
s->getField(name).get() != 0 && \
dynamic_pointer_cast<const ScalarArray>(s->getField(name)).get() != 0 && \
dynamic_pointer_cast<const ScalarArray>(s->getField(name))->getElementType() == type, \
name " check");
TEST_COLUMN("column0", pvDouble);
TEST_COLUMN("column1", pvString);
TEST_COLUMN("column2", pvInt);
#undef TEST_COLUMN
std::cout << *structure << std::endl;
// duplicate test
try
{
structure = builder->
addColumn("column0", pvDouble)->
addColumn("column0", pvString)->
createStructure();
testFail("duplicate column name");
} catch (std::runtime_error &) {
testPass("duplicate column name");
}
}
示例8: isCompatible
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;
}
示例9: test_extra
void test_extra()
{
testDiag("test_extra");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addTimeStamp()->
add("function", getFieldCreate()->createScalar(pvString))->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTContinuum::is_a(structure));
testOk1(structure->getID() == NTContinuum::URI);
testOk1(structure->getNumberFields() == 5);
testOk1(structure->getField("base").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("units").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("function").get() != 0);
testOk(dynamic_pointer_cast<const Scalar>(structure->getField("function")).get() != 0 &&
dynamic_pointer_cast<const Scalar>(structure->getField("function"))->getScalarType() == pvString, "function type");
std::cout << *structure << std::endl;
}
示例10: test_builder
void test_builder()
{
testDiag("test_builder");
NTScalarBuilderPtr builder = NTScalar::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
value(pvDouble)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addDisplay()->
addControl()->
add("valueAlarm",standardField->doubleAlarm()) ->
add("extra",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTScalar::is_a(structure));
testOk1(structure->getID() == NTScalar::URI);
testOk1(structure->getNumberFields() == 8);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("display").get() != 0);
testOk1(structure->getField("control").get() != 0);
testOk(dynamic_pointer_cast<const Scalar>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const Scalar>(structure->getField("value"))->getScalarType() == pvDouble, "value type");
std::cout << *structure << std::endl;
// no value set
try
{
structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addDisplay()->
addControl()->
createStructure();
testFail("no value type set");
} catch (std::runtime_error &) {
testPass("no value type set");
}
}
示例11: isCompatible
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;
}
示例12: test_builder
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;
}
示例13: test_builder
void test_builder(bool extraFields)
{
testDiag("test_builder");
NTNDArrayBuilderPtr builder = NTNDArray::createBuilder();
testOk(builder.get() != 0, "Got builder");
builder->addDescriptor()->
addTimeStamp()->
addAlarm()->
addDisplay();
if (extraFields)
{
builder->add("extra1",fieldCreate->createScalar(pvString))->
add("extra2",fieldCreate->createScalarArray(pvString));
}
StructureConstPtr structure = builder->createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTNDArray::is_a(structure));
testOk1(structure->getID() == NTNDArray::URI);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("compressedSize").get() != 0);
testOk1(structure->getField("uncompressedSize").get() != 0);
testOk1(structure->getField("codec").get() != 0);
testOk1(structure->getField("dimension").get() != 0);
testOk1(structure->getField("uniqueId").get() != 0);
testOk1(structure->getField("dataTimeStamp").get() != 0);
testOk1(structure->getField("attribute").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("display").get() != 0);
if (extraFields)
{
testOk1(structure->getField("extra1").get() != 0);
testOk1(structure->getField("extra2").get() != 0);
}
std::cout << *structure << std::endl;
}
示例14: test_builder
void test_builder()
{
testDiag("test_builder");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTContinuum::is_a(structure));
testOk1(structure->getID() == NTContinuum::URI);
testOk1(structure->getNumberFields() == 8);
testOk1(structure->getField("base").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("units").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("base")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("base"))->getElementType() == pvDouble, "base array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvDouble, "value array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("units")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("units"))->getElementType() == pvString, "units array element type");
std::cout << *structure << std::endl;
}
示例15: isCompatible
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;
}