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


C++ TreeNode::childByName方法代码示例

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


在下文中一共展示了TreeNode::childByName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_childByName

void TreeNodeTest::test_childByName()
{
  // same tree as for test_child()

  NRoot::Ptr node(new NRoot("Root"));
  NGeneric::Ptr node1(new NGeneric("Node1", "MyType"));
  NGeneric::Ptr node11(new NGeneric("Node11", "MyType"));
  NGeneric::Ptr node12(new NGeneric("Node12", "MyType"));
  NGeneric::Ptr node2(new NGeneric("Node2", "MyType"));
  NGeneric::Ptr node21(new NGeneric("Node21", "MyType"));
  NGeneric::Ptr node22(new NGeneric("Node22", "MyType"));
  NGeneric::Ptr node23(new NGeneric("Node23", "MyType"));
  NGeneric::Ptr node3(new NGeneric("Node3", "MyType"));

  TreeNode * treeNode = nullptr;
  TreeNode * treeNode1 = nullptr;
  TreeNode * treeNode11 = nullptr;
  TreeNode * treeNode12 = nullptr;
  TreeNode * treeNode2 = nullptr;
  TreeNode * treeNode21 = nullptr;
  TreeNode * treeNode22 = nullptr;
  TreeNode * treeNode23 = nullptr;
  TreeNode * treeNode3 = nullptr;

  node->addNode(node1);
  node->addNode(node2);
  node->addNode(node3);

  node1->addNode(node11);
  node1->addNode(node12);

  node2->addNode(node21);
  node2->addNode(node22);
  node2->addNode(node23);

  treeNode = new TreeNode(node, nullptr, 0);
  treeNode1 = treeNode->child(0);
  treeNode11 = treeNode1->child(0);
  treeNode12 = treeNode1->child(1);
  treeNode2 = treeNode->child(1);
  treeNode21 = treeNode2->child(0);
  treeNode22 = treeNode2->child(1);
  treeNode23 = treeNode2->child(2);
  treeNode3 = treeNode->child(2);

  //
  // 1. check the direct children
  //
  treeNode1 = treeNode->childByName("Node1");
  treeNode2 = treeNode->childByName("Node2");
  treeNode3 = treeNode->childByName("Node3");

  // check that pointer are not null
  QVERIFY( treeNode1 != (TreeNode*) nullptr );
  QVERIFY( treeNode2 != (TreeNode*) nullptr );
  QVERIFY( treeNode3 != (TreeNode*) nullptr );

  // their parent should be the root
  QCOMPARE( treeNode1->parentNode(), treeNode );
  QCOMPARE( treeNode2->parentNode(), treeNode );
  QCOMPARE( treeNode3->parentNode(), treeNode );

  // check their row number
  QCOMPARE( treeNode1->rowNumber(), 0 );
  QCOMPARE( treeNode2->rowNumber(), 1 );
  QCOMPARE( treeNode3->rowNumber(), 2 );

  //
  // 2. children of Node1
  //
  treeNode11 = treeNode1->childByName("Node11");
  treeNode12 = treeNode1->childByName("Node12");

  // check that pointer are not null
  QVERIFY( treeNode11 != (TreeNode*) nullptr );
  QVERIFY( treeNode12 != (TreeNode*) nullptr );

  // their parent should be the root
  QCOMPARE( treeNode11->parentNode(), treeNode1 );
  QCOMPARE( treeNode12->parentNode(), treeNode1 );

  // check their row number
  QCOMPARE( treeNode11->rowNumber(), 0 );
  QCOMPARE( treeNode12->rowNumber(), 1 );

  //
  // 3. wrong name
  //
  QCOMPARE ( treeNode2->childByName("Node"), (TreeNode*) nullptr );


  delete treeNode; // deletes the children as well
}
开发者ID:,项目名称:,代码行数:93,代码来源:


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