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


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

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


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

示例1: getNode

    TreeNode* getNode(const LocationCode<maxLevels>& code)
    {
        int level = maxLevels;

        // FIXME: it's really important to start from root.child (as root is a header) and ALL TESTS
        // PASS WHEN IT'S CHANGED TO: `node = &root;`
        TreeNode* node = &(root.child(0, 0));

        do
        {
            if (!node->hasChildren() || node == &(node->child(code)))
                break;
            node = &(node->child(code));
        } while (--level);
        return node;
    }
开发者ID:mgoral,项目名称:geocontainers,代码行数:16,代码来源:QuadTree.hpp

示例2: test_updateChildList

void TreeNodeTest::test_updateChildList()
{
  NRoot::Ptr node(new NRoot("Root"));
  NGeneric::Ptr node1(new NGeneric("Node1", "MyType"));
  NGeneric::Ptr node2(new NGeneric("Node2", "MyType"));
  TreeNode * treeNode;
  TreeNode * child;

  node->addNode(node1);

  treeNode = new TreeNode(node, nullptr, 0);

  QCOMPARE( treeNode->childCount(), 1);

  node->addNode(node2);

  QCOMPARE( treeNode->childCount(), 2);

  child = treeNode->child(1);
  QVERIFY( child != nullptr );

  QCOMPARE( child->nodeName(), QString("Node2"));

  delete treeNode;
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: getMenuTreeRootNode

/*---------------------------------------------------------------------*//**
	ルートノード取得
**//*---------------------------------------------------------------------*/
MenuTreeNode* Menu::getMenuTreeRootNode() const
{
	TreeNode<MenuTreeNode>* tnode = _tree->getRoot();
	if(tnode == 0L)	{	return 0L;	}
	tnode = tnode->child();
	if(tnode == 0L)	{	return 0L;	}
	return tnode->object();
}
开发者ID:Altoterras,项目名称:TheHeartOfSourcerer,代码行数:11,代码来源:Menu.cpp

示例4: executeFunctionCall

void Executer::executeFunctionCall(TreeNode* node) {
//	//qDebug() << "called";
	if (node->parent()->token()->type() == Token::Learn) {  // in case we're defining a function
		currentNode = node->parent();
		executeCurrent = true;
		return;
	}

	if (returning) {  // if the function is already executed and returns now
		returnValue = 0;
		returning = false;
		// //qDebug() << "==> functionReturned!";
		return;
	}

	if (!functionTable.contains(node->token()->look())) {
		addError(i18n("An unknown function named '%1' was called", node->token()->look()), *node->token(), 0);
		return;
	}
	
	CalledFunction c;
	c.function      = node;
	c.variableTable = new VariableTable();
	functionStack.push(c);
	// //qDebug() << "==> functionCalled!";
	
	TreeNode* learnNode = functionTable[node->token()->look()];

	// if the parameter numbers are not equal...
	if (node->childCount() != learnNode->child(1)->childCount()) {
		addError(
			i18n("The function '%1' was called with %2, while it should be called with %3",
				node->token()->look(),
				i18ncp("The function '%1' was called with %2, while it should be called with %3", "1 parameter", "%1 parameters", node->childCount()),
				i18ncp("The function '%1' was called with %2, while it should be called with %3", "1 parameter", "%1 parameters", learnNode->child(1)->childCount())
			),
			*node->token(), 0);
		return;
	}
		
	for (uint i = 0; i < node->childCount(); i++) {
		functionStack.top().variableTable->insert(learnNode->child(1)->child(i)->token()->look(), node->child(i)->value());
		// //qDebug() << "inserted variable " << learnNode->child(1)->child(i)->token()->look() << " on function stack";
	}
	newScope = learnNode->child(2);
}
开发者ID:KDE,项目名称:kturtle,代码行数:46,代码来源:executer.cpp

示例5: main

int main(int argc, char* argv[])
{
	Timer::instance.start();
	cerr << "R " << argv[0]  << endl;
	cerr << "RAND_MAX = " << RAND_MAX << endl;
	cerr << "sizeof(bool) = " << sizeof(bool) << endl;
	cerr << "sizeof(uint) = " << sizeof(uint) << endl;
	cerr << "sizeof(uint64) = " << sizeof(uint64) << endl;
	cerr << "sizeof(uint128) = " << sizeof(uint128) << endl;
	cerr << "sizeof(void*) = " << sizeof(void*) << endl;
	cerr << "sizeof(std::size_t) = " << sizeof(std::size_t) << endl;
	cerr << "sizeof(Rotation) = " << sizeof(Rotation) << endl;
	cerr << "sizeof(SymmetryGroup) = " << sizeof(SymmetryGroup) << endl;
	cerr << "sizeof(BoardPoint) = " << sizeof(BoardPoint) << endl;
	cerr << "sizeof(Move) = " << sizeof(Move) << endl;
	cerr << "sizeof(BoardMask) = " << sizeof(BoardMask) << endl;
	cerr << "sizeof(Board) = " << sizeof(Board) << endl;
	cerr << "sizeof(BoardNode) = " << sizeof(BoardNode) << endl;
	cerr << "sizeof(BoardNode::OrientedBoardNode) = " << sizeof(BoardNode::OrientedBoardNode) << endl;
	cerr << "sizeof(TreeNode) = " << sizeof(TreeNode) << endl;
	srand(time(0));
	BoardNode::initialize();
	BoardMask::initialize();
	assert(BoardNode::fragmentCount() == 37);
	cerr << "Initialized" << endl;
	
	TreeNode root;
	TreeNode* node = &root;
	//root.loadGames("games.txt");
	
	for(uint i = 0; i < 50; ++i) {
		for(uint j = 0; j < 1000; ++j)
			node->mcts();
		Move bestMove = node->bestMove();
		node = node->child(bestMove);
		assert(node != nullptr);
	}
	cerr << "Treenodes: " << TreeNode::numNodes() << endl;
	BoardNode::dumpHisto();
	
	
	ofstream stats("stats.csv");
	BoardNode::dumpStats(stats);
	
	
	return 0;
	
	GameInputOutput gio;
	gio.run();
	cerr << "Exit" << endl;
	Timer::instance.stop();
	return 0;
}
开发者ID:Recmo,项目名称:Codecup-2015-Ayu,代码行数:53,代码来源:main.cpp

示例6: insert

 iterator insert(StoredObject&& toStore)
 {
     TreeNode* node = getNode(toStore.location);
     if (node->level() > 0)
     {
         // We store one element at time so there will be a moment before node overflow when its
         // count will be equal capacity. Then we'll relocate all its elements to the new child
         // nodes. At worst scenario, all elements will be relocated to the same node, so its
         // count() will be again equal to capacity. The loop ends when at least one element is
         // relocated to the another child node.
         while (node->count() == nodeCapacity && node->level() > 0)
         {
             typename TreeNode::iterator it;
             typename TreeNode::iterator itEnd = node->end();
             for (it = node->begin(); it != itEnd; ++it)
             {
                 node->child(it->location).insert(std::move(*it));
             }
             node->clear();
             node = &(node->child(toStore.location));
         }
     }
     return iterator(node, node->insert(std::move(toStore)));
 }
开发者ID:mgoral,项目名称:geocontainers,代码行数:24,代码来源:QuadTree.hpp

示例7: test_child

void TreeNodeTest::test_child()
{
  /*

   The tree we will work with:

   Root
    |----> Node1
    |       |----> Node11
    |       |----> Node12
    |
    |----> Node2
    |       |----> Node21
    |       |----> Node22
    |       |----> Node23
    |
    |----> Node3


  */

  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);

  //
  // 1. check the direct children
  //
  treeNode1 = treeNode->child(0);
  treeNode2 = treeNode->child(1);
  treeNode3 = treeNode->child(2);

  // 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 name
  QCOMPARE( treeNode1->nodeName(), QString("Node1") );
  QCOMPARE( treeNode2->nodeName(), QString("Node2") );
  QCOMPARE( treeNode3->nodeName(), QString("Node3") );

  //
  // 2. children of Node1
  //
  treeNode11 = treeNode1->child(0);
  treeNode12 = treeNode1->child(1);

  // 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 name
  QCOMPARE( treeNode11->nodeName(), QString("Node11") );
  QCOMPARE( treeNode12->nodeName(), QString("Node12") );

  //
  // 3. children of Node2
  //
  treeNode21 = treeNode2->child(0);
  treeNode22 = treeNode2->child(1);
  treeNode23 = treeNode2->child(2);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

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