/*************************************************************************** * Copyright (C) 2009 by root * * root@localhost.localdomain * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include <cstdlib> #include "NodeBase.h" #include "TreeBuilder.h" using namespace std; #include <string.h> void show(); void build(); void outNode(CNodeBase*p,int tbls); int main(int argc, char *argv[]) { build(); show(); cout<<"ends"<<endl; return EXIT_SUCCESS; } void show() { TreeBuilder tree; CNodeBase* pRoot=tree.BuildTree(); int tbls=-1; //if(pRoot) // outNode(pRoot,tbls); CNodeBase* pDomain=pRoot->FirstChild(); tbls++; while(pDomain) { outNode(pDomain,tbls); CNodeBase* pClass=pDomain->FirstChild(); tbls++; while(pClass) { outNode(pClass,tbls); CNodeBase*pItem=pClass->FirstChild(); tbls++; while(pItem) { outNode(pItem,tbls); CNodeBase*pStyle=pItem->FirstChild(); tbls++; while(pStyle) { outNode(pStyle,tbls); pStyle=pItem->NextChild(); }tbls--; pItem=pClass->NextChild(); }tbls--; pClass=pDomain->NextChild(); }tbls--; pDomain=pRoot->NextChild(); }tbls--; } void build() { TreeBuilder tree; CNodeBase* root=tree.BuildTree(); CDomainUnitNode*pDomainUnit=tree.GetUnitNode(); CNodeBase* pUnitClass1=pDomainUnit->CreateChild("class_国际单位"); CNodeBase*pUnitItem1=pUnitClass1->ToClassNode()->CreateUnitItem("item_长度"); CNodeBase*pUnitData1=pUnitItem1->CreateChild("data_厘米"); CNodeBase*pUnitData2=pUnitItem1->CreateChild("data_分米"); CNodeBase*pUnitData3=pUnitItem1->CreateChild("data_米"); CNodeBase* pDomainGroup=tree.GetGroupNode(); CNodeBase* pDataGroup=pDomainGroup->CreateChild("组1"); { pDataGroup->ToDataGroupNode()->SetDataLength(32); } CNodeBase* pDataGroup2=pDomainGroup->CreateChild("组2"); { pDataGroup2->ToDataGroupNode()->SetDataLength(64); } CNodeBase* pDataGroup3=pDomainGroup->CreateChild("组3"); { pDataGroup3->ToDataGroupNode()->SetDataLength(16); } CNodeBase*pDomain=root->CreateChild("部队部署与行动类"); CNodeBase*pClass=pDomain->CreateChild("部队部署报"); CNodeBase*pRegularItem=pClass->ToClassNode()->CreatRegularDataItem("普通样式"); CNodeBase*pStyle=pRegularItem->CreateChild("样式1"); CNodeBase*pStyle2=pRegularItem->CreateChild("样式2"); pStyle2->ToDataStyleNode()->SetTypeName("float"); pStyle2->ToDataStyleNode()->SetUnitID(16843009); pStyle2->ToDataStyleNode()->SetDataLength(32); CNodeBase*pStyle3=pRegularItem->CreateChild("样式3"); CNodeBase*pStyle4=pRegularItem->CreateChild("样式4"); pStyle4->ToDataStyleNode()->SetTypeName("string"); pStyle4->ToDataStyleNode()->SetUnitID(16843011); CNodeBase*pEnumItem=pClass->ToClassNode()->CreateEnumDataItem("枚举样式"); tree.SaveFile(); } void outNode(CNodeBase*p,int tbls) { int i; for(i=0;i<tbls;i++) {cout<<"/t";} cout<<"Name:"<<p->GetName()<<" "<<endl; }