From 661b7a080aa0c7ece423b2d7f3ee889aa4f1d409 Mon Sep 17 00:00:00 2001 From: Ebersold Date: Fri, 10 Feb 2023 22:53:39 +0100 Subject: [PATCH] Continue on reqif parser --- src/xml/CMakeLists.txt | 2 +- src/xml/element.h | 84 ++ src/xml/{reqif => }/element_factory.cpp | 0 src/xml/{reqif => }/element_factory.h | 0 src/xml/reqif/CMakeLists.txt | 47 +- src/xml/reqif/parser_base.h | 68 ++ src/xml/reqif/parsers.h.inc | 94 ++ src/xml/reqif/reqif_element.h | 194 +++++ src/xml/reqif/reqif_elements_parser.cpp | 865 +++++++++++++++++++ src/xml/reqif/reqif_elements_parser.h | 323 +++++++ src/xml/reqif/reqif_elements_parser_root.cpp | 306 +++++++ 11 files changed, 1941 insertions(+), 42 deletions(-) create mode 100644 src/xml/element.h rename src/xml/{reqif => }/element_factory.cpp (100%) rename src/xml/{reqif => }/element_factory.h (100%) create mode 100644 src/xml/reqif/parser_base.h create mode 100644 src/xml/reqif/parsers.h.inc create mode 100644 src/xml/reqif/reqif_element.h create mode 100644 src/xml/reqif/reqif_elements_parser.cpp create mode 100644 src/xml/reqif/reqif_elements_parser.h create mode 100644 src/xml/reqif/reqif_elements_parser_root.cpp diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt index 8b376fa..abbe98b 100644 --- a/src/xml/CMakeLists.txt +++ b/src/xml/CMakeLists.txt @@ -1,5 +1,5 @@ PROJECT(antxml) cmake_minimum_required(VERSION 2.8) -SUBDIRS(parser) +SUBDIRS(parser reqif) diff --git a/src/xml/element.h b/src/xml/element.h new file mode 100644 index 0000000..8c68a45 --- /dev/null +++ b/src/xml/element.h @@ -0,0 +1,84 @@ +#ifndef XSD_ELEMENT_H__ +#define XSD_ELEMENT_H__ + +#include +#include +#include +#include +#include +#include +#ifdef ANTCC_WITH_BOOST +#include +#elif defined (ANTCC_WITH_AEB) +#include +#endif + + +namespace xml { + + template + struct element_traits { + typedef T element_type; +#ifdef XSD_WITH_BOOST + typedef typename boost::shared_ptr element_sptr; +#elif defined(XSD_WITH_AEB) + typedef typename aeb::shared_ptr element_sptr; +#else + typedef typename std::shared_ptr element_sptr; +#endif + typedef typename std::vector element_sequence; + }; + /// Usefulle template to create a static + // array of all avaialable attributes for an element + template + struct element_attributes { + const char *m_Name; + void (T::*m_Setter)(const std::string &_v); + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + public: + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + element(const t_sptr &s,const char *n) : m_content(s) ,m_name(n){}; + friend std::ostream & operator <<(std::ostream &os,const element &e) + { + os<<"<:"<serialize_attributes(os); + os<<">"; + os<<*(e.m_content); + os<<""; + return os; + }; + t_sptr m_content; + const char *m_name; + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + element(const t_sptr &s,const char *n) : m_content(s) ,m_name(n){}; + friend std::ostream & operator <<(std::ostream &os,const element &e) + { + os<<"<"<serialize_attributes(os); + os<<">"; + os<<*(e.m_content); + os<<"<"<"; + return os; + }; + t_sptr m_content; + const char *m_name; + }; + + } // end xml ns + +#endif diff --git a/src/xml/reqif/element_factory.cpp b/src/xml/element_factory.cpp similarity index 100% rename from src/xml/reqif/element_factory.cpp rename to src/xml/element_factory.cpp diff --git a/src/xml/reqif/element_factory.h b/src/xml/element_factory.h similarity index 100% rename from src/xml/reqif/element_factory.h rename to src/xml/element_factory.h diff --git a/src/xml/reqif/CMakeLists.txt b/src/xml/reqif/CMakeLists.txt index 9a68836..24a42d8 100644 --- a/src/xml/reqif/CMakeLists.txt +++ b/src/xml/reqif/CMakeLists.txt @@ -2,6 +2,7 @@ PROJECT(libreqifparser) INCLUDE_DIRECTORIES(${libreqifparser_SOURCE_DIR}) INCLUDE_DIRECTORIES(/usr/local/include) + # Check with BOOTSTRAP_expat too IF(NOT WIN32) FIND_PACKAGE(EXPAT REQUIRED) @@ -15,22 +16,17 @@ ENDIF(NOT WIN32) INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR}) ADD_LIBRARY(reqif_parser STATIC - document.cpp - ant_elements_parser.cpp - ant_elements_parser_root.cpp - element_factory.cpp + #document.cpp + # ant_elements_parser.cpp + # ant_elements_parser_root.cpp +reqif_elements_parser.cpp +reqif_elements_parser_root.cpp ) TARGET_LINK_LIBRARIES(reqif_parser ${EXPAT_LIBRARY}) EXPORT(TARGETS reqif_parser FILE libxsdLibraries.cmake) IF (0) -INSTALL(TARGETS libxsd - EXPORT libxsd - ARCHIVE - DESTINATION lib - COMPONENT Libraries) -INSTALL(EXPORT libxsd DESTINATION lib) INSTALL(TARGETS xsdd EXPORT xsdd @@ -39,35 +35,4 @@ INSTALL(TARGETS xsdd COMPONENT Libraries) INSTALL(EXPORT xsdd DESTINATION lib) -INSTALL(FILES - ${libxsd_SOURCE_DIR}/document_expat.cpp - ${libxsd_SOURCE_DIR}/elements.cpp - ${libxsd_SOURCE_DIR}/parser.cpp - DESTINATION lib/src - COMPONENT Headers - ) -INSTALL(FILES - ${libxsd_SOURCE_DIR}/../include/xsd/xsd.h - DESTINATION include/xsd - COMPONENT Headers - ) -INSTALL(FILES - ${libxsd_SOURCE_DIR}/../include/xsd/parser/parser.h - ${libxsd_SOURCE_DIR}/../include/xsd/parser/elements.h - ${libxsd_SOURCE_DIR}/../include/xsd/parser/document.h -# ${libxsd_SOURCE_DIR}/../include/xsd/parser/xml-schema.h - DESTINATION include/xsd/parser - COMPONENT Headers - ) -INSTALL(FILES - ${libxsd_SOURCE_DIR}/../include/xsd/parser/expat/elements.h - DESTINATION include/xsd/parser/expat - COMPONENT Headers - ) - -INSTALL(FILES - ${libxsd_SOURCE_DIR}/../include/xmlSerialize.h - DESTINATION include/ - COMPONENT Headers - ) ENDIF(0) diff --git a/src/xml/reqif/parser_base.h b/src/xml/reqif/parser_base.h new file mode 100644 index 0000000..b3042e7 --- /dev/null +++ b/src/xml/reqif/parser_base.h @@ -0,0 +1,68 @@ +#ifndef ANTCC_PARSER_ELEMENTS_H +#define ANTCC_PARSER_ELEMENTS_H +#include +namespace reqif +{ + struct Element; + namespace parser { + class Document; + class ComplexElement; + class SimpleElement; + class RootElement; + /** + * \brief Abstract class to implement the parser + * + */ + class ParserBase + { + private: + ParserBase(const ParserBase &p) {}; + public: + ParserBase() {}; + + virtual void pre() {}; + virtual Element *post() { return NULL; }; + + virtual void preInternal() {}; + virtual void postInternal() {}; + + virtual void preImpl() {preInternal();}; + virtual void postImpl() {postInternal();}; + + // + virtual void startAnyElement(const std::string &ns , const std::string &name) {}; + virtual void endAnyElement(const std::string &ns,const std::string &name) {}; + virtual void anyAttribute(const std::string &ns,const std::string &name,const std::string &val) {}; + + // post functions + virtual void post(std::string &) {std::cout<<"Should not behere\n";}; + //virtual void post(xsd::decimal &) {std::cout<<"Should not behere\n";}; + virtual void post(float &) {std::cout<<"Should not behere\n";}; + virtual void post(double &) {std::cout<<"Should not behere\n";}; + virtual void post(int &) {}; + virtual void post(short &) {}; + + // Function coded once called by the Documents. + protected: + virtual void _startElement(const std::string &ns,const std::string &name,const std::string &type) = 0; + virtual void _endElement(const std::string &ns,const std::string &name) = 0; + virtual void _Characters(const std::string &) = 0; + virtual void _Attribute(const std::string &ns,const std::string &name,const std::string &value) = 0; + + virtual const std::string &dynamicType() {static std::string s="base";return s;}; + + virtual void updateLocation(const antcc::Location &l) {}; + friend class reqif::parser::Document; + friend class reqif::parser::ComplexElement; + friend class reqif::parser::RootElement; + friend class reqif::parser::SimpleElement; + + + }; + + } + + +} + +#endif diff --git a/src/xml/reqif/parsers.h.inc b/src/xml/reqif/parsers.h.inc new file mode 100644 index 0000000..1ca3cf7 --- /dev/null +++ b/src/xml/reqif/parsers.h.inc @@ -0,0 +1,94 @@ +#ifndef COMPLEX_PARSER +#define COMPLEX_PARSER(nm,cls) +#endif +#ifndef ROOT_PARSER +#define ROOT_PARSER(nm,cls) +#endif +#ifndef SIMPLE_PARSER +#define SIMPLE_PARSER(nm,cls) +#endif + +ROOT_PARSER(REQ-IF,ReqifParser) +COMPLEX_PARSER(THE-HEADER,ReqifHeaderParser) +//SIMPLE_PARSER(REQ-IF-HEADER,DescriptionParser) +//SIMPLE_PARSER(CREATION-TIME,DescriptionParser) +//SIMPLE_PARSER(REQ-IF-TOOL-ID,DescriptionParser) +//SIMPLE_PARSER(REQ-IF-VERSION,DescriptionParser) +//SIMPLE_PARSER(SOURCE-TOOL-ID,DescriptionParser) +//SIMPLE_PARSER(TITLE,DescriptionParser) + + +COMPLEX_PARSER(CORE-CONTENT,CoreContentParser) +COMPLEX_PARSER(REQ-IF-CONTENT,ReqifContentParser) +COMPLEX_PARSER(DATATYPES,DatatypesParser) +SIMPLE_PARSER(DATATYPE-DEFINITION-STRING,DatatypeParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-XHTML,DatatypeParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-STRING,DatatypeParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-REAL,DatatypeParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-INTEGER,DatatypeParser) + + +COMPLEX_PARSER(SPEC-TYPES,TypeParser) +SIMPLE_PARSER(SPECIFICATION-TYPE,DescriptionParser) + +COMPLEX_PARSER(SPEC-OBJECT-TYPE,SpecObjectTypeParser) +COMPLEX_PARSER(SPEC-ATTRIBUTES,SpecAttributesParser) +COMPLEX_PARSER(ATTRIBUTES-DEFINITION-STRING,AttributeDefinitionParser) +//COMPLEX_PARSER(ATTRIBUTES-DEFINITION-INTEGER,AttributeDefinitionParser) +//COMPLEX_PARSER(ATTRIBUTES-DEFINITION-REAL,AttributeDefinitionParser) +//COMPLEX_PARSER(ATTRIBUTES-DEFINITION-DATE,AttribtuteDefinitionParser) +//COMPLEX_PARSER(ATTRIBUTES-DEFINITION-XHTML,AttribtuteDefinitionParser) +COMPLEX_PARSER(TYPE,AttributeTypeParser) +SIMPLE_PARSER(DATATYPE-DEFINITION-STRING-REF,DatatypeRefParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-XHTML-REF,DatatypeRefParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-STRING-REF,DatatypeRefParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-REAL-REF,DatatypeRefParser) +//SIMPLE_PARSER(DATATYPE-DEFINITION-INTEGER-REF,DatatypeRefParser) + +SIMPLE_PARSER(SPEC-RELATION-TYPE,RelationTypeParser) + +/* Spec Objects */ + +COMPLEX_PARSER(SPEC-OBJECTS,SpecObjectsParser) +COMPLEX_PARSER(SPEC-OBJECT,SpecObjectParser) +COMPLEX_PARSER(VALUES,ValuesParser) +COMPLEX_PARSER(ATTRIBUTE-VALUE-DATE,AttributeValueParser) +//COMPLEX_PARSER(ATTRIBUTE-VALUE-STRING,AttributeValueParser) +//COMPLEX_PARSER(ATTRIBUTE-VALUE-XHTML,AttributeValueParser) +//COMPLEX_PARSER(ATTRIBUTE-VALUE-INTEGER,AttributeValueParser) +//COMPLEX_PARSER(ATTRIBUTE-VALUE-REAL,AttributeValueParser) + +COMPLEX_PARSER(DEFINITION,AttributeDefitionParser) +COMPLEX_PARSER(THE-VALUE,TheValueParser) + +//SIMPLE_PARSER(ATTRIBUTE-DEFINITION-STRING-REF,DatatypeRefParser) +//SIMPLE_PARSER(ATTRIBUTE-DEFINITION-XHTML-REF,DatatypeRefParser) +//SIMPLE_PARSER(ATTRIBUTE-DEFINITION-STRING-REF,DatatypeRefParser) +//SIMPLE_PARSER(ATTRIBUTE-DEFINITION-REAL-REF,DatatypeRefParser) +//SIMPLE_PARSER(ATTRIBUTE-DEFINITION-INTEGER-REF,DatatypeRefParser) + + +//COMPLEX_PARSER(TYPE,TypeParser) +//SIMPLE_PARSER(SPEC-OBJECT-TYPE-REF,DatatypeRefParser) +//SIMPLE_PARSER(SPEC-RELATION-TYPE-REF,DatatypeRefParser) +//SIMPLE_PARSER(SPECIFICATION-TYPE-REF,DatatypeRefParser) + +/* Spec Relations */ +COMPLEX_PARSER(SPEC-RELATIONS,SpecRelationsParser) +COMPLEX_PARSER(SPEC-RELATION,SpecRelationParser) +COMPLEX_PARSER(TARGET,TargetParser) +COMPLEX_PARSER(SOURCE,SourceParser) +/*Type already defined above */ + +/* Specifications */ +COMPLEX_PARSER(SPECIFICATIONS,SpecificationsParser) +COMPLEX_PARSER(SPECIFICATION,SpecificationParser) + +COMPLEX_PARSER(CHILDREN,ChildrenParser) +//COMPLEX_PARSER(SPEC-HIERACHY,ChildrenParser) +//COMPLEX_PARSER(OBJECT,ChildrenParser) +//SIMPLE_PARSER(SPEC-OBJECT-REF,DatatypeRefParser) + + + +//COMPLEX_PARSER(TOOL-EXTENSIONS,ChildrenParser) diff --git a/src/xml/reqif/reqif_element.h b/src/xml/reqif/reqif_element.h new file mode 100644 index 0000000..14d3c3d --- /dev/null +++ b/src/xml/reqif/reqif_element.h @@ -0,0 +1,194 @@ +#ifndef REQIF_ELEMENT_H +#define REQIF_ELEMENT_H + +#include +#include +#include +#include +#include +#include +#ifdef ANTCC_WITH_BOOST +#include +#elif defined (ANTCC_WITH_AEB) +#include +#endif +#include + +namespace reqif { + class project; + struct Location; + +#if 0 +namespace xml { + + template + struct element_traits { + typedef T element_type; +#ifdef XSD_WITH_BOOST + typedef typename boost::shared_ptr element_sptr; +#elif defined(XSD_WITH_AEB) + typedef typename aeb::shared_ptr element_sptr; +#else + typedef typename std::shared_ptr element_sptr; +#endif + typedef typename std::vector element_sequence; + }; + /// Usefulle template to create a static + // array of all avaialable attributes for an element + template + struct element_attributes { + const char *m_Name; + void (T::*m_Setter)(const std::string &_v); + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + public: + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + element(const t_sptr &s,const char *n) : m_content(s) ,m_name(n){}; + friend std::ostream & operator <<(std::ostream &os,const element &e) + { + os<<"<:"<serialize_attributes(os); + os<<">"; + os<<*(e.m_content); + os<<""; + return os; + }; + t_sptr m_content; + const char *m_name; + }; + + template + struct element { + typedef typename element_traits::element_type t_type; + typedef typename element_traits::element_sptr t_sptr; + element(const t_sptr &s,const char *n) : m_content(s) ,m_name(n){}; + friend std::ostream & operator <<(std::ostream &os,const element &e) + { + os<<"<"<serialize_attributes(os); + os<<">"; + os<<*(e.m_content); + os<<"<"<"; + return os; + }; + t_sptr m_content; + const char *m_name; + }; + + } // end xml ns +#endif + // Ok, lets define ant_element + struct Element + { + public: + enum eAntType {eNone,eProject,eTarget,eTask,eType,eArgument,eParameter,eCondition,eSelector}; + typedef std::map attrMap_type; + typedef std::map::iterator attrMap_iterator; + typedef std::map::const_iterator attrMap_const_iterator; + typedef typename xml::element_traits::element_type t_type; + typedef typename xml::element_traits::element_sptr t_sptr; + + Element(int _type ) : m_Name("") , m_Type(_type) {} + + Element(const Element &_e) : m_Name(_e.m_Name),m_Type(_e.m_Type) + {} + virtual ~Element() {}; + /// Element name !!! not the value of attribute name + inline void setName(const char *_name) { m_Name = _name; }; + /// Return Element name + inline const char *getName() const { return m_Name.c_str(); }; + + // what are the public methods available on all elements ? + virtual void addChild(const char *_name,reqif::Element *_task) {} ; + /// + virtual void setProject(::antcc::project *_p) {}; + + virtual void setLocation(const ::antcc::Location &_loc) {} ; + /** + * @brief add attribute to antcc element. + * sub classes should check if attribute is allowed or not. + * @return false if the attribute is not supported + */ + virtual bool addAttribute(const std::string &_name,const std::string &_val) + { m_Attributes[_name] = _val; return true;} ; + + /// + const bool isTarget() const { return m_Type == eTarget; }; + + /// + const bool isTask() const { return m_Type == eTask; }; + + /// + const bool isType() const { return m_Type == eType; }; + + /// + const bool isParameter() const { return m_Type == eParameter; }; + + /// + const bool isNone() const { return m_Type == eNone; }; + + /// + const bool isCondition() const { return m_Type == eCondition; }; + + /// + const bool isSelector() const { return m_Type == eSelector; }; + + /// + const bool isArgument() const { return m_Type == eArgument; }; + /// Check if element has attribute + bool hasAttribute(const std::string _name) const + { + attrMap_const_iterator it = m_Attributes.find(_name); + return (it != m_Attributes.end() ); + } + protected: + template + bool addAttribute(C *_this,struct xml::element_attributes *gProjectAttr,const std::string &_n,const std::string &val) + { + bool l_ok = false; + long l_i = 0; + do + { + if (gProjectAttr[l_i].m_Name == NULL) + { + break; + } + if (! _n.compare(gProjectAttr[l_i].m_Name) ) + { + (_this->*gProjectAttr[l_i].m_Setter)(val); + l_ok = true; + break; + } + } while (++l_i); + + return l_ok; + } + + bool getAttribute(const std::string _name,std::string &_value) const + { + attrMap_const_iterator it = m_Attributes.find(_name); + if (it != m_Attributes.end() ) + { + _value = it->second; + return true; + } else + { + return false; + } + } + private: + attrMap_type m_Attributes; + std::string m_Name; + int m_Type; + }; +} +#endif diff --git a/src/xml/reqif/reqif_elements_parser.cpp b/src/xml/reqif/reqif_elements_parser.cpp new file mode 100644 index 0000000..12f1b0b --- /dev/null +++ b/src/xml/reqif/reqif_elements_parser.cpp @@ -0,0 +1,865 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +#include +#include +#include + + +//#define PARSER_DEBUG 1 +namespace reqif { + namespace parser { + + + +EmptyElement::EmptyElement(reqif::Element *_elt ) + : m_str(""), m_CurrentElement(_elt) +{ + ANTCC_PARSER_DEBUG("%s(%0x) ctor m_CurrentElement=%0x" + ,__FUNCTION__ + ,this + ,_elt); +} + + + void EmptyElement::_Attribute(const std::string &ns,const std::string &name,const std::string &val) + { + if( !this->AttributeImpl(ns,name,val) ) + { + std::cout<<"Any attribute "<setLocation(l); + } +} + + +/** + * Implement ComplexElement parsing function + */ + +ComplexElement::ComplexElement(reqif::Element *_elt ) + : EmptyElement(_elt) +{ + ANTCC_PARSER_DEBUG("Cplx(%0x)::Cplx ctor m_CurElt=%0x" + ,this + ,m_CurrentElement); +} + +ComplexElement::ComplexElement(const ComplexElement &c) + : reqif::parser::EmptyElement(c.m_CurrentElement) +{ + ANTCC_PARSER_DEBUG("Cplx(%0x)::Cplx copy c.m_CurElt=%0x" + ,this + ,c.m_CurrentElement); +} + +void ComplexElement::preImpl() +{ + m_context.push_back(State()); + ANTCC_PARSER_DEBUG("Cplx(%0x)::preImpl m_context size=%d call preInternal" + ,this + ,m_context.size()); + this->preInternal(); +} + +void ComplexElement::postImpl() +{ + this->postInternal(); + ANTCC_PARSER_DEBUG("Cplx(%0x)::postImpl after postInternal m_context size=%d" + ,this + ,m_context.size()); + m_context.pop_back(); + ANTCC_PARSER_DEBUG("Cplx::postImpl after m_context size=%d",m_context.size()); +} + +void ComplexElement::_startElement(const std::string &ns,const std::string &name,const std::string &type) +{ + State &s(m_context.back()); + std::string space; + ANTCC_PARSER_DEBUG("%sCplxE(%0x)::_startElement Enter name=%s s.depth=%d context.size=%d" + ,space.insert(0,s.m_depth,' ').c_str() + ,this + ,name.c_str() + ,s.m_depth + ,m_context.size()); + if (s.m_depth++ > 0) + { + //Should check if it's any first + if (s.m_parser) + { + ANTCC_PARSER_DEBUG("CplxE::_startElement call s.m_parser->_startElement : %s",name.c_str()); + s.m_parser->_startElement(ns,name,type); + } else { + ANTCC_PARSER_ERROR("CplxE::_startElement no parser stacked (s.m_parser==NULL) : %s",name.c_str()); + } + } else { + ANTCC_PARSER_DEBUG("CplxE::_startElement %s call startElementImpl",name.c_str()); + if (!startElementImpl(ns,name,type)) + { + ANTCC_PARSER_ERROR("CplxE::_startElement %s call startElementImpl returned false",name.c_str()); +#ifdef PARSER_DEBUG + std::cout<<"\tcplx _start call Any : unknown "<startAnyElement(ns,name); + /* Element not recogized by us*/ + } else + { + ANTCC_PARSER_DEBUG("CplxE::_startElement %s called startElementImpl returned true ",name.c_str()); + if (s.m_parser != 0) + { + s.m_parser->preImpl(); + /* Need to call pre */ +#ifdef PARSER_DEBUG + std::cout<<"\tcplx _start Need to call pre- : "< 0) + { + // Indirect + ANTCC_PARSER_DEBUG("CplxE::_endElement 1 name=%s ss.m_depth=%d m_context.size=%d" + ,name.c_str() + ,ss.m_depth + ,m_context.size()); + if (ss.m_parser) + { + ss.m_parser->_endElement(ns,name); + } else + std::cout<<"No parser ? "<postImpl(); + if (!endElementImpl(ns,name)) + { + ANTCC_PARSER_ERROR( "CplxE::_endElement %s endElementImpl call failed",name.c_str()); + } + } else + { + ANTCC_PARSER_ERROR( "CplxE::_endElement %s Must NOT HAPPEN!!!",name.c_str()); + } + } + } + else + { + State &s(m_context.back()); + if (--s.m_depth > 0) + { + space = ""; + ANTCC_PARSER_DEBUG("%sCplx(%0x)::_endElement 3 name=%s s.depth=%d context.size=%d" + ,space.insert(0,s.m_depth,' ').c_str() + ,this + ,name.c_str() + ,s.m_depth + ,m_context.size()); + if (s.m_parser) + { + s.m_parser->_endElement(ns,name); + } else + std::cout<<"No parser here\n"; + + } else { + ANTCC_PARSER_DEBUG("CplxE(%0x)::_endElement %s 4 %s same parser " + , this + , name.c_str() + , (this==s.m_parser.get())?"yes":"no"); + if (s.m_parser ) + { + ANTCC_PARSER_DEBUG("CplxE(%0x)::_endElement call postImpl %s" + ,this + ,name.c_str()); + s.m_parser->postImpl(); + } + + if (!endElementImpl(ns,name)) + { + ANTCC_PARSER_ERROR("CplxE::_endElement failed call endElementImpl %s" + ,name.c_str()); + // Wrong + //this->endAnyElement(ns,name); + } + } + } + ANTCC_PARSER_DEBUG("CplxE::_endElement LEAVE this=%0x name=%s,s.m_depth=%d m_context.size=%d" + , this + ,name.c_str() + ,s.m_depth + ,m_context.size() + ); +} + +/** + * + * + */ + void ComplexElement::_Attribute(const std::string &ns,const std::string &name,const std::string &val) +{ + if (m_context.back().m_depth > 0) + { + /// Handle Child Element Attributes of Current ComplexElement + State &s(m_context.back()); + if (s.m_any) + { + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre any name=%s",name.c_str()); + anyAttribute(ns,name,val); + } else if (s.m_parser) + { + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre with parser name=%s",name.c_str()); + s.m_parser->_Attribute(ns,name,val); + } + } else + { + /// Handle current Complex Element Attributes + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre call this->AttributeImpl name=%s",name.c_str()); + if ( ! this->AttributeImpl(ns,name,val) ) + { + ANTCC_PARSER_ERROR("Cplx::_AttributeImpl name=%s unsupported" + ,name.c_str()); + } + } +} + +/** + * + * + */ +void ComplexElement::_Characters(const std::string &val) +{ + State &s(m_context.back()); + if (s.m_depth > 0) + { + if (s.m_parser) { +#ifdef PARSER_DEBUG_CHARACTER + std::cout<<"CplxE::_characters"<setProject(_project);\ + } \ +} \ +cls::~cls() \ +{ \ + ANTCC_PARSER_DEBUG("%s::~" \ + ,#cls); \ +} \ +bool cls::startElementImpl(const std::string &ns,const std::string &name,const std::string &type) \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s::startElementImpl %s depth=%u size=%u" \ + ,#cls \ + ,name.c_str() \ + ,s.m_depth \ + ,m_context.size()); \ + start \ +} \ +bool cls::endElementImpl(const std::string &ns,const std::string &name) \ +{ \ + State &s(m_context.back()); \ + if (s.m_parser && m_CurrentElement) \ + m_CurrentElement->addChild(name.c_str(),s.m_parser->post()); \ + end \ +} \ +bool cls::AttributeImpl(const std::string &ns,const std::string &name,const std::string &val) \ +{ \ + bool l_ok = false; \ + if (m_CurrentElement) \ + l_ok = m_CurrentElement->addAttribute(name,val); \ + attr \ +} \ +void cls::preInternal() \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s(%0x)::preInternal depth=%u size=%u m_CurElt=%0x" \ + ,#cls \ + ,this \ + ,s.m_depth \ + ,m_context.size() \ + ,m_CurrentElement); \ + s.m_data = m_CurrentElement; \ + \ +} \ +void cls::postInternal() \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s::postInternal depth=%u size=%u m_CurElt=%0x" \ + ,#cls \ + ,s.m_depth \ + ,m_context.size() \ + ,m_CurrentElement \ + ); \ + m_CurrentElement = s.m_data; \ + s.m_data = NULL;\ +} \ + + +#define COMPLEX_PARSER(cls,start,end,attr) \ +cls :: cls(const cls &_c) : ComplexElement(_c.m_CurrentElement) \ +{ \ + ANTCC_PARSER_DEBUG("%s::%s cp elt=%0x" \ + ,#cls \ + ,#cls \ + ,_c.m_CurrentElement \ + ); \ +} \ +cls::cls(antcc::project *_project,reqif::Element *_elt) \ + : ComplexElement(_elt) ,m_Project(_project) \ +{ \ + ANTCC_PARSER_DEBUG("%s(%0x)::%s elt=%0x" \ + ,#cls \ + ,this \ + ,#cls \ + ,_elt \ + ); \ + if (_elt == NULL) \ + { \ + ANTCC_PARSER_ERROR("%s(%0x)::%s is NULL unsuported!!!" \ + ,#cls \ + ,this \ + ,#cls \ + ); \ + } else \ + { \ + _elt->setProject(_project);\ + } \ +} \ +cls::~cls() \ +{ \ + ANTCC_PARSER_DEBUG("%s::~" \ + ,#cls); \ +} \ +bool cls::startElementImpl(const std::string &ns,const std::string &name,const std::string &type) \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s::startElementImpl %s depth=%u size=%u" \ + ,#cls \ + ,name.c_str() \ + ,s.m_depth \ + ,m_context.size()); \ + start \ +} \ +bool cls::endElementImpl(const std::string &ns,const std::string &name) \ +{ \ + State &s(m_context.back()); \ + if (s.m_parser && m_CurrentElement) \ + m_CurrentElement->addChild(name.c_str(),s.m_parser->post()); \ + end \ +} \ +bool cls::AttributeImpl(const std::string &ns,const std::string &name,const std::string &val) \ +{ \ + bool l_ok = false; \ + if (m_CurrentElement) \ + l_ok = m_CurrentElement->addAttribute(name,val); \ + attr \ +} \ +void cls::preInternal() \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s(%0x)::preInternal depth=%u size=%u m_CurElt=%0x" \ + ,#cls \ + ,this \ + ,s.m_depth \ + ,m_context.size() \ + ,m_CurrentElement); \ + s.m_data = m_CurrentElement; \ + \ +} \ +void cls::postInternal() \ +{ \ + State &s(m_context.back()); \ + ANTCC_PARSER_DEBUG("%s::postInternal depth=%u size=%u m_CurElt=%0x" \ + ,#cls \ + ,s.m_depth \ + ,m_context.size() \ + ,m_CurrentElement \ + ); \ + m_CurrentElement = s.m_data; \ + s.m_data = NULL;\ +} \ + +#define SIMPLE_PARSER(cls,attr) \ +cls :: cls(const cls &_c) : SimpleElement() \ +{ \ + ANTCC_PARSER_DEBUG("%s::%s cp elt=%0x" \ + ,#cls \ + ,#cls \ + ,_c.m_CurrentElement \ + ); \ +} \ +cls::cls(antcc::project *_project,reqif::Element *_elt) \ + : SimpleElement(_elt), m_Project(_project) \ +{ \ + ANTCC_PARSER_DEBUG("%s(%0x)::%s elt=%0x" \ + ,#cls \ + ,this \ + ,#cls \ + ,_elt \ + ); \ + if (_elt == NULL) \ + { \ + ANTCC_PARSER_DEBUG("%s(%0x)::%s is NULL unsuported!!!" \ + ,#cls \ + ,this \ + ,#cls \ + ); \ + } else \ + { \ + _elt->setProject(_project);\ + } \ +} \ +cls::~cls() \ +{ \ + ANTCC_PARSER_DEBUG("%s::~" \ + ,#cls); \ +} \ +bool cls::AttributeImpl(const std::string &ns,const std::string &name,const std::string &val) \ +{ \ + bool l_ok = false; \ + if (m_CurrentElement) \ + l_ok = m_CurrentElement->addAttribute(name,val); \ + attr \ +} \ + +//Project Parser Impl +ROOT_PARSER(ReqifParser, +{ +if (name == "THE-HEADER" && ns.empty()) +{ + s.m_parser = SHARED_PTR(new TargetParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); +} else if (name == "TOOL-EXTENSION" && ns.empty()) +{ + s.m_parser = SHARED_PTR(new DescriptionParser(m_Project + , NULL) + ); +} else if (name == "CORE-CONTENT" && ns.empty()) +{ + s.m_parser = SHARED_PTR(new CoreContentParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + ) + ); +} else +{ + return false; +} +return true; + +} +, +{ +ANTCC_PARSER_DEBUG_PROJECT("ReqifParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + if (name == "THE-HEADER" && ns.empty()) + { + std::string m_result; + s.m_parser->post(m_result); + } + return true; +} +, +{ +ANTCC_PARSER_DEBUG_PROJECT("ReqifParser(%0x) Attribute: %s-> %s" + ,m_CurrentElement + ,name.c_str() + ,val.c_str()); +return l_ok; +}) + +// Target Parser Implementation +COMPLEX_PARSER(ReqifHeaderParser, + { + if (name == "REQ-IF-HEADER" && ns.empty()) + { + s.m_parser = SHARED_PTR(new DescriptionParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + } else if (name == "exec" && ns.empty()) + { + s.m_parser = SHARED_PTR(new DescriptionParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + } + else + { + s.m_parser = SHARED_PTR(new DescriptionParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + } + return true; + + } + , + { + ANTCC_PARSER_DEBUG_TARGET("ReqifHEaderParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TARGET("ReqifHeaderParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + +// DescriptionParser Implementation +COMPLEX_PARSER(CoreContentParser, + { + return true; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("CoreContentParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("CoreContentParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + +// Exec Parser Implementation +COMPLEX_PARSER(ReqifContentParser, + { + if (name == "DATATYPES" && ns.empty()) + { + ANTCC_PARSER_DEBUG("ReqifContentParser ignore %s size=%u" + ,name.c_str() + ,m_context.size()); + s.m_parser = SHARED_PTR(new DatatypesParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + } + else if (name == "SPEC-TYPES" && ns.empty()) + { + } else + { + s.m_parser = SHARED_PTR(new TypeParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + } + return true; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("ReqifParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("ReqifParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + +// Datypesarser Implementation +COMPLEX_PARSER(DatatypesParser, + { + s.m_parser = SHARED_PTR(new DatatypeParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + return true; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("DatatypeParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("DatatypeParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + +// Type Parser Implementation +COMPLEX_PARSER(TypeParser, + { + // Not sure that I need sub element for the Type parser + if (name == "include" && ns.empty()) + { + s.m_parser = SHARED_PTR(new TypeParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + return true; + } + return false; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("TypeParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("TypeParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + +// Spec Object Type Parser Implementation +COMPLEX_PARSER(SpecObjectTypeParser, + { + s.m_parser = SHARED_PTR(new SpecAttributesParser(m_Project + , reqif::ElementFactory::get().orderElement(name.c_str()) + )); + return true; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("SpecObjectTypeParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("SpecObjectTypeParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + +// Macrodef Parser Implementation +COMPLEX_PARSER(AttributeDefinitionParser, + { + if (name == "TYPE" && ns.empty()) + { + ANTCC_PARSER_DEBUG("TypeParser ignore %s size=%u" + ,name.c_str() + ,m_context.size()); + s.m_parser = SHARED_PTR(new TypeParser(m_Project + , reqif::ElementFactory::get().orderElement("TYPE") + )); + return true; + } + return false; + + } + , + { + ANTCC_PARSER_DEBUG_TASK("AttributeDefinitionParser end %s size=%u" + ,name.c_str() + ,m_context.size()); + return true; + } + , + { + ANTCC_PARSER_DEBUG_TASK("AttributeDefinitionParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + + +// Description Parser Implementation +SIMPLE_PARSER(DescriptionParser, + { + ANTCC_PARSER_DEBUG_TASK("DescriptionParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + +// Property Parser Implementation +SIMPLE_PARSER(DatatypeParser, + { + ANTCC_PARSER_DEBUG_TASK("DatatypeParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return l_ok; + }) + + +// Description Parser Implementation +SIMPLE_PARSER(DatatypeRefParser, + { + ANTCC_PARSER_DEBUG_TASK("DatatypeRefParser Attribute: %s-> %s" + ,name.c_str() + ,val.c_str()); + return true; + }) + + + + +} +} diff --git a/src/xml/reqif/reqif_elements_parser.h b/src/xml/reqif/reqif_elements_parser.h new file mode 100644 index 0000000..c81c44a --- /dev/null +++ b/src/xml/reqif/reqif_elements_parser.h @@ -0,0 +1,323 @@ +#ifndef REQIF_PARSER_PARSER_H +#define REQIF_PARSER_PARSER_H +#include +#include +#include + +#include + +namespace reqif +{ + class project; + namespace parser + { + template + struct _parser_data + { }; + + class EmptyElement : public reqif::parser::ParserBase + { + protected: + public: + EmptyElement(reqif::Element *_elt ) ; + EmptyElement(const EmptyElement &_e) + : m_str(""), m_CurrentElement(_e.m_CurrentElement) {} + virtual ~EmptyElement() {}; + + virtual void preImpl() {m_str.clear(); }; + + virtual void postImpl() {}; + // Any Elements + // + virtual void startAnyElement(const std::string &ns , const std::string &name) { + std::cout<<"EmptyElement::startAny: "<preInternal();}; + virtual void preInternal() {m_str.clear();}; + virtual bool _CharactersImpl(const std::string &c) { m_str+=c;return true;}; + virtual void _Characters(const std::string &c); + virtual void _Attribute(const std::string &ns,const std::string &name,const std::string &val); + virtual void updateLocation(const antcc::Location &l) ; + }; + + /** + * \brief Complex Elements have choice, sequence, extension... + * This is probably the most complicated case + * + * + * \author EBERSOLD Andre + * \date + * \param + * + */ + class ComplexElement : public ::reqif::parser::EmptyElement + { + protected: + ComplexElement(const ComplexElement &c); + /** + * use preInternal to allocated data on newly create stack state. + */ + virtual void preImpl() ; + /** + * calls postInternal before removing State from state stack. + * postInternal can be used to perform processing in underling classes. + */ + virtual void postImpl(); + public: + ComplexElement(reqif::Element *_elt ) ; + virtual ~ComplexElement() {}; + + + virtual void _startElement(const std::string &ns,const std::string &name,const std::string &type) ; + virtual void _endElement(const std::string &ns,const std::string &name) ; + + virtual void _Attribute(const std::string &ns,const std::string &name,const std::string &val); + virtual void _Characters(const std::string &c); + virtual void updateLocation(const antcc::Location &l) ; + protected: + /** + * Complex parser Stack States to handle tree + */ + struct State { + public: + State(); + State(const State &p); + virtual ~State(); + bool m_any; + int m_depth; /* I need to find another name for this*/ + SHARED_PTR m_parser; + reqif::Element *m_data; /* To solve recurse issue ....*/ + }; + std::vector m_context; + }; + + /** + * \brief This class implements the root element parser. + * There shall be only one root element per specification + * This is the only class that should hold a stack of parsers. + * + * + * \author EBERSOLD Andre + * \date 31/10/2019 + * \param + * + */ + class RootElement : public ::reqif::parser::EmptyElement + { + private: + RootElement(const RootElement &c); + /** + * use preInternal to allocated data on newly create stack state. + */ + virtual void preImpl() ; + /** + * calls postInternal before removing State from state stack. + * postInternal can be used to perform processing in underling classes. + */ + virtual void postImpl(); + public: + RootElement(reqif::Element *_elt ) ; + virtual ~RootElement() {}; + + + virtual void _startElement(const std::string &ns,const std::string &name,const std::string &type) ; + virtual void _endElement(const std::string &ns,const std::string &name) ; + + virtual void _Attribute(const std::string &ns,const std::string &name,const std::string &val); + virtual void _Characters(const std::string &c); + virtual void updateLocation(const antcc::Location &l) ; + protected: + /** + * Complex parser Stack States to handle tree + */ + struct State { + public: + State(); + State(const State &p); + virtual ~State(); + bool m_any; + int m_depth; /* I need to find another name for this*/ + SHARED_PTR m_parser; + reqif::Element *m_data; /* To solve recurse issue ....*/ + }; + std::vector m_context; + }; + +/* Parser Foward declaration */ +#define COMPLEX_PARSER(nm,cls) class cls; +#define ROOT_PARSER(nm,cls) class cls; +#define SIMPLE_PARSER(nm,cls) class cls; + +#include +#undef SIMPLE_PARSER +#undef COMPLEX_PARSER +#undef ROOT_PARSER + +/* */ +#define COMPLEX_PARSER(nm,cls) \ +class cls : public ComplexElement \ +{ \ + protected: \ + cls(const cls &_c) ; \ + public: \ + cls(antcc::project *_project,reqif::Element *_elt = NULL ) ; \ + virtual ~cls() ; \ + \ + virtual bool startElementImpl(const std::string &ns,const std::string &name,const std::string &type) ; \ + \ + virtual bool endElementImpl(const std::string &ns,const std::string &name) ; \ + \ + virtual bool AttributeImpl(const std::string &ns,const std::string &name,const std::string &val); \ + \ + virtual void preInternal() ; \ + \ + virtual void postInternal() ; \ + \ + private: \ + antcc::project *m_Project; \ + \ + _parser_data m_Data; \ +}; + +#define ROOT_PARSER(nm,cls) \ +class cls : public RootElement \ +{ \ + protected: \ + cls(const cls &_c) ; \ + public: \ + cls(antcc::project *_project,reqif::Element *_elt = NULL ) ; \ + virtual ~cls() ; \ + \ + virtual bool startElementImpl(const std::string &ns,const std::string &name,const std::string &type) ; \ + \ + virtual bool endElementImpl(const std::string &ns,const std::string &name) ; \ + \ + virtual bool AttributeImpl(const std::string &ns,const std::string &name,const std::string &val); \ + \ + virtual void preInternal() ; \ + \ + virtual void postInternal() ; \ + \ + private: \ + antcc::project *m_Project; \ + \ +}; + +#define SIMPLE_PARSER(nm,cls) \ +class cls : public SimpleElement \ +{ \ + protected: \ + cls(const cls &_c) ; \ + public: \ + cls(antcc::project *_project,reqif::Element *_elt = NULL ) ; \ + virtual ~cls() ; \ + \ + virtual bool AttributeImpl(const std::string &ns,const std::string &name,const std::string &val); \ + \ + private: \ + antcc::project *m_Project; \ + \ +}; + +// Parser DataType Specialization before usage +#define COMPLEX_DATA_PARSER(eltname,parse,data) \ +template <> \ +struct _parser_data< ::reqif::parser:: parse> \ +data ; \ + +COMPLEX_DATA_PARSER(target,TargetParser,{ + TaskParser *m_TaskParser; + CopyParser *m_CopyParser; + ExecParser *m_ExecParser; +}) +COMPLEX_DATA_PARSER(task,TaskParser,{}) +COMPLEX_DATA_PARSER(exec,ExecParser,{}) +COMPLEX_DATA_PARSER(copy,CopyParser,{}) +COMPLEX_DATA_PARSER(fileset,TypeParser,{}) +COMPLEX_DATA_PARSER(redirector,RedirectorParser,{}) +COMPLEX_DATA_PARSER(macrodef,MacrodefParser,{}) + + +#include +#undef COMPLEX_PARSER +#undef ROOT_PARSER +#undef SIMPLE_PARSER + + } +} + + +#endif diff --git a/src/xml/reqif/reqif_elements_parser_root.cpp b/src/xml/reqif/reqif_elements_parser_root.cpp new file mode 100644 index 0000000..f320874 --- /dev/null +++ b/src/xml/reqif/reqif_elements_parser_root.cpp @@ -0,0 +1,306 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace antcc { + namespace parser { + + + +/** + * Implement RootElement parsing function + */ + +RootElement::RootElement(antcc::antElement *_elt ) + : EmptyElement(_elt) +{ + ANTCC_PARSER_DEBUG("Cplx(%0x)::Cplx ctor m_CurElt=%0x" + ,this + ,m_CurrentElement); +} + +RootElement::RootElement(const RootElement &c) + : antcc::parser::EmptyElement(c.m_CurrentElement) +{ + ANTCC_PARSER_DEBUG("Cplx(%0x)::Cplx copy c.m_CurElt=%0x" + ,this + ,c.m_CurrentElement); +} + +void RootElement::preImpl() +{ + m_context.push_back(State()); + ANTCC_PARSER_DEBUG("Cplx(%0x)::preImpl m_context size=%d call preInternal" + ,this + ,m_context.size()); + this->preInternal(); +} + +void RootElement::postImpl() +{ + this->postInternal(); + ANTCC_PARSER_DEBUG("Cplx(%0x)::postImpl after postInternal m_context size=%d" + ,this + ,m_context.size()); + m_context.pop_back(); + ANTCC_PARSER_DEBUG("Cplx::postImpl after m_context size=%d",m_context.size()); +} + +void RootElement::_startElement(const std::string &ns,const std::string &name,const std::string &type) +{ + State &s(m_context.back()); + std::string space; + ANTCC_PARSER_DEBUG("%sCplxE(%0x)::_startElement Enter name=%s s.depth=%d context.size=%d" + ,space.insert(0,s.m_depth,' ').c_str() + ,this + ,name.c_str() + ,s.m_depth + ,m_context.size()); + if (s.m_depth++ > 0) + { + //Should check if it's any first + if (s.m_parser) + { + ANTCC_PARSER_DEBUG("CplxE::_startElement call s.m_parser->_startElement : %s",name.c_str()); + s.m_parser->_startElement(ns,name,type); + } else { + ANTCC_PARSER_ERROR("CplxE::_startElement no parser stacked (s.m_parser==NULL) : %s",name.c_str()); + } + } else { + ANTCC_PARSER_DEBUG("CplxE::_startElement %s call startElementImpl",name.c_str()); + if (!startElementImpl(ns,name,type)) + { + ANTCC_PARSER_ERROR("CplxE::_startElement %s call startElementImpl returned false",name.c_str()); +#ifdef PARSER_DEBUG + std::cout<<"\tcplx _start call Any : unknown "<startAnyElement(ns,name); + /* Element not recogized by us*/ + } else + { + ANTCC_PARSER_DEBUG("CplxE::_startElement %s called startElementImpl returned true ",name.c_str()); + if (s.m_parser != 0) + { + s.m_parser->preImpl(); + /* Need to call pre */ +#ifdef PARSER_DEBUG + std::cout<<"\tcplx _start Need to call pre- : "< 0) + { + // Indirect + ANTCC_PARSER_DEBUG("CplxE::_endElement 1 name=%s ss.m_depth=%d m_context.size=%d" + ,name.c_str() + ,ss.m_depth + ,m_context.size()); + if (ss.m_parser) + { + ss.m_parser->_endElement(ns,name); + } else + std::cout<<"No parser ? "<postImpl(); + if (!endElementImpl(ns,name)) + { + ANTCC_PARSER_ERROR( "CplxE::_endElement %s endElementImpl call failed",name.c_str()); + } + } else + { + ANTCC_PARSER_ERROR( "CplxE::_endElement %s Must NOT HAPPEN!!!",name.c_str()); + } + } + } + else + { + State &s(m_context.back()); + if (--s.m_depth > 0) + { + space = ""; + ANTCC_PARSER_DEBUG("%sCplx(%0x)::_endElement 3 name=%s s.depth=%d context.size=%d" + ,space.insert(0,s.m_depth,' ').c_str() + ,this + ,name.c_str() + ,s.m_depth + ,m_context.size()); + if (s.m_parser) + { + s.m_parser->_endElement(ns,name); + } else + std::cout<<"No parser here\n"; + + } else { + ANTCC_PARSER_DEBUG("CplxE(%0x)::_endElement %s 4 %s same parser " + , this + , name.c_str() + , (this==s.m_parser.get())?"yes":"no"); + if (s.m_parser ) + { + ANTCC_PARSER_DEBUG("CplxE(%0x)::_endElement call postImpl %s" + ,this + ,name.c_str()); + s.m_parser->postImpl(); + } + + if (!endElementImpl(ns,name)) + { + ANTCC_PARSER_ERROR("CplxE::_endElement failed call endElementImpl %s" + ,name.c_str()); + // Wrong + //this->endAnyElement(ns,name); + } + } + } + ANTCC_PARSER_DEBUG("CplxE::_endElement LEAVE this=%0x name=%s,s.m_depth=%d m_context.size=%d" + , this + ,name.c_str() + ,s.m_depth + ,m_context.size() + ); +} + +/** + * + * + */ + void RootElement::_Attribute(const std::string &ns,const std::string &name,const std::string &val) +{ + if (m_context.back().m_depth > 0) + { + State &s(m_context.back()); + if (s.m_any) + { + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre any name=%s",name.c_str()); + anyAttribute(ns,name,val); + } else if (s.m_parser) + { + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre with parser name=%s",name.c_str()); + s.m_parser->_Attribute(ns,name,val); + } + } else + { + ANTCC_PARSER_DEBUG_CPLX_ATTR("Cplx::_Attributre call this->AttributeImpl name=%s",name.c_str()); + if ( ! this->AttributeImpl(ns,name,val) ) + { + ANTCC_PARSER_ERROR("Cplx::_AttributeImpl name=%s unsupported" + ,name.c_str()); + } + } +} + +/** + * + * + */ +void RootElement::_Characters(const std::string &val) +{ + State &s(m_context.back()); + if (s.m_depth > 0) + { + if (s.m_parser) { +#ifdef PARSER_DEBUG_CHARACTER + std::cout<<"CplxE::_characters"<