⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: Tree.h															*
 * Creation: TD 12-19-02														*
 * Purpose: Origin C support for a general Tree/TreeNode						*
 * Copyright (c) OriginLab Corp.2003											*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:07/25/03_PRITHVI_ADDED_DOCUMENTATION_FOR_METHODS_IN_		*
 *					TREENODE_CLASS												*
 *------------------------------------------------------------------------------*/

 
#ifndef _TREE_H
#define _TREE_H


#include <common.h>
#include <Collection.h>

/** >Composite Data Types
*/
class PropertyNode
{
public:
	PropertyNode();
	PropertyNode(PropertyNode &tn);
	
	int    				nVal;	
	double 				dVal;
	string				strVal;
	// vector data
	vector<double>		dVals;
	vector<float>		fVals;
	vector<int>			nVals;
	vector<short>		sVals;
	vector<char>		bVals;
	vector<string>      strVals;

	matrix<double>		dVals2;
	matrix<float>		fVals2;
	matrix<int>			nVals2;
	matrix<short>		sVals2;
	matrix<char>		bVals2;

};

/** >Composite Data Types
*/
class TreeNode :public PropertyNode
{
public:
	
	/** 
	
			Default contructor.
		Example:
			void test()
			{	Tree myTree;
				TreeNode tn1;
				tn1 = myTree.AddTextNode("abc", "node2", 2);
				out_tree(myTree);
			}
	*/		
	
	TreeNode(); //Default contructor

	/** 
	
			Contructor.
		Example:
			void test()
			{	Tree myTree1;
				TreeNode tn1;
				tn1 = myTree1.AddTextNode("abc", "node1", 1);
				
				Tree myTree2;
				TreeNode tn2(tn1);
				bool flag = myTree2.AddNode(tn2, FALSE);
				out_tree(myTree1);
				out_tree(myTree2);
			}
	*/		

	TreeNode(TreeNode &tn);//Contructor
	
	string 				Text;		
	int    				nVal;	
	double 				dVal;
	string				strVal;
	int					ID;
	int					Show;
	int					Enable; // -1 if attribute not in node
	
	string				tagName;		//read only

	// iterators -- syntax similar to C#
	TreeNode			FirstNode;		//read only
	TreeNode			NextNode;		//read only
	TreeNode			PrevNode;		//read only
	TreeNode			LastNode;		//read only

	/** 
	
			Gets a node from a tree when the name of the node is given.
		Parameters:
			Name = name of the node
		Returns:
			The node whose name matches the given name.
		Example:
			#include <Tree.h>
			void test()
			{	Tree myTree;
				TreeNode tn1, tn2, tn3;
				tn2 = myTree.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("efg", "node3", 3);//tn2 is adding tn3 as its child
				tn1 = tn2.GetNode("node3");//now tn1 has tn3 as its child  
			}
	*/		
	TreeNode			GetNode(LPCSTR Name); // Find child by name
	
	/** 
	
			Gets the parent of a node in a tree.
		Returns: 
			 Parent node of the child node which calls this method.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1, tn2, tn3;
				tn2 = myTree.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("efg", "node3", 3);//tn2 is adding tn3 as its child
				tn1 = tn3.Parent();//now tn1 has the parent of tn3  		
			}
	
	*/			
	TreeNode			Parent(); // Find parent -- Null if parent is not an element node
	
	
	/** 
	
			Creates a clone of a node i.e., creates an exact copy of a node and its contents. 
			If bDeep is true, copies the whole branch.
		Parameters:
			bDeep = TRUE or FALSE
		Returns: 
			 The cloned node
		Example:
			void test()
			{
				Tree myTree1, myTree2;
				TreeNode tn1, tn2, tn3;
				tn2 = myTree2.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("efg", "node3", 3);//tn2 added tn3 as its child
				
				tn1 = tn2.Clone(TRUE);//TRUE, copies the tn2 as well as its sub-branch 	
				bool flag = myTree2.AddNode(tn1);
				out_tree(myTree1);
				out_tree(myTree2);
			}
	*/			
	TreeNode			Clone(BOOL bDeep = TRUE); // Clones a Node, if bDeep is true, copies the whole branch

	
	/** 
	
			Removes all the attributes and the children of a node or a tree.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;
				tn1 = myTree.AddTextNode("abc", "node1", 1);
				out_tree(myTree);
				myTree.Reset();
				out_tree(myTree);
			}
	
	*/	
	void	Reset();	
	
	/** 
	
			Adds a reference to an existing node (in the same tree or another tree).
		Parameters:
			tn = the new node to be added to the tree
			bDeep = TRUE or FALSE; 
		Returns: 
			 TRUE if the node is successfully added; FALSE otherwise
		Example:
			void test()
			{	Tree myTree1;
				TreeNode tn1;
				tn1 = myTree1.AddTextNode("abc", "node1", 1);
				out_tree(myTree1);
				
				Tree myTree2;
				TreeNode tn2(tn1); // adds a node from myTree1	
				bool flag = myTree2.AddNode(tn2, FALSE);	
				out_tree(myTree2);
			}
	*/				
	BOOL				AddNode(TreeNode &tn, BOOL bDeep = TRUE);

	/** 
	
			Replaces a node in the tree.
		Parameters:
			tn = the new node to be added to the tree
			bDeep = TRUE or FALSE; 
		Returns: 
			 TRUE if the node is successfully replaced; FALSE otherwise
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1, tn2, tn3;
				tn1 = myTree.AddNumericNode(123, "node1", 1);			
				tn2 = myTree.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("abc", "node3", 2);
				out_tree(myTree);
				
				bool flag1 = tn3.Replace(tn1, TRUE);
				if(flag1) printf("node3 successfully replaced \n");
				out_tree(myTree);
				
			}
			
	*/			

	BOOL				Replace(TreeNode &tn, BOOL bDeep = TRUE);
	
	/** 
	
			Gives the number of nodes in the tree.
		Parameters:
		Returns: 
			 number of nodes in the tree
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1, tn2, tn3;
				tn1 = myTree.AddNumericNode(123, "node1", 1);			
				tn2 = myTree.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("abc", "node3", 2);
				printf("number of nodes in myTree = %d", myTree.GetNodeCount());
			}
	*/				
	int					GetNodeCount();
	
	/** 
			Creates a new node with the specified name & id and returns that node.
		Parameters:
			name  = the name of the new node to be added to the tree
			nChildID = the id of the new node to be added to the tree
		Returns: 
			 A new node bearing the name and the id.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1, tn2, tn3;
				tn1 = myTree.AddNode("node1", 1);
				tn2 = myTree.AddTextNode("abc", "node2", 2);
				tn3 = tn2.AddTextNode("efg", "node3", 3);
			}
	
	*/
	
	TreeNode			AddNode(LPCSTR Name = NULL, int nChildID = -1); //NodeID will not be created if < 0
	
	/** 
			Creates a new node with the specified name,id and the double value and returns that node. 
		Parameters:
			dVal  = double contents of the node
			name  = the name of the new node to be added to the tree
			nChildID = the id of the new node to be added to the tree; NodeID  will not be created if < 0
		Returns: 
			 A new node bearing the name and the id.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;	
				tn1 = myTree.AddNumericNode(5.432, "node1", 1);
				out_tree(myTree);
			}
	*/	
	
	TreeNode			AddNumericNode(double  dVal, LPCSTR Name = NULL, int nChildID = -1);
	
	
	/** 
			Creates a new node with the specified name,id and the integer value and returns that node. 
		Parameters:
			nVal  = integer contents of the node
			name  = the name of the new node to be added to the tree
			nChildID = the id of the new node to be added to the tree; node will not be created if < 0
		Returns: 
			 A new node bearing the name and the id.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;	
				tn1 = myTree.AddNumericNode(5, "node1", 1);
				out_tree(myTree);
			}
	*/		
	TreeNode			AddNumericNode(int nVal, LPCSTR Name = NULL, int nChildID = -1);
	
	
	/** 
			Creates a new node with the specified name,id and the string value and returns that node. 
		Parameters:
			strVal  = string contents of the node
			name  = the name of the new node to be added to the tree
			nChildID = the id of the new node to be added to the tree; node will not be created if < 0
		Returns: 
			 A new node bearing the name and the id.
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;	
				tn1 = myTree.AddTextNode("abcd", "node1", 1);
				out_tree(myTree);
			}
	*/			
	TreeNode			AddTextNode(LPCSTR strVal, LPCSTR Name = NULL, int nChildID = -1);
	
	/** 
			Gets the integer attribute of a node with the specified name. 
		Parameters:
			lpcszAttrName  = name of the node
			nVal  = contains the integer attribute of the node after the function call is finished
		Returns: 
			 True if the node is found; FALSE otherwise
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;
				tn1 = myTree.AddTextNode("abc", "node1", 2);
				int nVal;
	            bool flag1 = tn1.SetAttribute("node2", 5); //creates a new attribute named node2 and gives it an
	            										   //integer value 5 	
				bool flag2 = tn1.GetAttribute("node2", nVal);
				printf("the integer value of the attribute node2 is %d", nVal);
			}
	*/			

	BOOL				GetAttribute(LPCSTR lpcszAttrName, 	int &nVal);
	
	/** 
			Gets the double attribute of a node with the specified name. 
		Parameters:
			lpcszAttrName  = name of the node
			nVal  = After the method call, nVal contains the double attribute of the node.
		Returns: 
			 True if the node is found; FALSE otherwise
		Example:
			void test()
			{
				Tree myTree;
				TreeNode tn1;
				tn1 = myTree.AddTextNode("abc", "node1", 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				GetAttribute(LPCSTR lpcszAttrName, 	double  &dVal);
	
	/** 
			Gets the string attribute of a node with the specified name. 
		Parameters:
			lpcszAttrName  = name of the node
			strVal  = After the method call, strVal contains the string attribute of the node.
		Returns: 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -