to advance xml::ElementParseCreater

This commit is contained in:
2020-08-31 19:09:12 +08:00
parent 44f897d608
commit 20fcbc2a02
2 changed files with 31 additions and 10 deletions

View File

@@ -47,20 +47,24 @@ namespace hgl
class ElementParseCreater:public ElementParse class ElementParseCreater:public ElementParse
{ {
Stack<ElementCreater *> ecs_stack; Stack<ElementCreater *> ecs_stack;
Map<AnsiString,ElementCreater *> ecs_map;
ElementCreater *root_ec;
ElementCreater *cur_ec; ElementCreater *cur_ec;
public: public:
ElementParseCreater(ElementCreater *rec) ElementParseCreater(ElementCreater *root_ec)
{ {
root_ec=rec; cur_ec=nullptr;
cur_ec=rec;
Registry(root_ec);
} }
virtual ~ElementParseCreater()=default; virtual ~ElementParseCreater()=default;
bool Registry (ElementCreater *ec);
public: public:
bool Start (const u8char *element_name) override; bool Start (const u8char *element_name) override;

View File

@@ -4,17 +4,34 @@ namespace hgl
{ {
namespace xml namespace xml
{ {
bool ElementParseCreater::Registry(ElementCreater *ec)
{
if(!ec)return(false);
return ecs_map.Add(ec->GetElementName(),ec);
}
bool ElementParseCreater::Start (const u8char *element_name) bool ElementParseCreater::Start (const u8char *element_name)
{ {
if(!element_name||!*element_name)return(false); if(!element_name||!*element_name)return(false);
if(!cur_ec) ElementCreater *ec=nullptr;
return(false);
ElementCreater *ec=cur_ec->GetSubElementCreater(element_name); if(ecs_stack.GetCount()==0) //根
ecs_stack.Push(cur_ec); {
if(!ecs_map.Get(element_name,ec))
cur_ec=nullptr; return(false);
}
else
{
if(!cur_ec)
return(false);
ec=cur_ec->GetSubElementCreater(element_name);
ecs_stack.Push(cur_ec);
}
cur_ec=nullptr;
if(ec) if(ec)
{ {