📄 tree.h
字号:
True if the node is found; FALSE otherwise
Example:
#include <Tree.h>
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
string strVal;
bool flag1 = tn1.SetAttribute("node2", "xyz");//creating a new attribute named node2 and giving it a
//string value "xyz"
bool flag2 = tn1.GetAttribute("node2", strVal);
printf("the string value of the attribute node2 is %d", strVal);
}
*/
BOOL GetAttribute(LPCSTR lpcszAttrName, string &strVal);
/**
Sets the integer value of a node.
Parameters:
lpcszAttrName = name of the node
dVal = contains the integer value to be set into the node.
Returns:
True if the node is found; FALSE otherwise
Example:
#include <Tree.h>
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
int nVal;
bool flag1 = tn1.SetAttribute("node2", 5); //creating a new attribute named node2 and giving it an
//integer value 5
bool flag2 = tn1.GetAttribute("node2", nVal);
printf("the integer value of the attribute node2 is %d", nVal);
}
*/
BOOL SetAttribute(LPCSTR lpcszAttrName, int nVal);
/**
Sets the double value of a node.
Parameters:
lpcszAttrName = name of the node
dVal = contains the double value to be set into the node.
Returns:
True if the node is found; FALSE otherwise
Example:
#include <Tree.h>
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node2", 2);
double dVal;
bool flag1 = tn1.SetAttribute("node2", 5.345);//creating a new attribute named node2 and giving it a
//double value 5.345
bool flag2 = tn1.GetAttribute("node2", dVal);
printf("the double value of the attribute node2 is %d", dVal);
}
*/
BOOL SetAttribute(LPCSTR lpcszAttrName, double dVal);
/**
Sets the string attribute of the node.
Parameters:
lpcszAttrName = name of the node
strVal = contains the string value to be set into the node.
Returns:
True if the node is found; FALSE otherwise
Example:
#include <Tree.h>
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
string strVal;
bool flag1 = tn1.SetAttribute("node2", "xyz");//creating a new attribute named node2 and giving it a
//string value "xyz"
bool flag2 = tn1.GetAttribute("node2", strVal);
printf("the string value of the attribute node2 is %d", strVal);
}
*/
BOOL SetAttribute(LPCSTR lpcszAttrName, LPCSTR strVal);
/**
Removes the attribute of a node.
Parameters:
lpcszAttrName = name of attribute
Returns:
TRUE if attribute existed and was deleted successfully, FALSE if attribute does not exist.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
string strVal;
bool flag1 = tn1.SetAttribute("node2", "xyz");//creating a new attribute named node2 and giving it a
//string value "xyz"
bool flag2 = tn1.RemoveAttribute("node2");
bool flag3 = tn1.GetAttribute("node2", strVal);
}
*/
BOOL RemoveAttribute(LPCSTR lpcszAttrName);
/**
Removes the node with the specified id.
Parameters:
nChildID = id of the node to be removed
Returns:
TRUE if the node existed and was removed successfully; FALSE otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddNumericNode(5, "node1", 1);
printf("number of nodes = %d", myTree.GetNodeCount());
bool flag = myTree.RemoveChild(1);
printf("number of nodes = %d", myTree.GetNodeCount());
}
*/
BOOL RemoveChild(int nChildID);
/**
Removes the node with the specified name.
Parameters:
name = name of the node to be removed
Returns:
TRUE if the node existed and was removed successfully; FALSE otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddNumericNode(5, "node1", 1);
printf("number of nodes = %d", myTree.GetNodeCount());
bool flag = myTree.RemoveChild("node1");
printf("number of nodes = %d", myTree.GetNodeCount());
}
*/
BOOL RemoveChild(LPCSTR Name);
/**
Removes the node specified by the object.
Parameters:
tn = the node object that has to be removed
Returns:
TRUE if the node existed and was removed successfully; FALSE otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddNumericNode(5, "node1", 1);
printf("number of nodes = %d", myTree.GetNodeCount());
bool flag = myTree.RemoveChild(tn1);
printf("number of nodes = %d", myTree.GetNodeCount());
}
*/
BOOL RemoveChild(TreeNode &tn);
/**
Removes the node with the specified prefix.
Parameters:
lpcszPrefix = the prefix of name of the node(s).
Returns:
1 if the node existed and was removed successfully; 0 otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1, tn2;
tn1 = myTree.AddNumericNode(5, "node1", 1);
tn2 = myTree.AddNumericNode(5, "node2", 1);
printf("number of nodes = %d \n", myTree.GetNodeCount());
int flag = myTree.RemoveChildrenWithPrefix("no");
printf("number of nodes = %d \n", myTree.GetNodeCount());//should print 0
}
*/
int RemoveChildrenWithPrefix(LPCSTR lpcszPrefix);
/**
Removes the node that calls this method.
Parameters:
Returns:
TRUE if the node was removed successfully; FALSE otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
bool flag1 = tn1.Remove();
printf("the number of nodes in myTree = %d", myTree.GetNodeCount());
}
*/
BOOL Remove();
/**
Checks if a given node is a valid node or not
Parameters:
Returns:
TRUE if the node is valid; FALSE otherwise.
Example:
void test()
{
Tree myTree;
TreeNode tn1;
tn1 = myTree.AddTextNode("abc", "node1", 2);
bool flag2 = tn1.IsValid();
}
*/
BOOL IsValid();
Collection<TreeNode> Children;
/**
Example:
void run_XML()
{
Tree tr;
TreeNode trNode;
trNode = tr.AddNode("Node1", 1);
string strXML = tr.XML;
out_str(strXML);
}
*/
string XML; // init treenode from XML string or to get as XML string
};
/** >Composite Data Types
*/
class Tree : public TreeNode
{
public:
/**
Constructor which initializes a tree from an XML file.
Parameters:
File = file name
nType = 0
Returns:
Example:
void test()
{
Tree myTree("xyz.xml", 0);
}
*/
Tree(LPCSTR File, int nType = 0);
/**
Constructor.
Parameters:
nType = 0
Returns:
Example:
void test()
{
Tree myTree(0);
}
*/
Tree(int nType = 0);
/**
Gets a tree from an XML file.
Parameters:
File = file name
nType = 0
Returns: TRUE if the tree can be created; FALSE otherwise
Example:
void test()
{
Tree myTree;
myTree.Load("xyz.xml", 0);
}
*/
BOOL Load(LPCSTR File, int nType = 0);
/**
Saves a tree to an XML file.
Parameters:
File = file name
nType = 0
Returns: TRUE if the tree can be created; FALSE otherwise
Example:
void test()
{
Tree myTree(0);
TreeNode tn1, tn2, tn3;
tn1 = myTree.AddNode("node1", 1);
tn2 = tn1.AddTextNode("abc", "node2", 2);
tn3 = tn2.AddTextNode("efg", "node3", 3);
myTree.Save("c:\\xyz.xml");
}
*/
BOOL Save(LPCSTR lpcszFile);
};
/** >Composite Data Types
Example:
Tree tree;
if(tree)
{
tree.AddNode();
tree.AddNumericNode(1);
tree.AddNumericNode(2);
tree.AddNumericNode(3, "I333");
tree.AddNumericNode(4);
TreeNodeCollection tnc(tree, "int");
foreach(TreeNode tn in tnc)
{
string str = tn.tagName;
out_str(str);
}
}
*/
class TreeNodeCollection : public Collection<TreeNode>
{
public:
/**
To get a collection of tree nodes from parent tree node by name profix.
Parameters:
node = the parent tree node
lpcsz = the name prefix of the tree node
Example:
Tree tree;
if(tree)
{
tree.AddNode();
tree.AddNumericNode(1);
tree.AddNumericNode(2);
tree.AddNumericNode(3, "I333");
tree.AddNumericNode(4);
TreeNodeCollection tnc(tree, "int");
foreach(TreeNode tn in tnc)
{
string str = tn.tagName;
out_str(str);
}
}
*/
TreeNodeCollection(TreeNode node, LPCSTR lpcsz);
};
#endif //_TREE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -