/*************************************************************************** * 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 "Analyse.h" #include "MemBlock.h" #include "MsgNodeBase.h" using namespace std; void test(); void show(CAnalyseWrite *paw); void recursion_show(CInputNodeBase* pRootGroup); void set_values(CAnalyseWrite *paw); void recursion_set_values(CInputNodeBase* pRootGroup); void outTbls(int num); int main(int argc, char *argv[]) { test(); return EXIT_SUCCESS; } void test() { CMsgTreeBuilder msgTree; msgTree.BuildTree(); CMsgNodeBase *pItem=msgTree.FindeNodeByID(16843008); MemBlock *mem_block=NULL; //Write CAnalyseWrite aw; aw.SetMsgNode(pItem); set_values(&aw);//user input show(&aw); //show the input CInputNodeBase*pErr=aw.Check(); if(pErr) { cout<<"Error node:"<<pErr->GetName()<<endl; } if(!aw.WriteToMem(mem_block))//Auto malloc {cout<<"Write error!"<<endl;}; //Read CAnalyseRead ar; ar.ReadBuf(mem_block); //out info to screen string strbuf; ar.ToString(strbuf); cout<<strbuf<<endl; //Save to disk ar.ToXml("ReadData.xml"); cout<<"数据已成功存入 ReadData.xml"<<endl; ///////////*//////////// } void show(CAnalyseWrite *paw) { CInputNodeBase*pRootGroup=paw->GetInputGroupNode(); recursion_show(pRootGroup); } void recursion_show(CInputNodeBase* pRootGroup) { static int recursionDepth=-1; recursionDepth++; int tbnum; ////////////////// int i=0; int data=0; int total=pRootGroup->ToGroupNode()->GetUsedNum(); for(i=0;i<total;i++) { CInputNodeBase* pNode=pRootGroup->GetFirstChild(i+1); while(pNode) { outTbls(recursionDepth); if(pNode->GetNodeType()==GROUPNODE) { cout<<"Group:"<<pNode->GetShowString()<<endl; recursion_show(pNode); } else { cout<<"Elemt:"<<pNode->GetShowString()<<endl; } pNode=pRootGroup->GetNextChild(i+1); } } ///////*////////////// recursionDepth--; } void set_values(CAnalyseWrite *paw) { CInputNodeBase*pRootGroup=paw->GetInputGroupNode(); recursion_set_values(pRootGroup); } void recursion_set_values(CInputNodeBase* pRootGroup) { static int recursionDepth=-1; recursionDepth++; int tbnum; ////////////////// char chSet; double dSet; float fSet; int iSet; time_t tSet; unsigned int uiSet; string strSet; char tem[50]; int i=0; int data=0; int total=pRootGroup->ToGroupNode()->GetUsedNum(); for(i=0;i<total;i++) { CInputNodeBase* pNode=pRootGroup->GetFirstChild(i+1); while(pNode) { outTbls(recursionDepth); switch(pNode->GetNodeType()) { case UNKNOWNNODE: cout<<"Unknow node type skiped..."<<endl; break; case CHARNODE: cout<<"Char node Input "<<pNode->GetName()<<":"; cin>>chSet; strSet=chSet; pNode->SetContent(strSet); break; case DOUBLENODE: cout<<"Double node Input "<<pNode->GetName()<<":"; cin>>dSet; sprintf(tem,"%f",dSet); strSet=tem; pNode->SetContent(strSet); break; case FLOATNODE: cout<<"Float node Input "<<pNode->GetName()<<":"; cin>>fSet; sprintf(tem,"%f",fSet); strSet=tem; pNode->SetContent(strSet); break; case SIGNEDNODE: cout<<"Signed int node Input "<<pNode->GetName()<<":"; cin>>iSet; sprintf(tem,"%d",iSet); strSet=tem; pNode->SetContent(strSet); break; case TIMENODE: cout<<"Time node Input (long infact) "<<pNode->GetName()<<":"; cin>>tSet; sprintf(tem,"%d",tSet); strSet=tem; pNode->SetContent(strSet); break; case UNSIGNEDNODE: cout<<"Unsigned int node Input "<<pNode->GetName()<<":"; cin>>uiSet; sprintf(tem,"%u",uiSet); strSet=tem; pNode->SetContent(strSet); break; case STRINGNODE: cout<<"String node Input "<<pNode->GetName()<<":"; cin>>strSet; pNode->SetContent(strSet); break; case GROUPNODE: cout<<"Group node Input length for "<<pNode->GetName()<<":"; cin>>iSet; pNode->ToGroupNode()->SetUsedNum(iSet); recursion_set_values(pNode); break; } pNode=pRootGroup->GetNextChild(i+1); } } ///////*////////////// recursionDepth--; } void outTbls(int num) { for(int i=0;i<num;i++) cout<<"/t"; }