From: Andre EBERSOLD Date: Fri, 3 Feb 2023 14:48:49 +0000 (+0100) Subject: New developments ahead X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;h=9bb452315634715d4f44b671d6a9510ffb8ccdca;p=antcc.git New developments ahead Started code for http element support Started source tree for reqif parsing --- diff --git a/src/tasks/http.cpp b/src/tasks/http.cpp new file mode 100644 index 0000000..2c5b19a --- /dev/null +++ b/src/tasks/http.cpp @@ -0,0 +1,90 @@ +#include +#include + + +/** + * Attributes supported by exec + */ +antcc::xml::element_attributes http::gAttr[] = +{ + {"method",&http::setMethod} + , {"url",&http::setUrl} + , {"status",&http::setStatus} + , {"contentType",&http::setContentType} + , {NULL,NULL} +}; + + +http::http() +{ +} + +http::~http() +{ +} + +antcc::task::eStatus +http::execute() +{ + eStatus l_return = EXEC_FAILED; + std::string _name; + std::string l_unless; + if (getResolvedAttribute("method",l_unless)) + { + std::string l_prop; + + if (getProject().getProperty(l_unless,l_prop)) + { + l_return = EXEC_SUCCESS; + + } else { + getProject().log(*this,eINFO,"unless %s ",l_prop.c_str()); + } + } + if ( (l_return == EXEC_FAILED) && getResolvedAttribute("message",_name)) + { + getProject().log(*this,eINFO,_name); + } else + { + ANTCC_LOG_DEBUG("http::%s success condition is met" + ,__FUNCTION__); + } + return l_return; +} + +/// +bool +http::addAttribute(const std::string &_name,const std::string &_v) +{ + bool l_ok = false; + if ( (l_ok = antElement::addAttribute(this,http::gAttr,_name,_v)) == true) + { + antElement::addAttribute(_name,_v); + } + return l_ok; +} +/// +void +http::setMethod(const std::string &s) +{ + m_Method = s; +} +/// +void +http::setUrl(const std::string &s) +{ + m_Url = s; +} +/// +void +http::setContent(const std::string &s) +{ + m_Content = s; +} +/// +void +http::setContentType(const std::string &s) +{ + m_ContentType = s; +} + diff --git a/src/tasks/http.h b/src/tasks/http.h new file mode 100644 index 0000000..2220b32 --- /dev/null +++ b/src/tasks/http.h @@ -0,0 +1,44 @@ +#ifndef __TASK_HTTP_H__ +#define __TASK_HTTP_H__ + + +/** + * @brief This tag sets one or multiple proproties for the + * project. The properties once set cannot be changed anymore. + * + */ +class http : public antcc::task +{ + public: + /// + http() ; + /// + virtual ~http(); + /// + virtual eStatus execute() ; + private: + template + friend struct element_attributes; + /// + /// + virtual bool addAttribute(const std::string &_name,const std::string &_v) ; + /// + void setUrl(const std::string &s); + /// + void setMethod(const std::string &s); + /// + void setContent(const std::string &s); + /// + void setContentType(const std::string &s); + private: + std::string m_Content; + std::string m_ContentType; + std::string m_Method; + std::string m_Url; + static ::antcc::xml::element_attributes gAttr []; +}; + + + +#endif +/* vim:et:sw=4:ts=4:list: */ diff --git a/src/xml/reqif/CMakeLists.txt b/src/xml/reqif/CMakeLists.txt new file mode 100644 index 0000000..9a68836 --- /dev/null +++ b/src/xml/reqif/CMakeLists.txt @@ -0,0 +1,73 @@ +PROJECT(libreqifparser) + +INCLUDE_DIRECTORIES(${libreqifparser_SOURCE_DIR}) +INCLUDE_DIRECTORIES(/usr/local/include) +# Check with BOOTSTRAP_expat too +IF(NOT WIN32) + FIND_PACKAGE(EXPAT REQUIRED) +ELSE(NOT WIN32) + # C:\Tools\Expat 2.2.10\Source\lib + SET(EXPAT_INCLUDE_DIR "c:/Tools/Expat 2.2.10/Source/lib" CACHE STRING "Expat include dir") + SET(EXPAT_LIBRARY "c:/Tools/Expat 2.2.10/Bin/libexpat.lib" CACHE STRING "Expat library") + INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR}) +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 + ) + +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 + ARCHIVE + DESTINATION lib + 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 new file mode 100644 index 0000000..2443b3a --- /dev/null +++ b/src/xml/reqif/element_factory.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include + +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 new file mode 100644 index 0000000..83c5eb7 --- /dev/null +++ b/src/xml/reqif/element_factory.h @@ -0,0 +1,79 @@ +#pragma once +#include +#include + +#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 m_generators; +}; + +template +class ElementFactoryRegistration +{ + private: + static Element *create(const char *_id) + { + return new T() ; + } + public: + ElementFactoryRegistration(const char *id) + { + ElementFactory::get().registerGenerator( + id + ,ElementFactoryRegistration::create ); + } +}; + +template +class LibElementFactoryRegistration +{ + private: + static Element *create(const char *_name) + { + return new T(_name) ; + } + public: + LibElementFactoryRegistration(const char *id) + { + ElementFactory::get().registerGenerator( + id + ,LibElementFactoryRegistration::create ); + } +}; + +/** + * How to use registration + * in antElements cpp file simply create an object + * antElementFactoryRegistration _Property("property"); + * should do the trick + */ +} //end reqif