/usr/include/crystalspace-2.0/csutil/tree.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | /*
Copyright (C) 2000 by Norman Kraemer
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_CSTREENODE_H__
#define __CS_CSTREENODE_H__
/**\file
* Generic tree class
*/
#include "csextern.h"
#include "array.h"
/**
* A generic tree class.
*/
class csTreeNode
{
public:
/// Returns true if this node has no children.
bool IsLeaf ()
{ return children.GetSize () == 0; }
/// Remove a child node.
void RemoveChild (csTreeNode *child)
{
size_t idx = children.Find (child);
if (idx != csArrayItemNotFound) children.DeleteIndex (idx);
}
/// Add a child node.
void AddChild (csTreeNode *child)
{ children.Push (child); child->parent = this; }
/// Create node, optionally as a child of <code>theParent</code>.
csTreeNode (csTreeNode *theParent=0)
{ parent=theParent; if (parent) parent->children.Push (this); }
virtual ~csTreeNode ()
{
size_t i;
for(i=children.GetSize (); i>0; i--)
delete children.Get (i - 1);
if (parent)
parent->RemoveChild (this);
}
/**
* Execute a function on this node and its children. Do this in
* "DepthSearchFirst" order, that is check a childs children
* before testing the next direct child.
* Returns the last node where TreeFunc resulted in TRUE.
* If stopOnSuccess is true, then execution is stoped after first
* successful execution of TreeFunc.
* SelBranch lets you decide which children to select for further
* investigation. 0 means all children.
*/
csTreeNode *DSF (bool (*TreeFunc)(csTreeNode *node, void* param,
bool stopOnSuccess),
bool (*SelBranch)(csTreeNode *node), void* param,
bool stopOnSuccess)
{
csTreeNode *foundNode = 0;
size_t i=0;
bool dive;
if (TreeFunc (this, param, stopOnSuccess))
foundNode = this;
while (i<children.GetSize () && !(foundNode && stopOnSuccess))
{
dive = (SelBranch == 0) || SelBranch (children[i]);
if (dive)
foundNode = (children[i])->DSF (TreeFunc, SelBranch,
param, stopOnSuccess);
i++;
}
return foundNode;
}
/**
* Execute a function on this node and its children. Do this in
* "BreadthSearchFirst" order, that is check first all
* direct children before diving into subchildren.
* Returns the last node where TreeFunc resulted in TRUE.
* If stopOnSuccess is true, then execution is stoped after first
* successful execution of TreeFunc.
* SelBranch lets you decide which children to select for further
* investugation. 0 means all children.
*/
csTreeNode *BSF (bool (*TreeFunc)(csTreeNode *node, void* param,
bool stopOnSuccess),
bool (*SelBranch)(csTreeNode *node), void* param,
bool stopOnSuccess)
{
csTreeNode *node, *foundNode = 0;
csArray<csTreeNode*> fifo;
fifo.Push (this);
while (fifo.GetSize () > 0 && !(foundNode && stopOnSuccess))
{
node = fifo[0]; fifo.DeleteIndex (0);
if (TreeFunc (node, param, stopOnSuccess))
foundNode = node;
if (!node->IsLeaf () && (SelBranch==0 || SelBranch (node)))
{
size_t i;
for (i=0; i < node->children.GetSize (); i++ )
fifo.Push (node->children[i]);
}
}
fifo.DeleteAll ();
return foundNode;
}
public:
csTreeNode *parent; // parent node or 0 if toplevel
csArray<csTreeNode*> children; // node children
};
#endif // __CS_CSTREENODE_H__
|