From 3f09d59cebd3c359f7721befd8a0ff3151e80fc2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 4 Sep 2020 18:07:00 +0800 Subject: [PATCH] split Start&Init from Start in XMLParse --- inc/hgl/util/xml/ElementParse.h | 3 ++- inc/hgl/util/xml/ElementParseCreater.h | 21 +++++++++++---------- src/xml/ElementParseCreater.cpp | 11 +++++++++-- src/xml/XMLParseClass.cpp | 4 +++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/inc/hgl/util/xml/ElementParse.h b/inc/hgl/util/xml/ElementParse.h index 8d9d047..05e6ed0 100644 --- a/inc/hgl/util/xml/ElementParse.h +++ b/inc/hgl/util/xml/ElementParse.h @@ -15,8 +15,9 @@ namespace hgl virtual ~ElementParse()=default; - virtual bool Start (const u8char *element_name) {return(true);} + virtual bool Init (const u8char *element_name) {return(true);} virtual void Attr (const u8char *flag,const u8char *info) {} + virtual bool Start () {return(true);} virtual void CharData (const u8char *str,const int str_length){} virtual void End (const u8char *element_name) {} };//class ElementParse diff --git a/inc/hgl/util/xml/ElementParseCreater.h b/inc/hgl/util/xml/ElementParseCreater.h index eb9777e..1f5829e 100644 --- a/inc/hgl/util/xml/ElementParseCreater.h +++ b/inc/hgl/util/xml/ElementParseCreater.h @@ -34,13 +34,13 @@ namespace hgl public: - virtual bool Start (){return true;} - virtual void Attr (const u8char *flag,const u8char *info){} - virtual void CharData (const u8char *str,const int str_length){} - - virtual void End (){} + virtual bool Init (){return true;} ///<初始化节点 + virtual void Attr (const u8char *flag,const u8char *info){} ///<节点属性 + virtual bool Start (){return true;} ///<开始内部数据解晰 + virtual void CharData (const u8char *str,const int str_length){} ///<文本数据 + virtual void End (){} ///<节点结束 };//class ElementCreater - + /** * Creater模式XML节点解析器 */ @@ -67,10 +67,11 @@ namespace hgl public: - bool Start (const u8char *element_name) override; - void Attr (const u8char *flag,const u8char *info) override; - void CharData (const u8char *str,const int str_length) override; - void End (const u8char *element_name) override; + virtual bool Init (const u8char *element_name) override; + virtual void Attr (const u8char *flag,const u8char *info) override; + virtual bool Start () override; + virtual void CharData (const u8char *str,const int str_length) override; + virtual void End (const u8char *element_name) override; };//class ElementParseCreater:public ElementParse }//namespace xml }//namespace hgl diff --git a/src/xml/ElementParseCreater.cpp b/src/xml/ElementParseCreater.cpp index 013d273..4acfa50 100644 --- a/src/xml/ElementParseCreater.cpp +++ b/src/xml/ElementParseCreater.cpp @@ -11,7 +11,7 @@ namespace hgl return ecs_map.Add(ec->GetElementName(),ec); } - bool ElementParseCreater::Start (const u8char *element_name) + bool ElementParseCreater::Init(const u8char *element_name) { if(!element_name||!*element_name)return(false); @@ -39,7 +39,7 @@ namespace hgl if(ec) { - if(ec->Start()) + if(ec->Init()) cur_ec=ec; else delete ec; @@ -55,6 +55,13 @@ namespace hgl cur_ec->Attr(flag,info); } + bool ElementParseCreater::Start() + { + if(!cur_ec)return(false); + + return cur_ec->Start(); + } + void ElementParseCreater::CharData(const u8char *str,const int str_length) { if(!cur_ec)return; diff --git a/src/xml/XMLParseClass.cpp b/src/xml/XMLParseClass.cpp index 6b6257c..cb3cc2d 100644 --- a/src/xml/XMLParseClass.cpp +++ b/src/xml/XMLParseClass.cpp @@ -13,7 +13,7 @@ namespace hgl { void XMLStartElement(ElementParse *ep,const XML_Char *name,const XML_Char **atts) { - if(!ep->Start((const u8char *)name)) + if(!ep->Init((const u8char *)name)) return; const u8char *flag; @@ -26,6 +26,8 @@ namespace hgl ep->Attr(flag,info); } + + ep->Start(); } void XMLCharData(ElementParse *ep,const XML_Char *str,int len)