Continue on reqif parser
authorEbersold <aebersol@n3150.home>
Fri, 10 Feb 2023 21:53:39 +0000 (22:53 +0100)
committerEbersold <aebersol@n3150.home>
Fri, 10 Feb 2023 21:53:39 +0000 (22:53 +0100)
13 files changed:
src/xml/CMakeLists.txt
src/xml/element.h [new file with mode: 0644]
src/xml/element_factory.cpp [new file with mode: 0644]
src/xml/element_factory.h [new file with mode: 0644]
src/xml/reqif/CMakeLists.txt
src/xml/reqif/element_factory.cpp [deleted file]
src/xml/reqif/element_factory.h [deleted file]
src/xml/reqif/parser_base.h [new file with mode: 0644]
src/xml/reqif/parsers.h.inc [new file with mode: 0644]
src/xml/reqif/reqif_element.h [new file with mode: 0644]
src/xml/reqif/reqif_elements_parser.cpp [new file with mode: 0644]
src/xml/reqif/reqif_elements_parser.h [new file with mode: 0644]
src/xml/reqif/reqif_elements_parser_root.cpp [new file with mode: 0644]

index 8b376fa77846c9532ddf6aae4169f0112af8a677..abbe98bdc677246f91bb594caed5a57020c7e609 100644 (file)
@@ -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 (file)
index 0000000..8c68a45
--- /dev/null
@@ -0,0 +1,84 @@
+#ifndef XSD_ELEMENT_H__
+#define XSD_ELEMENT_H__
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+#include <antcc/config.h>
+#ifdef ANTCC_WITH_BOOST
+#include <boost/shared_ptr.hpp>
+#elif defined (ANTCC_WITH_AEB)
+#include <utils/aeb/shared_ptr.h>
+#endif
+
+
+namespace xml {
+
+    template <typename T>
+    struct element_traits {
+        typedef T                               element_type;
+#ifdef XSD_WITH_BOOST
+        typedef typename boost::shared_ptr<element_type> element_sptr;
+#elif defined(XSD_WITH_AEB)
+        typedef typename aeb::shared_ptr<element_type> element_sptr;
+#else
+        typedef typename std::shared_ptr<element_type> element_sptr;
+#endif
+        typedef typename std::vector<element_sptr>       element_sequence;
+    };
+    /// Usefulle template to create a static 
+    // array of all avaialable attributes for an element
+    template <typename T>
+    struct element_attributes {
+       const char *m_Name;
+       void (T::*m_Setter)(const std::string &_v);
+    };     
+
+    template <typename T,bool ns>
+    struct element {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::element_sptr t_sptr;
+        public:
+    };
+
+    template <typename T>
+    struct element<T,true > {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::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<<"<:"<<e.m_name;
+            e.m_content->serialize_attributes(os);
+            os<<">";
+            os<<*(e.m_content);
+            os<<"</:"<<e.m_name<<">";
+           return os;
+        };
+        t_sptr    m_content;
+        const char *m_name;
+    };
+    
+    template <typename T>
+    struct element<T,false> {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::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<<"<"<<e.m_name;
+            e.m_content->serialize_attributes(os);
+            os<<">";
+            os<<*(e.m_content);
+            os<<"<"<<e.m_name<<">";
+           return os;
+        };
+        t_sptr  m_content;
+        const   char *m_name;
+    };
+
+  } // end  xml ns
+
+#endif
diff --git a/src/xml/element_factory.cpp b/src/xml/element_factory.cpp
new file mode 100644 (file)
index 0000000..2443b3a
--- /dev/null
@@ -0,0 +1,46 @@
+#include <ios>
+#include <iostream>
+#include <antcc/config.h>
+#include <logger.h>
+#include <reqif/element_factory.h>
+#include <reqif/elements.h>
+
+namespace reqif {
+
+ElementFactory::ElementFactory()
+{
+}
+
+ElementFactory::~ElementFactory()
+{
+}
+
+ElementFactory &ElementFactory::get()
+{
+  static ElementFactory instance;
+  return instance;
+}
+
+
+Element* ElementFactory::orderElement(const char* typeName)
+{
+  auto it = m_generators.find(typeName);
+  if ( it != m_generators.end()) {
+    ANTCC_PARSER_DEBUG("ElementFactory::orderElement %s",typeName);
+    Element *_elt = it->second(typeName);
+    _elt->setName(typeName);
+    return _elt;
+  }
+  ANTCC_LOG_ERROR("antElementFactory::orderElement <%s> failed not found ",typeName);
+  return nullptr;
+}
+
+bool ElementFactory::registerGenerator(
+                        const char* typeName,
+                        const ElementGenerator& funcCreate)
+{
+  ANTCC_LOG_DEBUG("antElementFactory::registerGenerator %s",typeName);
+  return m_generators.insert(std::make_pair(typeName,funcCreate)).second;
+}
+
+}
diff --git a/src/xml/element_factory.h b/src/xml/element_factory.h
new file mode 100644 (file)
index 0000000..83c5eb7
--- /dev/null
@@ -0,0 +1,79 @@
+#pragma once
+#include <string>
+#include <unordered_map>
+#ifdef N_WIN32
+#ifdef BUILD_DLL
+#define DLL_INTERFACE __declspec(dllexport)
+#else
+#define DLL_INTERFACE __declspec(dllimport)
+#endif
+#else
+#define DLL_INTERFACE
+#endif
+namespace reqif {
+
+struct Element;
+typedef Element*(*ElementGenerator)(const char *_typeName);
+class ElementFactory
+{
+public:
+    DLL_INTERFACE static ElementFactory& get();
+    DLL_INTERFACE Element* orderElement(const char* typeName);
+    DLL_INTERFACE bool registerGenerator(
+                            const char* typeName,
+                            const ElementGenerator& funcCreate);
+private:
+    ElementFactory();
+    ElementFactory(const ElementFactory&);
+    ~ElementFactory();
+    std::unordered_map<std::string, ElementGenerator> m_generators;
+};
+
+template <typename T>
+class ElementFactoryRegistration
+{
+  private:
+    static Element *create(const char *_id)
+    {
+        return new T() ;
+    }
+  public:
+    ElementFactoryRegistration(const char *id) 
+    {
+      ElementFactory::get().registerGenerator(
+        id
+        ,ElementFactoryRegistration<T>::create );
+    }
+};
+
+template <typename T>
+class LibElementFactoryRegistration
+{
+  private:
+    static Element *create(const char *_name)
+    {
+        return new T(_name) ;
+    }
+  public:
+    LibElementFactoryRegistration(const char *id) 
+    {
+      ElementFactory::get().registerGenerator(
+        id
+        ,LibElementFactoryRegistration<T>::create );
+    }
+};
+
+/**
+ * How to use registration
+ * in antElements cpp file simply create an object
+ * antElementFactoryRegistration<property> _Property("property");
+ * should do the trick
+ */
+} //end reqif
index 9a68836aed06bfee3e2795113c5ba8979645001c..24a42d8f0c731bb9e4b90730f1d9215b1cb75c3e 100644 (file)
@@ -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/element_factory.cpp b/src/xml/reqif/element_factory.cpp
deleted file mode 100644 (file)
index 2443b3a..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <ios>
-#include <iostream>
-#include <antcc/config.h>
-#include <logger.h>
-#include <reqif/element_factory.h>
-#include <reqif/elements.h>
-
-namespace reqif {
-
-ElementFactory::ElementFactory()
-{
-}
-
-ElementFactory::~ElementFactory()
-{
-}
-
-ElementFactory &ElementFactory::get()
-{
-  static ElementFactory instance;
-  return instance;
-}
-
-
-Element* ElementFactory::orderElement(const char* typeName)
-{
-  auto it = m_generators.find(typeName);
-  if ( it != m_generators.end()) {
-    ANTCC_PARSER_DEBUG("ElementFactory::orderElement %s",typeName);
-    Element *_elt = it->second(typeName);
-    _elt->setName(typeName);
-    return _elt;
-  }
-  ANTCC_LOG_ERROR("antElementFactory::orderElement <%s> failed not found ",typeName);
-  return nullptr;
-}
-
-bool ElementFactory::registerGenerator(
-                        const char* typeName,
-                        const ElementGenerator& funcCreate)
-{
-  ANTCC_LOG_DEBUG("antElementFactory::registerGenerator %s",typeName);
-  return m_generators.insert(std::make_pair(typeName,funcCreate)).second;
-}
-
-}
diff --git a/src/xml/reqif/element_factory.h b/src/xml/reqif/element_factory.h
deleted file mode 100644 (file)
index 83c5eb7..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#pragma once
-#include <string>
-#include <unordered_map>
-#ifdef N_WIN32
-#ifdef BUILD_DLL
-#define DLL_INTERFACE __declspec(dllexport)
-#else
-#define DLL_INTERFACE __declspec(dllimport)
-#endif
-#else
-#define DLL_INTERFACE
-#endif
-namespace reqif {
-
-struct Element;
-typedef Element*(*ElementGenerator)(const char *_typeName);
-class ElementFactory
-{
-public:
-    DLL_INTERFACE static ElementFactory& get();
-    DLL_INTERFACE Element* orderElement(const char* typeName);
-    DLL_INTERFACE bool registerGenerator(
-                            const char* typeName,
-                            const ElementGenerator& funcCreate);
-private:
-    ElementFactory();
-    ElementFactory(const ElementFactory&);
-    ~ElementFactory();
-    std::unordered_map<std::string, ElementGenerator> m_generators;
-};
-
-template <typename T>
-class ElementFactoryRegistration
-{
-  private:
-    static Element *create(const char *_id)
-    {
-        return new T() ;
-    }
-  public:
-    ElementFactoryRegistration(const char *id) 
-    {
-      ElementFactory::get().registerGenerator(
-        id
-        ,ElementFactoryRegistration<T>::create );
-    }
-};
-
-template <typename T>
-class LibElementFactoryRegistration
-{
-  private:
-    static Element *create(const char *_name)
-    {
-        return new T(_name) ;
-    }
-  public:
-    LibElementFactoryRegistration(const char *id) 
-    {
-      ElementFactory::get().registerGenerator(
-        id
-        ,LibElementFactoryRegistration<T>::create );
-    }
-};
-
-/**
- * How to use registration
- * in antElements cpp file simply create an object
- * antElementFactoryRegistration<property> _Property("property");
- * should do the trick
- */
-} //end reqif
diff --git a/src/xml/reqif/parser_base.h b/src/xml/reqif/parser_base.h
new file mode 100644 (file)
index 0000000..b3042e7
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef ANTCC_PARSER_ELEMENTS_H
+#define ANTCC_PARSER_ELEMENTS_H
+#include <iostream>
+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 (file)
index 0000000..1ca3cf7
--- /dev/null
@@ -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 (file)
index 0000000..14d3c3d
--- /dev/null
@@ -0,0 +1,194 @@
+#ifndef REQIF_ELEMENT_H
+#define REQIF_ELEMENT_H
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+#include <antcc/config.h>
+#ifdef ANTCC_WITH_BOOST
+#include <boost/shared_ptr.hpp>
+#elif defined (ANTCC_WITH_AEB)
+#include <utils/aeb/shared_ptr.h>
+#endif
+#include <xml/element.h>
+
+namespace reqif {
+  class  project;
+  struct Location;
+
+#if 0
+namespace xml {
+
+    template <typename T>
+    struct element_traits {
+        typedef T                               element_type;
+#ifdef XSD_WITH_BOOST
+        typedef typename boost::shared_ptr<element_type> element_sptr;
+#elif defined(XSD_WITH_AEB)
+        typedef typename aeb::shared_ptr<element_type> element_sptr;
+#else
+        typedef typename std::shared_ptr<element_type> element_sptr;
+#endif
+        typedef typename std::vector<element_sptr>       element_sequence;
+    };
+    /// Usefulle template to create a static 
+    // array of all avaialable attributes for an element
+    template <typename T>
+    struct element_attributes {
+       const char *m_Name;
+       void (T::*m_Setter)(const std::string &_v);
+    };     
+
+    template <typename T,bool ns>
+    struct element {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::element_sptr t_sptr;
+        public:
+    };
+
+    template <typename T>
+    struct element<T,true > {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::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<<"<:"<<e.m_name;
+            e.m_content->serialize_attributes(os);
+            os<<">";
+            os<<*(e.m_content);
+            os<<"</:"<<e.m_name<<">";
+           return os;
+        };
+        t_sptr    m_content;
+        const char *m_name;
+    };
+    
+    template <typename T>
+    struct element<T,false> {
+        typedef typename element_traits<T>::element_type t_type;
+        typedef typename element_traits<T>::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<<"<"<<e.m_name;
+            e.m_content->serialize_attributes(os);
+            os<<">";
+            os<<*(e.m_content);
+            os<<"<"<<e.m_name<<">";
+           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<std::string,std::string> attrMap_type;
+            typedef std::map<std::string,std::string>::iterator attrMap_iterator;
+            typedef std::map<std::string,std::string>::const_iterator attrMap_const_iterator;
+            typedef typename xml::element_traits<Element>::element_type t_type;
+            typedef typename xml::element_traits<Element>::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<class C>
+            bool addAttribute(C *_this,struct xml::element_attributes<C> *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 (file)
index 0000000..12f1b0b
--- /dev/null
@@ -0,0 +1,865 @@
+#include <ios>
+#include <iostream>
+#include <antcc/config.h>
+#include <os/path.h>
+#include <os/file.h>
+#include <location.h>
+#include <parser_base.h>
+#include <logger.h>
+
+//#include <xml/element.h>
+#include <xml/reqif/reqif_element.h>
+#include <xml/reqif/reqif_elements_parser.h>
+#include <xml/element_factory.h>
+
+
+//#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 "<<name<<" val="<<val<<std::endl;
+         anyAttribute(ns,name,val);
+     }
+ }
+
+ /**
+ * Implement SimpleElement parsing function 
+ */
+
+void SimpleElement::_Characters(const std::string &val)
+{
+    if (! _CharactersImpl(val))
+         m_str+=val;
+}
+
+void SimpleElement::_Attribute(const std::string &ns,const std::string &name,const std::string &val)
+{
+    if (!this->AttributeImpl(ns,name,val))
+    {
+        anyAttribute(ns,name,val);
+        std::cout<<" SimpleElement::_Attribute unknown attr "<<name<<"\n";
+    } else {
+    }
+}
+
+void 
+SimpleElement::updateLocation(const antcc::Location &l)
+{
+    if (m_CurrentElement)
+    {
+        m_CurrentElement->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 "<<name<<std::endl;
+#endif
+           // Unexpectect element 
+           //this->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- : "<<name<<std::endl;
+#endif
+            }
+        }
+    }
+}
+
+
+void ComplexElement::_endElement(const std::string &ns,const std::string &name) 
+{
+    State &s(m_context.back());
+    std::string space;
+    ANTCC_PARSER_DEBUG("%sCplx(%0x)::_endElement 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 (m_context.back().m_depth==0)
+    {
+        State &ss(m_context[m_context.size()-2]);
+        if (--ss.m_depth > 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 ? "<<name<<std::endl;
+
+        } else
+        {
+            // Direct recursion
+            ANTCC_PARSER_DEBUG( "CplxE::_endElement %s 2 WARNING I pass by here Direct recursion: "
+                    ,name.c_str());
+            if (this == ss.m_parser.get())
+            {
+                ANTCC_PARSER_DEBUG( "CplxE::_endElement %s good this==ss.m_parser",name.c_str());
+                 
+                this->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"<<val<<" sz="<<m_context.size()<<"call parser@ "<<s.m_parser<<"\n";
+#endif
+            if (s.m_parser.get() == this) 
+            {
+              std::cerr<<"CplxE::_Characters ERROR: I have serious trouble treating -("<<val<<")"<<s.m_depth<<"\n";
+              if (!_CharactersImpl(val))
+              {
+                // Call any characters
+#ifdef PARSER_DEBUG_CHARATER
+          std::cout<<"CplxE::_Characters what to do? call any_characters :"<<val<<" depth="<<s.m_depth<<std::endl;
+#endif
+              }
+            } else
+              s.m_parser->_Characters(val);
+        } else {
+            std::cout<<"CplxE::_characters... what to do with char ("<<val<<") "<<m_context.size()<<" parser@="<<s.m_parser<<"\n";
+        }
+
+    } else {
+        if (!_CharactersImpl(val))
+        {
+          // Call any characters
+#ifdef PARSER_DEBUG_CHARATER
+    std::cout<<"CplxE::_Characters what to do? call any_characters :"<<val<<" depth="<<s.m_depth<<std::endl;
+#endif
+        }
+    }
+}
+            
+void 
+ComplexElement::updateLocation(const antcc::Location &l)
+{
+    State &s(m_context.back());
+    if (s.m_parser != NULL)
+    {
+        s.m_parser->updateLocation(l);
+    } else if (m_CurrentElement)
+    {
+        m_CurrentElement->setLocation(l);
+    }
+}
+
+ComplexElement::State::State() : m_any(0),m_depth(0),m_parser(0),m_data(0)
+{ 
+  //ANTCC_PARSER_DEBUG("State::State %d",m_depth);
+}
+
+ComplexElement::State::~State()
+{ 
+    //ANTCC_PARSER_DEBUG("State::~State %d",m_depth);
+    if (m_data)
+    {
+        ANTCC_PARSER_ERROR("State::~State error m_data != null %d",m_depth);
+    }
+}
+ComplexElement::State::State(const ComplexElement::State &p) 
+        : m_any(p.m_any),m_depth(p.m_depth),m_parser(p.m_parser),m_data(p.m_data)
+{
+        ANTCC_PARSER_DEBUG("State::State copy ctor depth=%d data=%0x"
+                    ,m_depth
+                    ,m_data
+                    );
+}
+// Local instance of parsers.
+//TargetParser gTargetParser;
+//TaskParser gTaskParser;
+
+/* Parser Implementations ...*/
+
+#define ROOT_PARSER(cls,start,end,attr) \
+cls :: cls(const cls &_c) : RootElement(_c.m_CurrentElement)                  \
+{ \
+  ANTCC_PARSER_DEBUG("%s::%s cp elt=%0x"                       \
+                    ,#cls                                      \
+                    ,#cls                                      \
+                    ,_c.m_CurrentElement                       \
+    );                                         \
+} \
+cls::cls(antcc::project *_project,reqif::Element *_elt)    \
+        : RootElement(_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 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<TargetParser>(new TargetParser(m_Project
+                       , reqif::ElementFactory::get().orderElement(name.c_str())
+                 ));
+} else if (name == "TOOL-EXTENSION" && ns.empty())
+{
+    s.m_parser = SHARED_PTR<DescriptionParser>(new DescriptionParser(m_Project
+                       , NULL)
+                   );
+} else if (name == "CORE-CONTENT" && ns.empty())
+{
+    s.m_parser = SHARED_PTR<CoreContentParser>(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<DescriptionParser>(new DescriptionParser(m_Project
+                           , reqif::ElementFactory::get().orderElement(name.c_str())
+                 ));
+    } else if (name == "exec" && ns.empty())
+    {
+      s.m_parser = SHARED_PTR<DescriptionParser>(new DescriptionParser(m_Project
+                           , reqif::ElementFactory::get().orderElement(name.c_str())
+                 ));
+    }
+    else
+    {
+      s.m_parser = SHARED_PTR<DescriptionParser>(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<DatatypesParser>(new DatatypesParser(m_Project
+                           , reqif::ElementFactory::get().orderElement(name.c_str())
+                 ));
+    }
+    else if (name == "SPEC-TYPES" && ns.empty())
+    {
+    } else
+    {
+      s.m_parser = SHARED_PTR<TypeParser>(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<DatatypeParser>(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<TypeParser>(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<SpecAttributesParser>(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<TypeParser>(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 (file)
index 0000000..c81c44a
--- /dev/null
@@ -0,0 +1,323 @@
+#ifndef REQIF_PARSER_PARSER_H
+#define REQIF_PARSER_PARSER_H
+#include <antcc/config.h>
+#include <xml/reqif/reqif_element.h>
+#include <vector>
+
+#include <stdlib.h>
+
+namespace reqif 
+{
+    class project;
+    namespace parser
+    {
+        template <typename T>
+        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: "<<name<<"\n";
+           };
+           virtual void endAnyElement(const std::string &ns,const std::string &name) {
+               std::cout<<"EmptyElement::end Any: "<<name<<"\n";
+           };
+           virtual void anyAttribute(const std::string &ns,const std::string &name,const std::string &val) {};
+
+            //
+            // Implementation start functions ....
+            //
+
+            virtual void post(std::string &m) {m.swap(m_str);};
+            virtual void post(int &v) {v = atoi(m_str.c_str());};
+            virtual void post(short &v) {v = atoi(m_str.c_str());};
+            virtual void post(unsigned long &v) {v = atoi(m_str.c_str());};
+            virtual void post(unsigned int &v) {v = atoi(m_str.c_str());};
+            virtual void post(unsigned short &v) {v = atoi(m_str.c_str());};
+            virtual void post(unsigned char &v) {v = atoi(m_str.c_str());};
+            /* byte */
+            virtual void post(signed char &v) {v = (signed char) atoi(m_str.c_str()); };
+            virtual void post(float &v) {v = atof(m_str.c_str());};
+            virtual void post(double &v) {v = atof(m_str.c_str());};
+            virtual void post(bool &v) {
+                if (m_str[0] == '0') {
+                  v = 0;
+                } else if (m_str[0] == '1') {
+                  v = 1;
+                } else if (!m_str.compare("true")) {
+                  v = 1;
+                } else if (!m_str.compare("false")) {
+                  v = 0;
+                } else {
+                  std::cerr<<"post(bool) with bad value:"<<m_str<<std::endl;
+                }
+            };
+            virtual reqif::Element *post() { return m_CurrentElement; };
+            //virtual void post(xsd::decimal &v) {v = atoi(m_str.c_str());};
+
+           //
+            // Called by document parse ...
+            //
+
+
+            virtual bool startElementImpl(const std::string &ns,const std::string &name,const std::string &type) {return false;};
+            virtual bool endElementImpl(const std::string &ns,const std::string &name) {return false;};
+            virtual bool AttributeImpl(const std::string &ns,const std::string &name,const std::string &val) {return false;};
+            virtual bool _CharactersImpl(const std::string &c) {return false;};
+//
+
+            virtual void _startElement(const std::string &ns,const std::string &name,const std::string &type){startElementImpl(ns,name,type);};
+            virtual void _endElement(const std::string &ns,const std::string &name) {endElementImpl(ns,name);};
+
+            virtual void _Characters(const std::string &c) {if (!_CharactersImpl(c)) m_str+=c;};
+            virtual void _Attribute(const std::string &ns,const std::string &name,const std::string &value) ;
+            protected:
+            /** Characters in element */
+            std::string        m_str;
+           reqif::Element     *m_CurrentElement;
+        };
+
+        /**
+         * \brief
+         *
+         * \author EBERSOLD Andre
+         * \date
+         * \param
+         *
+         */
+        class SimpleElement : public EmptyElement
+        {
+            public:
+            SimpleElement(reqif::Element *_elt=NULL)
+                   : EmptyElement(_elt) {};
+            virtual ~SimpleElement() { };
+            private:
+            virtual void pre() {this->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<reqif::parser::ParserBase> m_parser;
+                    reqif::Element         *m_data;  /* To solve recurse issue ....*/
+                };
+                std::vector<State> 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<reqif::parser::ParserBase> m_parser;
+                    reqif::Element            *m_data;  /* To solve recurse issue ....*/
+                };
+                std::vector<State> 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 <xml/parser/parsers.h.inc>
+#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<cls> 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 <xml/reqif/parsers.h.inc>
+#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 (file)
index 0000000..f320874
--- /dev/null
@@ -0,0 +1,306 @@
+#include <ios>
+#include <iostream>
+#include <antcc/config.h>
+#include <os/path.h>
+#include <os/file.h>
+#include <location.h>
+#include <parser_base.h>
+#include <logger.h>
+#include <ant_elements.h>
+#include <ant_elements_parser.h>
+#include <ant_element_factory.h>
+
+#include <project.h>
+#include <projectComponent.h>
+
+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 "<<name<<std::endl;
+#endif
+           // Unexpectect element 
+           //this->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- : "<<name<<std::endl;
+#endif
+            }
+        }
+    }
+}
+
+
+void RootElement::_endElement(const std::string &ns,const std::string &name) 
+{
+    State &s(m_context.back());
+    std::string space;
+    ANTCC_PARSER_DEBUG("%sCplx(%0x)::_endElement 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 (m_context.back().m_depth==0)
+    {
+        State &ss(m_context[m_context.size()-2]);
+        if (--ss.m_depth > 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 ? "<<name<<std::endl;
+
+        } else
+        {
+            // Direct recursion
+            ANTCC_PARSER_DEBUG( "CplxE::_endElement %s 2 WARNING I pass by here Direct recursion: "
+                    ,name.c_str());
+            if (this == ss.m_parser.get())
+            {
+                ANTCC_PARSER_DEBUG( "CplxE::_endElement %s good this==ss.m_parser",name.c_str());
+                 
+                this->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"<<val<<" sz="<<m_context.size()<<"call parser@ "<<s.m_parser<<"\n";
+#endif
+            if (s.m_parser.get() == this) 
+            {
+              std::cerr<<"CplxE::_Characters ERROR: I have serious trouble treating -("<<val<<")"<<s.m_depth<<"\n";
+              if (!_CharactersImpl(val))
+              {
+                // Call any characters
+#ifdef PARSER_DEBUG_CHARATER
+          std::cout<<"CplxE::_Characters what to do? call any_characters :"<<val<<" depth="<<s.m_depth<<std::endl;
+#endif
+              }
+            } else
+              s.m_parser->_Characters(val);
+        } else {
+            std::cout<<"CplxE::_characters... what to do with char ("<<val<<") "<<m_context.size()<<" parser@="<<s.m_parser<<"\n";
+        }
+
+    } else {
+        if (!_CharactersImpl(val))
+        {
+          // Call any characters
+#ifdef PARSER_DEBUG_CHARATER
+    std::cout<<"CplxE::_Characters what to do? call any_characters :"<<val<<" depth="<<s.m_depth<<std::endl;
+#endif
+        }
+    }
+}
+            
+void 
+RootElement::updateLocation(const antcc::Location &l)
+{
+    State &s(m_context.back());
+    if (s.m_parser != NULL)
+    {
+        s.m_parser->updateLocation(l);
+    } else if (m_CurrentElement)
+    {
+        m_CurrentElement->setLocation(l);
+    }
+}
+
+RootElement::State::State() : m_any(0),m_depth(0),m_parser(0),m_data(0)
+{ 
+  //ANTCC_PARSER_DEBUG("State::State %d",m_depth);
+}
+
+RootElement::State::~State()
+{ 
+    //ANTCC_PARSER_DEBUG("State::~State %d",m_depth);
+    if (m_data)
+    {
+        ANTCC_PARSER_ERROR("State::~State error m_data != null %d",m_depth);
+    }
+}
+RootElement::State::State(const RootElement::State &p) 
+        : m_any(p.m_any),m_depth(p.m_depth),m_parser(p.m_parser),m_data(p.m_data)
+{
+        ANTCC_PARSER_DEBUG("State::State copy ctor depth=%d data=%0x"
+                    ,m_depth
+                    ,m_data
+                    );
+}
+
+}
+}