本文整理汇总了C++中NodeRef::get_child方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRef::get_child方法的具体用法?C++ NodeRef::get_child怎么用?C++ NodeRef::get_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeRef
的用法示例。
在下文中一共展示了NodeRef::get_child方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testClone
void testClone() {
NodeRef p = Node::create("Parent");
NodeRef c = Node::create("child");
p->add_child(c);
NodeRef copy = p->clone();
copy->get_child("child")->set_name("child1");
CPPUNIT_ASSERT_NO_THROW ( copy->get_child("child1") );
CPPUNIT_ASSERT_NO_THROW ( p->get_child("child") );
CPPUNIT_ASSERT_THROW ( p->get_child("child1"), Exception );
NodeRef attr = Node::create("attr");
p->set_attr("test",attr);
p->set_attr("data",3);
copy = p->clone();
((NodeRef)copy->get_attr("test"))->set_name("attr1");
CPPUNIT_ASSERT_EQUAL ( ((NodeRef)p->get_attr("test"))->get_name(), std::string("attr" ) );
CPPUNIT_ASSERT_EQUAL ( ((NodeRef)copy->get_attr("test"))->get_name(), std::string("attr1" ) );
CPPUNIT_ASSERT_NO_THROW ( copy->get_attr("data") );
CPPUNIT_ASSERT_EQUAL ( 3, (int) copy->get_attr("data" ) );
NodeRef di = DeviceInterface::create("di");
NodeRef term = Terminal::create("term1");
di->add_child(term);
NodeRef term2 = term->clone();
term2->set_name("term2");
term2->del_attr("addr"); // so we get a new one
CPPUNIT_ASSERT_NO_THROW( di->add_child(term2) );
}
示例2: testRefs
void testRefs() {
NodeRef orig = DeviceInterface::create("top");
orig->add_child(Terminal::create("child1"));
NodeRef child2 = Register::create("child2");
CPPUNIT_ASSERT_NO_THROW(orig->get_child ( "child1")->add_child(child2));
child2->set_attr("test", "hello" );
CPPUNIT_ASSERT_NO_THROW(orig->get_child ( "child1")->get_child("child2")->get_attr("test"));
CPPUNIT_ASSERT_EQUAL ( std::string("hello"), (std::string)orig->get_child("child1")->get_child("child2")->get_attr("test"));
}
示例3: testNameChange
void testNameChange() {
NodeRef p = Node::create("Parent");
NodeRef c = Node::create("child");
p->add_child( c );
c->set_name ( "child1" );
CPPUNIT_ASSERT_THROW ( p->get_child ( "child" ), Exception );
CPPUNIT_ASSERT_NO_THROW ( p->get_child ( "child1" ) );
}
示例4: testXml
void testXml () {
const char* xml_path="test.xml";
XmlReader dummy ( "some_nonexistent_file_path" ) ;
NodeRef tmp = DeviceInterface::create("hi");
CPPUNIT_ASSERT_THROW(dummy.read(tmp), Exception);
XmlReader reader (xml_path, true);
NodeRef tree = DeviceInterface::create("root");
CPPUNIT_ASSERT_NO_THROW(reader.read(tree));
CPPUNIT_ASSERT_NO_THROW(tree->get_attr("name"));
CPPUNIT_ASSERT_EQUAL( string("Test Device Interface"), (string) tree->get_attr("name") );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child("Terminal1") );
CPPUNIT_ASSERT_THROW ( tree->get_child("some_other_term"), Exception );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child("Terminal1")->get_child("reg1"));
CPPUNIT_ASSERT_NO_THROW ( tree->get_attr("version") );
CPPUNIT_ASSERT_EQUAL ( string("test_di"), (string) tree->get_attr("version") );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ( "Terminal1")->get_attr("version") );
CPPUNIT_ASSERT_EQUAL ( string("1.0"), (string) tree->get_child("Terminal1")->get_attr("version") );
NodeRef term1=tree->get_child("Terminal1");
NodeRef reg1=term1->get_child("reg1");
CPPUNIT_ASSERT_NO_THROW ( reg1->get_attr("width") );
CPPUNIT_ASSERT ( reg1->get_attr("width") == 18 );
CPPUNIT_ASSERT_NO_THROW ( reg1->get_attr("mode") );
CPPUNIT_ASSERT ( reg1->get_attr("mode") == "write" );
CPPUNIT_ASSERT_NO_THROW ( reg1->get_attr("type") );
CPPUNIT_ASSERT ( reg1->get_attr("type") == "int" );
CPPUNIT_ASSERT_NO_THROW ( term1->get_child("addr2reg") );
CPPUNIT_ASSERT_NO_THROW ( term1->get_child("addr2reg")->get_attr("addr") );
CPPUNIT_ASSERT ( term1->get_child("addr2reg")->get_attr("addr") == 2 );
CPPUNIT_ASSERT ( term1->get_child("addr2reg")->has_attr("comment"));
CPPUNIT_ASSERT_NO_THROW( term1->get_child("reg2") );
NodeRef reg2=term1->get_child("reg2");
CPPUNIT_ASSERT ( reg2->get_attr("type") == "trigger" );
CPPUNIT_ASSERT ( reg2->get_attr("addr") == 23 );
CPPUNIT_ASSERT_NO_THROW( term1->get_child("reg3") );
NodeRef reg3=term1->get_child("reg3");
CPPUNIT_ASSERT ( reg3->get_attr("type") == "int" );
CPPUNIT_ASSERT_NO_THROW ( reg3->get_attr("width") );
CPPUNIT_ASSERT ( reg3->get_attr("width") == 3 );
CPPUNIT_ASSERT_NO_THROW ( reg3->get_attr ( "addr" ) );
CPPUNIT_ASSERT ( reg3->get_attr("addr") == 24 );
CPPUNIT_ASSERT_NO_THROW ( reg3->get_child("subreg2") );
NodeRef sub2 = reg3->get_child("subreg2");
CPPUNIT_ASSERT_NO_THROW ( sub2->get_attr("valuemap") );
CPPUNIT_ASSERT_EQUAL ( 1, (int32) ((NodeRef)sub2->get_attr("valuemap"))->get_attr("OFF") );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child("term2") );
CPPUNIT_ASSERT_EQUAL ( 0x200, (int) tree->get_child("term2")->get_attr("addr") );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child("array_term" )->get_child("array1") );
CPPUNIT_ASSERT_EQUAL ( 5, (int) tree->get_child("array_term")->get_child("array1")->get_attr("array") );
NodeRef a2 = tree->get_child("array_term")->get_child("array2");
CPPUNIT_ASSERT_EQUAL ( LIST_DATA, a2->get_attr("init").get_type() );
vector<DataType> init = a2->get_attr("init");
CPPUNIT_ASSERT_EQUAL ( INT_DATA, init.at(1).get_type() );
CPPUNIT_ASSERT_EQUAL ( 2, (int) init.at(1) );
CPPUNIT_ASSERT_EQUAL ( BIGINT_DATA, init.at(2).get_type() );
// include
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ( "include_term" ) );
CPPUNIT_ASSERT_EQUAL ( 76, (int) tree->get_child ( "include_term" )->get_attr ( "addr" ) );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ( "include_term1" ) );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ( "include_term1" )->get_child("reg_renamed"));
CPPUNIT_ASSERT_EQUAL ( 77, (int) tree->get_child ( "include_term1")->get_attr ( "addr" ) );
CPPUNIT_ASSERT_EQUAL ( 1, (int) tree->get_child("include_term1")->get_child("reg_renamed")->get_attr("addr") );
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ("include_term1" )->get_child ("new_register") );
// endian
CPPUNIT_ASSERT_NO_THROW ( tree->get_child ( "big_term" ) );
NodeRef bt = tree->get_child("big_term");
CPPUNIT_ASSERT_EQUAL ( string("big"), (string) bt->get_attr( "endian" ) );
CPPUNIT_ASSERT_EQUAL ( string("little"), (string) tree->get_child("term2")->get_attr("endian") );
CPPUNIT_ASSERT_NO_THROW ( bt->get_child( "big" ) );
CPPUNIT_ASSERT_NO_THROW ( bt->get_child( "big" )->get_attr("endian") );
CPPUNIT_ASSERT_EQUAL ( string("big"), (string) bt->get_child("big")->get_attr("endian") );
CPPUNIT_ASSERT_NO_THROW ( bt->get_child( "little" ) );
CPPUNIT_ASSERT_NO_THROW ( bt->get_child( "little" )->get_attr("endian") );
CPPUNIT_ASSERT_EQUAL ( string("little"), (string) bt->get_child("little")->get_attr("endian") );
}
示例5: testAttrs
void testAttrs() {
NodeRef orig = DeviceInterface::create("top");
CPPUNIT_ASSERT_THROW ( orig->get_attr("attrX"), Exception );
orig->set_attr ( "attr1", 1 );
orig->set_attr ( "attr2", std::string("two") );
orig->set_attr ( "attr3", 3 );
CPPUNIT_ASSERT ( orig->get_attr("attr3")==3 );
orig->set_attr ( "attr3", 4 ); // overwrite
CPPUNIT_ASSERT ( orig->get_attr("attr3")==4 );
orig->set_attr ( "attr3", 5 ); // overwrite again
CPPUNIT_ASSERT ( orig->get_attr("attr3")==5 );
CPPUNIT_ASSERT ( orig->get_attr("attr1")== 1 );
CPPUNIT_ASSERT ( orig->get_attr("attr2") == "two" );
CPPUNIT_ASSERT_THROW ( orig->get_attr ( "attrX" ), Exception );
{
NodeRef attr_map = Node::create("generic attrs");
attr_map->set_attr ( "map1", 1 );
attr_map->set_attr ( "map2", 2 );
orig->set_attr ( "map", attr_map );
// attr map out of scope
}
CPPUNIT_ASSERT_NO_THROW ( orig->get_attr ( "map" ));
CPPUNIT_ASSERT_EQUAL ( NODE_DATA, orig->get_attr( "map" ).get_type());
CPPUNIT_ASSERT_EQUAL ( 2, (int32)((NodeRef)orig->get_attr("map"))->get_attr ("map2") );
// four attrs
DIAttrIter ai = orig->attrs_begin();
++ai;
++ai;
CPPUNIT_ASSERT ( ai != orig->attrs_end() );
++ai;
++ai;
CPPUNIT_ASSERT ( ai == orig->attrs_end() );
{
NodeRef first = Terminal::create("first");
first->set_attr("attr1", 1 );
orig->add_child(first);
//first goes out of scope
}
NodeRef child=orig->get_child("first");
child->set_attr ( "attr2", 2 );
CPPUNIT_ASSERT_THROW ( orig->get_child ("first")->get_attr ( "attrX" ), Exception );
CPPUNIT_ASSERT ( orig->get_child("first")->get_attr("attr2") == 2 );
{
NodeRef second = Terminal::create("second");
second->set_attr("attr3",std::string("three"));
orig->add_child(second);
// second goes out of scope
}
CPPUNIT_ASSERT_NO_THROW ( orig->get_child("second")->get_attr("attr3") );
NodeRef second=orig->get_child("second");
CPPUNIT_ASSERT ( second->get_attr("attr3") == "three" );
CPPUNIT_ASSERT_THROW ( orig->get_child("childY"), Exception );
// child ref should still be good
CPPUNIT_ASSERT_NO_THROW ( child->get_attr("attr1") );
}