当前位置: 首页>>代码示例>>C++>>正文


C++ NodeRef::add_child方法代码示例

本文整理汇总了C++中NodeRef::add_child方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRef::add_child方法的具体用法?C++ NodeRef::add_child怎么用?C++ NodeRef::add_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodeRef的用法示例。


在下文中一共展示了NodeRef::add_child方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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) ); 
        }
开发者ID:ubixum,项目名称:nitro,代码行数:35,代码来源:node.cpp

示例2: testCopy

        void testCopy() {

            NodeRef orig = DeviceInterface::create ( "orig" );
            orig->add_child(Terminal::create("child1"));
            orig->add_child(Terminal::create("child2"));
            NodeRef copy(orig);
            
            CPPUNIT_ASSERT ( copy->has_children() );
            CPPUNIT_ASSERT ( std::string("child1") == copy->get_child("child1")->get_name() );
            CPPUNIT_ASSERT ( std::string("child2") == copy->get_child("child2")->get_name() );
            CPPUNIT_ASSERT_THROW ( copy->get_child("child3") , Exception );

            NodeRef orig2 = DeviceInterface::create("orig");
            orig2->add_child(Terminal::create("child3"));
            orig2->add_child(Terminal::create("child4"));
            CPPUNIT_ASSERT_THROW ( orig2->add_child(Terminal::create("child3")), Exception );
            copy = orig2;
            
            CPPUNIT_ASSERT ( copy->has_children() );
            CPPUNIT_ASSERT_THROW ( copy->get_child("child1"), Exception );
            CPPUNIT_ASSERT_EQUAL ( std::string("child3") , copy->get_child("child3")->get_name() );

            int children=0;
            for (DITreeIter i = copy->child_begin(); i != copy->child_end(); ++i ) {
               children += 1; 
            }
            CPPUNIT_ASSERT ( children == 2 );
        };
开发者ID:ubixum,项目名称:nitro,代码行数:28,代码来源:node.cpp

示例3: 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"));
 }
开发者ID:ubixum,项目名称:nitro,代码行数:9,代码来源:node.cpp

示例4: testErase

 void testErase() {
    NodeRef node = Node::create("Test");
    NodeRef child1 = Node::create("child1");
    NodeRef child2 = Node::create("child2");
    node->add_child(child1);
    node->add_child(child2);
    CPPUNIT_ASSERT_NO_THROW( node->del_child("child2") );
    CPPUNIT_ASSERT_EQUAL ( 1, (int) node->num_children() );
    CPPUNIT_ASSERT_THROW ( node->del_child ( "child2" ), Exception ); 
 }
开发者ID:ubixum,项目名称:nitro,代码行数:10,代码来源:node.cpp

示例5: 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" ) );


        }
开发者ID:ubixum,项目名称:nitro,代码行数:13,代码来源:node.cpp

示例6: testOrder

 void testOrder() {
     NodeRef orig = DeviceInterface::create("top");
     for (int i=10;i>=0;--i) {
         std::stringstream io;
         std::string name;
         io << '_';
         io << i;
         io >> name;
         NodeRef child = Terminal::create(name);
         orig->add_child(child);
     }
     // nodes are ordered 
     int i=10;
     for (DITreeIter itr=orig->child_begin();itr!=orig->child_end();++itr) {
        NodeRef c =*itr; 
        std::stringstream io;
        std::string name;      
        io << '_';
        io << i--;
        io >> name;
        CPPUNIT_ASSERT_EQUAL ( name, c->get_name() ); 
     }
 }
开发者ID:ubixum,项目名称:nitro,代码行数:23,代码来源:node.cpp

示例7: 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") ); 

        }
开发者ID:ubixum,项目名称:nitro,代码行数:68,代码来源:node.cpp


注:本文中的NodeRef::add_child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。