diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 6322164..68d519f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -51,7 +51,7 @@ jobs: if: matrix.Repo != '' - name: Add packages run: | - sudo apt-get --yes install libxerces-c-dev libssl-dev ${{ matrix.PackageDeps }} + sudo apt-get --yes install libxerces-c-dev ${{ matrix.PackageDeps }} - name: create $ACE_ROOT/ace/config.h run: | '#include "ace/config-linux.h"' > ${env:ACE_ROOT}/ace/config.h @@ -59,7 +59,6 @@ jobs: - name: create $ACE_ROOT/include/makeinclude/platform_macros.GNU run: | 'xerces3=1' > ${env:ACE_ROOT}/include/makeinclude/platform_macros.GNU - 'ssl=1' >> ${env:ACE_ROOT}/include/makeinclude/platform_macros.GNU 'xsc=1' >> ${env:ACE_ROOT}/include/makeinclude/platform_macros.GNU shell: pwsh - name: add optional optional macros @@ -106,6 +105,17 @@ jobs: Pop-Location } shell: pwsh + - name: Run read-only mode compatibility tests + run: | + Push-Location ${env:XSC_ROOT}/Tests/ReadOnly + try { + perl run_test.pl + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + finally { + Pop-Location + } + shell: pwsh - name: Build XSC generated schema tests run: | Push-Location ${env:XSC_ROOT}/Tests @@ -117,3 +127,14 @@ jobs: Pop-Location } shell: pwsh + - name: Run DanceX11 generated-code test + run: | + Push-Location ${env:XSC_ROOT}/Tests/DanceX11 + try { + perl run_test.pl + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + finally { + Pop-Location + } + shell: pwsh diff --git a/.gitignore b/.gitignore index 65aaa53..445c521 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,8 @@ Debug/ Release/ *.obj *.lib -*.dll \ No newline at end of file +*.dll + +# Generated example output kept local. +/Examples/Recursive/recursive.cpp +/Examples/Recursive/recursive.hpp diff --git a/CCF/CodeGenerationKit/IndentationCxx.hpp b/CCF/CodeGenerationKit/IndentationCxx.hpp index 3e2c88d..a4b087d 100644 --- a/CCF/CodeGenerationKit/IndentationCxx.hpp +++ b/CCF/CodeGenerationKit/IndentationCxx.hpp @@ -44,7 +44,9 @@ namespace Indentation position_ (0), paren_balance_ (0), spaces_ (2), - construct_ (OTHER) + construct_ (OTHER), + last_non_whitespace_ (0), + inline_initializer_ (false) { indentation_.push (0); } @@ -94,6 +96,16 @@ namespace Indentation if (this->construct_ != CXX_COMMENT && this->construct_ != STRING_LITERAL) { + if (this->last_non_whitespace_ == '=' || + this->last_non_whitespace_ == '_') + { + this->output_indentation (); + result = this->write (c); + ++ this->position_; + this->inline_initializer_ = true; + break; + } + // Make sure there is a new line in the buffer. We then need to // move the correct position on the newline. this->ensure_new_line (); @@ -114,6 +126,15 @@ namespace Indentation case '}': if (!(this->construct_ == CXX_COMMENT || this->construct_ == STRING_LITERAL)) { + if (this->inline_initializer_) + { + this->output_indentation (); + result = this->write (c); + ++ this->position_; + this->inline_initializer_ = false; + break; + } + // Remove the current indentation value, if it exists. if (this->indentation_.size () > 1) this->indentation_.pop (); @@ -138,8 +159,7 @@ namespace Indentation this->hold_.push_back (c); - // Add double newline after '}'. - this->hold_.push_back ('\n'); + // Add a newline after '}'. this->hold_.push_back ('\n'); // Set position to the start of the line. @@ -319,6 +339,9 @@ namespace Indentation // Update the position. ++ this->position_; } + + if (c != ' ' && c != '\t' && c != '\n' && c != '\r') + this->last_non_whitespace_ = c; } catch (const Full &) { @@ -431,6 +454,12 @@ namespace Indentation /// The type of construct. Construct construct_; + /// Last non-whitespace input character. + char_type last_non_whitespace_; + + /// Whether the current brace pair is an inline initializer. + bool inline_initializer_; + /// Type definition of the holding queue. using Hold = std::deque; diff --git a/Examples/Recursive/recursive.cpp b/Examples/Recursive/recursive.cpp deleted file mode 100644 index 3ee96ee..0000000 --- a/Examples/Recursive/recursive.cpp +++ /dev/null @@ -1,637 +0,0 @@ -#include "recursive.hpp" - -#include "ace/ace_wchar.h" -#include "ace/Null_Mutex.h" -#include "ace/TSS_T.h" -#include "ace/Singleton.h" - -namespace Recursive -{ - // Element - - Element::Element (value_container_type const& value__, - long_container_type const& long___) - : ::XSCRT::Type () - , value_ (value__) - , long__ (long___) - { - } - - Element::Element (Element const& s) : - ::XSCRT::Type (s) - , value_ (s.value_) - , long__ (s.long__) - , el_ (s.el_) - { - } - - Element& - Element::operator= (Element const& s) - { - if (&s != this) - { - value_ = s.value_; - - long__ = s.long__; - - el_ = s.el_; - } - - return *this; - } - - - // Element - Element::value_iterator Element:: - begin_value () - { - return value_.begin (); - } - - Element::value_iterator Element:: - end_value () - { - return value_.end (); - } - - Element::value_const_iterator Element:: - begin_value () const - { - return value_.begin (); - } - - Element::value_const_iterator Element:: - end_value () const - { - return value_.end (); - } - - void Element:: - add_value (Element::value_value_type const& e) - { - value_.push_back (e); - } - - size_t Element:: - count_value(void) const - { - return value_.size (); - } - - // Element - Element::long_iterator Element:: - begin_long () - { - return long__.begin (); - } - - Element::long_iterator Element:: - end_long () - { - return long__.end (); - } - - Element::long_const_iterator Element:: - begin_long () const - { - return long__.begin (); - } - - Element::long_const_iterator Element:: - end_long () const - { - return long__.end (); - } - - void Element:: - add_long (Element::long_value_type const& e) - { - long__.push_back (e); - } - - size_t Element:: - count_long(void) const - { - return long__.size (); - } - - // Element - Element::el_iterator Element:: - begin_el () - { - return el_.begin (); - } - - Element::el_iterator Element:: - end_el () - { - return el_.end (); - } - - Element::el_const_iterator Element:: - begin_el () const - { - return el_.begin (); - } - - Element::el_const_iterator Element:: - end_el () const - { - return el_.end (); - } - - void Element:: - add_el (Element::el_value_type const& e) - { - el_.push_back (e); - } - - size_t Element:: - count_el(void) const - { - return el_.size (); - } -} - -namespace Recursive -{ - // Element - - Element:: - Element (::XSCRT::XML::Element const& e) - :Base (e) - { - - ::XSCRT::Parser p (e); - - while (p.more_elements ()) - { - ::XSCRT::XML::Element e (p.next_element ()); - std::basic_string n (::XSCRT::XML::uq_name (e.name ())); - - if (n == ACE_TEXT("value")) - { - value_value_type t (new ::XMLSchema::string (e)); - add_value (t); - } - - else if (n == ACE_TEXT("long")) - { - long_value_type t (new ::XMLSchema::long_ (e)); - add_long (t); - } - - else if (n == ACE_TEXT("el")) - { - el_value_type t (new ::Recursive::Element (e)); - add_el (t); - } - - else - { - } - } - } -} - -namespace Recursive -{ - namespace reader - { - ::Recursive::Element - el (xercesc::DOMDocument const* d) - { - // Initiate our Singleton as an ACE_TSS object (ensures thread - // specific storage - ID_Map::TSS_ID_Map* TSS_ID_Map (ACE_Singleton::instance()); - xercesc::DOMElement* dom_element = d->getDocumentElement (); - if (!dom_element) - { - throw 1; - } - - ::XSCRT::XML::Element e (dom_element); - if (e.name () == ACE_TEXT("el")) - { - ::Recursive::Element r (e); - - (*TSS_ID_Map)->resolve_idref(); - - return r; - } - - else - { - throw 1; - } - } - } -} - -#include "ace/XML_Utils/XMLSchema/TypeInfo.hpp" - -namespace Recursive -{ - namespace - { - ::XMLSchema::TypeInfoInitializer < ACE_TCHAR > XMLSchemaTypeInfoInitializer_ (::XSCRT::extended_type_info_map ()); - - struct ElementTypeInfoInitializer - { - ElementTypeInfoInitializer () - { - ::XSCRT::TypeId id (typeid (::Recursive::Element)); - ::XSCRT::ExtendedTypeInfo nf (id); - - nf.add_base (::XSCRT::ExtendedTypeInfo::Access::public_, false, typeid (::XSCRT::Type)); - ::XSCRT::extended_type_info_map ().insert (std::make_pair (id, nf)); - } - }; - - ElementTypeInfoInitializer ElementTypeInfoInitializer_; - } -} - -namespace Recursive -{ - namespace Traversal - { - // Element - - void Element:: - traverse (Type& o) - { - pre (o); - value (o); - long_ (o); - el (o); - post (o); - } - - void Element:: - traverse (Type const& o) - { - pre (o); - value (o); - long_ (o); - el (o); - post (o); - } - - void Element:: - pre (Type&) - { - } - - void Element:: - pre (Type const&) - { - } - - void Element:: - value (Type& o) - { - // VC6 anathema strikes again - ::Recursive::Element::value_iterator b (o.begin_value()), e (o.end_value()); - - if (b != e) - { - value_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) value_next (o); - } - - value_post (o); - } - } - - void Element:: - value (Type const& o) - { - // VC6 anathema strikes again - ::Recursive::Element::value_const_iterator b (o.begin_value()), e (o.end_value()); - - if (b != e) - { - value_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) value_next (o); - } - - value_post (o); - } - } - - void Element:: - value_pre (Type&) - { - } - - void Element:: - value_pre (Type const&) - { - } - - void Element:: - value_next (Type&) - { - } - - void Element:: - value_next (Type const&) - { - } - - void Element:: - value_post (Type&) - { - } - - void Element:: - value_post (Type const&) - { - } - - void Element:: - long_ (Type& o) - { - // VC6 anathema strikes again - ::Recursive::Element::long_iterator b (o.begin_long()), e (o.end_long()); - - if (b != e) - { - long_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) long_next (o); - } - - long_post (o); - } - } - - void Element:: - long_ (Type const& o) - { - // VC6 anathema strikes again - ::Recursive::Element::long_const_iterator b (o.begin_long()), e (o.end_long()); - - if (b != e) - { - long_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) long_next (o); - } - - long_post (o); - } - } - - void Element:: - long_pre (Type&) - { - } - - void Element:: - long_pre (Type const&) - { - } - - void Element:: - long_next (Type&) - { - } - - void Element:: - long_next (Type const&) - { - } - - void Element:: - long_post (Type&) - { - } - - void Element:: - long_post (Type const&) - { - } - - void Element:: - el (Type& o) - { - // VC6 anathema strikes again - ::Recursive::Element::el_iterator b (o.begin_el()), e (o.end_el()); - - if (b != e) - { - el_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) el_next (o); - } - - el_post (o); - } - - else el_none (o); - } - - void Element:: - el (Type const& o) - { - // VC6 anathema strikes again - ::Recursive::Element::el_const_iterator b (o.begin_el()), e (o.end_el()); - - if (b != e) - { - el_pre (o); - for (; b != e;) - { - dispatch (*(*b)); - if (++b != e) el_next (o); - } - - el_post (o); - } - - else el_none (o); - } - - void Element:: - el_pre (Type&) - { - } - - void Element:: - el_pre (Type const&) - { - } - - void Element:: - el_next (Type&) - { - } - - void Element:: - el_next (Type const&) - { - } - - void Element:: - el_post (Type&) - { - } - - void Element:: - el_post (Type const&) - { - } - - void Element:: - el_none (Type&) - { - } - - void Element:: - el_none (Type const&) - { - } - - void Element:: - post (Type&) - { - } - - void Element:: - post (Type const&) - { - } - } -} - -namespace Recursive -{ - namespace Writer - { - // Element - Element:: - Element (::XSCRT::XML::Element& e) - : ::XSCRT::Writer (e) - { - } - - Element:: - Element () - { - } - - void Element:: - traverse (Type const& o) - { - Traversal::Element::traverse (o); - } - - void Element:: - value_pre (Type const&) - { - push_ (::XSCRT::XML::Element (ACE_TEXT("value"), top_ ())); - } - - void Element:: - value_next (Type const& o) - { - value_post (o); - value_pre (o); - } - - void Element:: - value_post (Type const&) - { - pop_ (); - } - - void Element:: - long_pre (Type const&) - { - push_ (::XSCRT::XML::Element (ACE_TEXT("long"), top_ ())); - } - - void Element:: - long_next (Type const& o) - { - long_post (o); - long_pre (o); - } - - void Element:: - long_post (Type const&) - { - pop_ (); - } - - void Element:: - el_pre (Type const&) - { - push_ (::XSCRT::XML::Element (ACE_TEXT("el"), top_ ())); - } - - void Element:: - el_next (Type const& o) - { - el_post (o); - el_pre (o); - } - - void Element:: - el_post (Type const&) - { - pop_ (); - } - } -} - -namespace Recursive -{ - namespace writer - { - void - el (::Recursive::Element const& s, xercesc::DOMDocument* d) - { - xercesc::DOMElement* dom_element = d->getDocumentElement (); - if (!dom_element) - { - throw 1; - } - - ::XSCRT::XML::Element e (dom_element); - if (e.name () != ACE_TEXT ("el")) - { - throw 1; - } - - struct W : virtual ::Recursive::Writer::Element, - virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::string< ACE_TCHAR >, ACE_TCHAR >, - virtual ::XMLSchema::Writer::FundamentalType< ::XMLSchema::long_, ACE_TCHAR >, - virtual ::XSCRT::Writer - { - explicit W (::XSCRT::XML::Element& e) - : ::XSCRT::Writer (e) - { - } - }; - - W w (e); - w.dispatch (s); - } - } -} - diff --git a/Examples/Recursive/recursive.hpp b/Examples/Recursive/recursive.hpp deleted file mode 100644 index d1d2180..0000000 --- a/Examples/Recursive/recursive.hpp +++ /dev/null @@ -1,319 +0,0 @@ -#ifndef RECURSIVE_HPP -#define RECURSIVE_HPP - -// Forward declarations. -namespace Recursive -{ - class Element; -} - -#include -#include -#include -#include "ace/XML_Utils/XMLSchema/Types.hpp" -#include "ace/XML_Utils/XMLSchema/id_map.hpp" -#include "ace/Refcounted_Auto_Ptr.h" -#include "ace/Null_Mutex.h" -#include "ace/ace_wchar.h" - -namespace Recursive -{ - class Element : public ::XSCRT::Type - { - typedef ::XSCRT::Type Base; - - public: - typedef ACE_Refcounted_Auto_Ptr < ::Recursive::Element, ACE_Null_Mutex> _ptr; - - // value - public: - typedef ACE_Refcounted_Auto_Ptr < ::XMLSchema::string, ACE_Null_Mutex> value_value_type; - typedef std::list value_container_type; - typedef value_container_type::iterator value_iterator; - typedef value_container_type::const_iterator value_const_iterator; - value_iterator begin_value (); - value_iterator end_value (); - value_const_iterator begin_value () const; - value_const_iterator end_value () const; - void add_value (value_value_type const&); - size_t count_value () const; - - protected: - value_container_type value_; - - // long - public: - typedef ACE_Refcounted_Auto_Ptr < ::XMLSchema::long_, ACE_Null_Mutex> long_value_type; - typedef std::list long_container_type; - typedef long_container_type::iterator long_iterator; - typedef long_container_type::const_iterator long_const_iterator; - long_iterator begin_long (); - long_iterator end_long (); - long_const_iterator begin_long () const; - long_const_iterator end_long () const; - void add_long (long_value_type const&); - size_t count_long () const; - - protected: - long_container_type long__; - - // el - public: - typedef ACE_Refcounted_Auto_Ptr < ::Recursive::Element, ACE_Null_Mutex> el_value_type; - typedef std::list el_container_type; - typedef el_container_type::iterator el_iterator; - typedef el_container_type::const_iterator el_const_iterator; - el_iterator begin_el (); - el_iterator end_el (); - el_const_iterator begin_el () const; - el_const_iterator end_el () const; - void add_el (el_value_type const&); - size_t count_el () const; - - protected: - el_container_type el_; - - public: - Element (value_container_type const& value__, - long_container_type const& long___); - - explicit Element (::XSCRT::XML::Element const&); - Element (Element const& s); - Element& operator= (Element const& s); - }; -} - -namespace Recursive -{ - namespace reader - { - ::Recursive::Element - el (xercesc::DOMDocument const*); - } -} - -#include "ace/XML_Utils/XMLSchema/Traversal.hpp" - -namespace Recursive -{ - namespace Traversal - { - struct Element : ::XMLSchema::Traversal::Traverser< ::Recursive::Element > - { - virtual void - traverse (Type&); - - virtual void - traverse (Type const&); - - virtual void - pre (Type&); - - virtual void - pre (Type const&); - - virtual void - value (Type&); - - virtual void - value (Type const&); - - virtual void - value_pre (Type&); - - virtual void - value_pre (Type const&); - - virtual void - value_next (Type&); - - virtual void - value_next (Type const&); - - virtual void - value_post (Type&); - - virtual void - value_post (Type const&); - - virtual void - long_ (Type&); - - virtual void - long_ (Type const&); - - virtual void - long_pre (Type&); - - virtual void - long_pre (Type const&); - - virtual void - long_next (Type&); - - virtual void - long_next (Type const&); - - virtual void - long_post (Type&); - - virtual void - long_post (Type const&); - - virtual void - el (Type&); - - virtual void - el (Type const&); - - virtual void - el_pre (Type&); - - virtual void - el_pre (Type const&); - - virtual void - el_next (Type&); - - virtual void - el_next (Type const&); - - virtual void - el_post (Type&); - - virtual void - el_post (Type const&); - - virtual void - el_none (Type&); - - virtual void - el_none (Type const&); - - virtual void - post (Type&); - - virtual void - post (Type const&); - }; - } -} - -#include "ace/XML_Utils/XMLSchema/Writer.hpp" - -namespace Recursive -{ - namespace Writer - { - struct Element : Traversal::Element, - virtual ::XSCRT::Writer - { - typedef ::Recursive::Element Type; - explicit Element (::XSCRT::XML::Element&); - - virtual void - traverse (Type &o) - { - this->traverse (const_cast (o)); - } - - virtual void - traverse (Type const&); - - virtual void - value_pre (Type &o) - { - this->value_pre (const_cast (o)); - } - - virtual void - value_pre (Type const&); - - virtual void - value_next (Type &o) - { - this->value_next (const_cast (o)); - } - - virtual void - value_next (Type const&); - - virtual void - value_post (Type &o) - { - this->value_post (const_cast (o)); - } - - virtual void - value_post (Type const&); - - virtual void - long_pre (Type &o) - { - this->long_pre (const_cast (o)); - } - - virtual void - long_pre (Type const&); - - virtual void - long_next (Type &o) - { - this->long_next (const_cast (o)); - } - - virtual void - long_next (Type const&); - - virtual void - long_post (Type &o) - { - this->long_post (const_cast (o)); - } - - virtual void - long_post (Type const&); - - virtual void - el_pre (Type &o) - { - this->el_pre (const_cast (o)); - } - - virtual void - el_pre (Type const&); - - virtual void - el_next (Type &o) - { - this->el_next (const_cast (o)); - } - - virtual void - el_next (Type const&); - - virtual void - el_post (Type &o) - { - this->el_post (const_cast (o)); - } - - virtual void - el_post (Type const&); - - protected: - Element (); - }; - } -} - -namespace Recursive -{ - namespace writer - { - void - el (::Recursive::Element const&, xercesc::DOMDocument*); - } -} - -#endif // RECURSIVE_HPP diff --git a/Tests/Abstract/abstract.mpc b/Tests/Abstract/abstract.mpc index 452cdce..3d206a0 100644 --- a/Tests/Abstract/abstract.mpc +++ b/Tests/Abstract/abstract.mpc @@ -1,6 +1,7 @@ project (xsc_test_abstract): xscdefaults { requires += xsc custom_only = 1 + xscflags += --cxx-generate-cdr-writer-types XSC_Files { abstract.xsd } @@ -10,8 +11,10 @@ project (xsc_test_abstract): xscdefaults { project (xsc_test_abstract_generated): xscrt { after += xsc_test_abstract + includes += $(ACE_ROOT)/ace/XML_Utils Source_Files { abstract.cpp + abstract_api.cpp } } diff --git a/Tests/Abstract/abstract.xsd b/Tests/Abstract/abstract.xsd index 5bfa85b..ba5ba77 100644 --- a/Tests/Abstract/abstract.xsd +++ b/Tests/Abstract/abstract.xsd @@ -14,6 +14,13 @@ + + + + + + + @@ -32,4 +39,4 @@ - \ No newline at end of file + diff --git a/Tests/Abstract/abstract_api.cpp b/Tests/Abstract/abstract_api.cpp new file mode 100644 index 0000000..4747ae0 --- /dev/null +++ b/Tests/Abstract/abstract_api.cpp @@ -0,0 +1,15 @@ +#include "abstract.hpp" + +#include + +using StudentString = ::XMLSchema::string; +using StudentWithoutAdditionalFields = + ::XSC::Tests::StudentWithoutAdditionalFields; + +static_assert (std::is_constructible_v< + StudentWithoutAdditionalFields, + StudentString const&, + StudentString const&, + StudentString const&>); +static_assert (!std::is_default_constructible_v< + StudentWithoutAdditionalFields>); diff --git a/Tests/DanceX11/README.md b/Tests/DanceX11/README.md index bf01aca..8d3f833 100644 --- a/Tests/DanceX11/README.md +++ b/Tests/DanceX11/README.md @@ -4,4 +4,6 @@ This directory archives the XSD inputs listed in the `DANCEX11_XSC_XML_Generatio project in [DanceX11's config-handler build](https://github.com/RemedyIT/dancex11/blob/master/tools/config_handlers/config_handlers.mpc). They provide a regression corpus for XSC generation and C++17 compilation. The schemas were imported from `etc/schema` in the DanceX11 repository; no generated -C++ is checked in here. +C++ is checked in here. The MPC test explicitly requests C++17 output and +generates writer types. Its runtime test verifies that copy-assigning an unset +optional member clears a previously set value. diff --git a/Tests/DanceX11/dancex11.mpc b/Tests/DanceX11/dancex11.mpc index fe14888..a621558 100644 --- a/Tests/DanceX11/dancex11.mpc +++ b/Tests/DanceX11/dancex11.mpc @@ -4,7 +4,9 @@ project (xsc_test_dancex11): xscdefaults { requires += xsc custom_only = 1 + xscflags += --cxx-cpp17 xscflags += --cxx-char-type char + xscflags += --cxx-generate-writer-types xscflags += --search-path . XSC_Files { @@ -42,3 +44,65 @@ project (xsc_test_dancex11_generated): xscrt { toplevel.cpp } } + +project (xsc_test_dancex11_readonly): xscdefaults { + requires += xsc + custom_only = 1 + + Modify_Custom (XSC) { + source_outputext = .readonly.cpp, + header_outputext = .readonly.hpp, + } + + xscflags += --cxx-char-type char + xscflags += --search-path . + xscflags += --cxx-read-only + xscflags += --cxx-header-suffix .readonly.hpp + xscflags += --cxx-source-suffix .readonly.cpp + + XSC_Files { + Basic_Deployment_Data.xsd + Deployment.xsd + XMI.xsd + ccd.xsd + cdd.xsd + cdp.xsd + cid.xsd + cpd.xsd + iad.xsd + pcd.xsd + toplevel.xsd + } + + Source_Files { + } +} + +project (xsc_test_dancex11_readonly_generated): xscrt { + after += xsc_test_dancex11_readonly + + Source_Files { + Basic_Deployment_Data.readonly.cpp + Deployment.readonly.cpp + XMI.readonly.cpp + ccd.readonly.cpp + cdd.readonly.cpp + cdp.readonly.cpp + cid.readonly.cpp + cpd.readonly.cpp + iad.readonly.cpp + pcd.readonly.cpp + toplevel.readonly.cpp + readonly_api.cpp + } +} + +project (xsc_test_dancex11_optional_copy): xscrt { + after += xsc_test_dancex11_generated + libs += CXX IDL + + Source_Files { + Basic_Deployment_Data.cpp + optional_copy.cpp + } +} diff --git a/Tests/DanceX11/optional_copy.cpp b/Tests/DanceX11/optional_copy.cpp new file mode 100644 index 0000000..523a2c8 --- /dev/null +++ b/Tests/DanceX11/optional_copy.cpp @@ -0,0 +1,20 @@ +#include "Basic_Deployment_Data.hpp" + +int +main () +{ + Deployment::DataValue sequence; + Deployment::DataValue sequence_copy (sequence); + sequence_copy = sequence; + + Deployment::IdRef destination; + XMLSchema::string href ("urn:destination"); + destination.href (href); + if (destination.href_if_set () == nullptr) + return 1; + + Deployment::IdRef source; + destination = source; + + return destination.href_if_set () != nullptr; +} diff --git a/Tests/DanceX11/readonly_api.cpp b/Tests/DanceX11/readonly_api.cpp new file mode 100644 index 0000000..ca417ee --- /dev/null +++ b/Tests/DanceX11/readonly_api.cpp @@ -0,0 +1,18 @@ +#include "toplevel.readonly.hpp" + +#include +#include +#include + +namespace +{ + using TopLevel = Deployment::TopLevelPackageDescription; + using Package = Deployment::PackageConfiguration; + using Packages = TopLevel::package_container_type; + + static_assert (std::is_same_v>); + static_assert (!std::is_copy_constructible_v); + static_assert (!std::is_move_constructible_v); + static_assert (std::is_same_v ().begin ()), + Package const&>); +} diff --git a/Tests/DanceX11/run_test.pl b/Tests/DanceX11/run_test.pl new file mode 100644 index 0000000..225fdb8 --- /dev/null +++ b/Tests/DanceX11/run_test.pl @@ -0,0 +1,35 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use strict; +use warnings; + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::TestTarget; + +my $status = 0; +my $target = PerlACE::TestTarget::create_target (1) + || die "Create target 1 failed\n"; + +my $test = "$ENV{XSC_ROOT}/Tests/DanceX11/optional_copy"; +unless (-x $test) { + die "ERROR: Cannot find executable $test\n"; +} + +my $process = $target->CreateProcess ($test); +my $result = $process->SpawnWaitKill ($target->ProcessStartWaitInterval ()); + +if ($result == -1) { + print STDERR "ERROR: DanceX11 optional-copy test could not be started or timed out\n"; + $status = 1; +} +elsif ($result != 0) { + print STDERR "ERROR: generated copy assignment did not clear the optional href\n"; + $status = 1; +} +else { + print "DanceX11 generated copy assignment passed\n"; +} + +exit $status; diff --git a/Tests/ReadOnly/readonly.mpc b/Tests/ReadOnly/readonly.mpc new file mode 100644 index 0000000..343e7da --- /dev/null +++ b/Tests/ReadOnly/readonly.mpc @@ -0,0 +1,57 @@ +project (xsc_test_readonly): xscdefaults { + requires += xsc + custom_only = 1 + xscflags += --cxx-char-type char + xscflags += --cxx-read-only + xscflags += --cxx-generate-cdr-reader-types + xscflags += --cxx-generate-cdr-writer-types + xscflags += --cxx-generate-traversal-types + + XSC_Files { + readonly.xsd + } + Source_Files { + } +} + +project (xsc_test_readonly_generated): xscrt { + after += xsc_test_readonly + includes += $(ACE_ROOT)/ace/XML_Utils + + Source_Files { + readonly.cpp + readonly_api.cpp + } +} + +project (xsc_test_cpp03_compatibility): xscdefaults { + requires += xsc + custom_only = 1 + + Modify_Custom (XSC) { + source_outputext = .cpp03.cpp, + header_outputext = .cpp03.hpp, + } + + xscflags += --cxx-char-type char + xscflags += --cxx-cpp03 + xscflags += --cxx-generate-traversal-types + xscflags += --cxx-header-suffix .cpp03.hpp + xscflags += --cxx-source-suffix .cpp03.cpp + + XSC_Files { + readonly.xsd + } + + Source_Files { + } +} + +project (xsc_test_cpp03_compatibility_generated): xscrt { + after += xsc_test_cpp03_compatibility + includes += $(ACE_ROOT)/ace/XML_Utils + + Source_Files { + readonly.cpp03.cpp + } +} diff --git a/Tests/ReadOnly/readonly.xsd b/Tests/ReadOnly/readonly.xsd new file mode 100644 index 0000000..a163b82 --- /dev/null +++ b/Tests/ReadOnly/readonly.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Tests/ReadOnly/readonly_api.cpp b/Tests/ReadOnly/readonly_api.cpp new file mode 100644 index 0000000..a88f8be --- /dev/null +++ b/Tests/ReadOnly/readonly_api.cpp @@ -0,0 +1,48 @@ +#include "readonly.hpp" + +#include +#include +#include + +namespace +{ + template + struct has_name_setter : std::false_type + { + }; + + template + struct has_name_setter ().name ( + std::declval<::XMLSchema::string const&> ()))>> : std::true_type + { + }; + + template + struct has_optionalValue_presence_accessor : std::false_type + { + }; + + template + struct has_optionalValue_presence_accessor ().has_optionalValue ())>> : std::true_type + { + }; + + using ReadOnly = ReadOnlyType; + + static_assert (!std::is_default_constructible_v); + static_assert (!std::is_copy_constructible_v); + static_assert (!std::is_move_constructible_v); + static_assert (!std::is_copy_assignable_v); + static_assert (!std::is_move_assignable_v); + static_assert (!has_name_setter::value); + static_assert (!has_optionalValue_presence_accessor::value); + static_assert (std::is_same_v>>); + static_assert (std::is_same_v ().name ()), + ::XMLSchema::string const&>); + static_assert (std::is_same_v ().optionalValue_if_set ()), + ::XMLSchema::string const*>); + static_assert (std::is_same_v ().begin_item ()), + ::XMLSchema::string const&>); +} diff --git a/Tests/ReadOnly/run_test.pl b/Tests/ReadOnly/run_test.pl new file mode 100644 index 0000000..0a205ea --- /dev/null +++ b/Tests/ReadOnly/run_test.pl @@ -0,0 +1,85 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use strict; +use warnings; + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::TestTarget; + +my $target = PerlACE::TestTarget::create_target (1) + || die "Create target 1 failed\n"; + +my $xsc = "$ENV{XSC_ROOT}/bin/xsc"; +unless (-x $xsc) { + die "ERROR: Cannot find executable $xsc\n"; +} + +my $status = 0; +my $index = 0; +for my $mode ('--cxx-cpp03', '--cxx-cpp11') { + my $suffix = ".reject" . $$ . "_" . $index; + ++$index; + my $header = "readonly$suffix.hpp"; + my $source = "readonly$suffix.cpp"; + my $process = $target->CreateProcess ( + $xsc, "--backend cxx --cxx-read-only $mode " . + "--cxx-header-suffix $suffix.hpp --cxx-source-suffix $suffix.cpp " . + "readonly.xsd"); + my $result = $process->SpawnWaitKill ( + $target->ProcessStartWaitInterval ()); + + if ($result == -1) { + print STDERR "ERROR: XSC $mode read-only rejection test timed out\n"; + $status = 1; + } + elsif ($result == 0) { + print STDERR "ERROR: XSC accepted read-only mode with $mode\n"; + $status = 1; + } + else { + print "XSC rejected read-only mode with $mode as expected\n"; + } + + if (-e $header || -e $source) { + print STDERR "ERROR: XSC generated output for unsupported read-only $mode\n"; + unlink $header if -e $header; + unlink $source if -e $source; + $status = 1; + } +} + +my $compat_suffix = ".compat" . $$; +my $compat_header = "readonly$compat_suffix.hpp"; +my $compat_source = "readonly$compat_suffix.cpp"; +my $compat_process = $target->CreateProcess ( + $xsc, "--backend cxx --cxx-char-type char --cxx-cpp03 " . + "--cxx-generate-traversal-types --cxx-header-suffix " . + "$compat_suffix.hpp --cxx-source-suffix $compat_suffix.cpp readonly.xsd"); +my $compat_result = $compat_process->SpawnWaitKill ( + $target->ProcessStartWaitInterval ()); + +if ($compat_result != 0) { + print STDERR "ERROR: XSC failed to generate writable C++03 traversal code\n"; + $status = 1; +} +elsif (open my $source_file, '<', $compat_source) { + local $/; + my $source_text = <$source_file>; + close $source_file; + + if ($source_text =~ /\bnullptr\b/) { + print STDERR "ERROR: C++03 traversal output contains nullptr\n"; + $status = 1; + } +} +else { + print STDERR "ERROR: XSC did not create C++03 traversal output\n"; + $status = 1; +} + +unlink $compat_header if -e $compat_header; +unlink $compat_source if -e $compat_source; + +exit $status; diff --git a/Tests/Tests.mwc b/Tests/Tests.mwc index 436263b..339ced0 100644 --- a/Tests/Tests.mwc +++ b/Tests/Tests.mwc @@ -12,6 +12,7 @@ workspace (Tests) { Import Include NoNamespace + ReadOnly UnqualifiedImport Validation } diff --git a/Tests/Validation/run_test.pl b/Tests/Validation/run_test.pl index 57a594b..ac1e463 100644 --- a/Tests/Validation/run_test.pl +++ b/Tests/Validation/run_test.pl @@ -33,4 +33,49 @@ print "XSC rejected test.xsd as expected\n"; } +my $banner = "banner_$$\xFF.txt"; +my $schema = "$ENV{XSC_ROOT}/Tests/Abstract/abstract.xsd"; +open my $banner_file, '>', $banner + or die "ERROR: Cannot create non-ASCII banner file $banner\n"; +close $banner_file; + +for my $backend ( + ['cxx', '--cxx-banner-file', "--cxx-header-suffix .args.$$.hpp --cxx-source-suffix .args.$$.cpp", "abstract.args.$$.hpp"], + ['idl', '--idl-banner-file', "--idl-file-suffix .args.$$.idl", "abstract.args.$$.idl"]) +{ + my ($name, $banner_option, $suffix_options, $output) = @$backend; + my $process = $target->CreateProcess ( + $xsc, "--backend $name $banner_option $banner $suffix_options $schema"); + my $result = $process->SpawnWaitKill ($target->ProcessStartWaitInterval ()); + + if ($result != 0) { + print STDERR "ERROR: XSC $name generation with a non-ASCII argument failed\n"; + $status = 1; + } + elsif (open my $generated, '<', $output) { + binmode $generated; + local $/; + my $text = <$generated>; + close $generated; + my ($arguments) = $text =~ m{^// Arguments: ([^\r\n]*)}m; + if (!defined $arguments || index ($arguments, "\xFF") != -1 || + index ($arguments, '?') == -1) { + print STDERR "ERROR: XSC $name did not safely record non-ASCII arguments\n"; + $status = 1; + } + } + else { + print STDERR "ERROR: XSC did not create $output\n"; + $status = 1; + } + + unlink $output if -e $output; + if ($name eq 'cxx') { + (my $source = $output) =~ s/\.hpp$/.cpp/; + unlink $source if -e $source; + } +} + +unlink $banner; + exit $status; diff --git a/XSC/Parser.cpp b/XSC/Parser.cpp index 83541f0..66f2e8f 100644 --- a/XSC/Parser.cpp +++ b/XSC/Parser.cpp @@ -8,8 +8,8 @@ #include "xercesc/util/XMLString.hpp" #include "xercesc/validators/common/Grammar.hpp" #include "xercesc/validators/schema/XSDDOMParser.hpp" +#include "utils/XML_Error_Handler.h" #include "utils/XML_Schema_Resolver.h" -#include "utils/XML_Helper.h" #include // std::wcstombs #include diff --git a/XSC/Version.hpp b/XSC/Version.hpp new file mode 100644 index 0000000..e7ec807 --- /dev/null +++ b/XSC/Version.hpp @@ -0,0 +1,9 @@ +#ifndef XSC_VERSION_HPP +#define XSC_VERSION_HPP + +namespace XSC +{ + inline constexpr wchar_t wide_version[] {L"2.0.0"}; +} + +#endif // XSC_VERSION_HPP diff --git a/XSC/be/CXX/Elements.cpp b/XSC/be/CXX/Elements.cpp index f58e7ae..eaacb4e 100644 --- a/XSC/be/CXX/Elements.cpp +++ b/XSC/be/CXX/Elements.cpp @@ -337,6 +337,14 @@ type_name (SemanticGraph::Type& t, string const& nss) return anon_prefix_ + id (t.name ()) + anon_suffix_; } +string Context:: +base_type_name (SemanticGraph::Complex& t) +{ + auto b (t.inherits_begin ()), e (t.inherits_end ()); + + return b == e ? L"::XSCRT::Type" : type_name ((**b).inheritee ()); +} + string Context:: type_name (SemanticGraph::Instance& i, string const& nss) { diff --git a/XSC/be/CXX/Elements.hpp b/XSC/be/CXX/Elements.hpp index fcb5504..bda299e 100644 --- a/XSC/be/CXX/Elements.hpp +++ b/XSC/be/CXX/Elements.hpp @@ -5,6 +5,7 @@ #define CXX_ELEMENTS_HXX #include +#include #include #include #include @@ -72,7 +73,8 @@ class Context cdr_writer_generation_ (false), cppmode_ (CPPMODE::CPP17), orb_ (ORB::TAO), - generate_ra_sequences_ (false) + generate_ra_sequences_ (false), + read_only_ (false) { if (char_type == L"wchar_t") { @@ -119,7 +121,8 @@ class Context cdr_writer_generation_ (c.cdr_writer_generation_), cppmode_ (c.cppmode_), orb_ (c.orb_), - generate_ra_sequences_ (c.generate_ra_sequences_) + generate_ra_sequences_ (c.generate_ra_sequences_), + read_only_ (c.read_only_) { } @@ -171,6 +174,9 @@ class Context string type_name (SemanticGraph::Type& t, string const& ns_suffix = L""); + string + base_type_name (SemanticGraph::Complex& t); + protected: string fq_name (SemanticGraph::Nameable& n, string const& ns_suffix = L"", bool mangle = true); @@ -273,6 +279,24 @@ class Context return this->generate_ra_sequences_; } + void + read_only (bool flag) + { + this->read_only_ = flag; + } + + bool + read_only () + { + return this->read_only_; + } + + bool + optional_via_if_set () + { + return this->cppmode_ != CPPMODE::CPP03 || this->read_only_; + } + public: std::wostream& os; string& scope; @@ -342,6 +366,7 @@ class Context ORB orb_; bool generate_ra_sequences_; + bool read_only_; }; struct Anonymous : Traversal::Element, @@ -480,6 +505,85 @@ has (Y& y) return r; } +struct CopyRequiredMembers : Traversal::Element, Traversal::Attribute +{ + void + traverse (SemanticGraph::Element& e) override + { + if (e.max () == 1) + required = true; + } + + void + traverse (SemanticGraph::Attribute&) override + { + required = true; + } + + bool required {}; +}; + +inline bool +has_copy_required_members (SemanticGraph::Complex& c) +{ + CopyRequiredMembers t; + Traversal::Scope s; + Traversal::Names n; + s.edge_traverser (n); + n.node_traverser (t); + s.traverse (c); + return t.required; +} + +struct ConstructorRequiredMembers : Traversal::Enumeration, + Traversal::Element, + Traversal::Attribute +{ + void + traverse (SemanticGraph::Enumeration&) override + { + required = true; + } + + void + traverse (SemanticGraph::Element& e) override + { + if (e.min () >= 1) + required = true; + } + + void + traverse (SemanticGraph::Attribute& a) override + { + if (!a.optional ()) + required = true; + } + + bool required {}; +}; + +inline bool +has_constructor_required_members (SemanticGraph::Complex& c) +{ + ConstructorRequiredMembers t; + + std::function visit = [&] (SemanticGraph::Complex& current) + { + for (auto i (current.inherits_begin ()); i != current.inherits_end (); ++i) + if (auto base = dynamic_cast (std::addressof ((**i).inheritee ()))) + visit (*base); + + Traversal::Complex complex; + Traversal::Names names; + complex.edge_traverser (names); + names.node_traverser (t); + complex.traverse (current); + }; + + visit (c); + return t.required; +} + // Fundamental type mapping helper. // struct Fundamental : Traversal::FundamentalType, diff --git a/XSC/be/CXX/Generator.cpp b/XSC/be/CXX/Generator.cpp index ca9cc0e..878b380 100644 --- a/XSC/be/CXX/Generator.cpp +++ b/XSC/be/CXX/Generator.cpp @@ -8,6 +8,7 @@ #include #include #include "XSC/SemanticGraph.hpp" +#include "XSC/Version.hpp" #include "CCF/CodeGenerationKit/Regex.hpp" #include "CCF/CodeGenerationKit/IndentationCxx.hpp" @@ -57,6 +58,17 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con throw std::invalid_argument ("invalid value for --cxx-orb: " + orb); } + ::Context::CPPMODE cppmode_ { ::Context::CPPMODE::CPP17 }; + if (options.count ("cxx-cpp03")) + cppmode_ = ::Context::CPPMODE::CPP03; + if (options.count ("cxx-cpp11")) + cppmode_ = ::Context::CPPMODE::CPP11; + if (options.count ("cxx-cpp17")) + cppmode_ = ::Context::CPPMODE::CPP17; + + if (options.count ("cxx-read-only") && cppmode_ != ::Context::CPPMODE::CPP17) + throw std::invalid_argument ("--cxx-read-only requires C++17 mode"); + //Stores file suffixes (defaults are .hpp, ipp, and cpp) std::string hxx_suffix (options.value ("cxx-header-suffix")); std::string ixx_suffix (options.value ("cxx-inline-suffix")); @@ -115,6 +127,26 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con return; } + auto write_version = [&options] (std::wostream& output) + { + output << L"// Generated by XSC version " << XSC::wide_version << std::endl + << L"// Arguments: "; + std::string const& arguments {options.value ("arguments")}; + for (char c : arguments) + { + unsigned char const u {static_cast (c)}; + output << (u < 0x80 ? static_cast (u) : L'?'); + } + output << std::endl; + }; + + write_version (hxx); + if (inline_) + { + write_version (ixx); + } + write_version (cxx); + // Banner. // //Takes in the name of a "banner" file. This banner, if it exists, will @@ -221,7 +253,6 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con } } - // // string char_type; @@ -249,23 +280,10 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con traversal); // Check if cdr reader/writer options are set - bool cdr_reader (options.count ("cxx-generate-cdr-reader-types")); + bool read_only (options.count ("cxx-read-only")); + bool cdr_reader (options.count ("cxx-generate-cdr-reader-types") && !read_only); bool cdr_writer (options.count ("cxx-generate-cdr-writer-types")); - ::Context::CPPMODE cppmode_ { ::Context::CPPMODE::CPP17 }; - if (options.count ("cxx-cpp03")) - { - cppmode_ = ::Context::CPPMODE::CPP03; - } - if (options.count ("cxx-cpp11")) - { - cppmode_ = ::Context::CPPMODE::CPP11; - } - if (options.count ("cxx-cpp17")) - { - cppmode_ = ::Context::CPPMODE::CPP17; - } - // Check about random access sequences bool ra_sequences (options.count ("cxx-enable-random-access-sequences")); @@ -355,6 +373,7 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con ctx.cppmode (cppmode_); ctx.orb (orb_); + ctx.read_only (read_only); // Add additional information to the context: ctx.generate_ra_sequences (ra_sequences); @@ -398,6 +417,7 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con ctx.cppmode (cppmode_); ctx.orb (orb_); + ctx.read_only (read_only); // Add additional information to the context: ctx.generate_ra_sequences (ra_sequences); @@ -409,6 +429,7 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con // CXX // cxx << "#include \"" << hxx_name.c_str () << "\"" << std::endl + << "#include " << std::endl << std::endl; { @@ -423,6 +444,7 @@ generate (XSC::Options const& options, Schema& schema, std::filesystem::path con ctx.cppmode (cppmode_); ctx.orb (orb_); + ctx.read_only (read_only); if (!inline_) { diff --git a/XSC/be/CXX/Header.cpp b/XSC/be/CXX/Header.cpp index 856abeb..31d4002 100644 --- a/XSC/be/CXX/Header.cpp +++ b/XSC/be/CXX/Header.cpp @@ -36,16 +36,6 @@ namespace os << " : public " << name << "{"; - switch(this->cppmode_) - { - case CPPMODE::CPP03: - os << "typedef " << name << " Base;" << std::endl; - break; - case CPPMODE::CPP11: - case CPPMODE::CPP17: - os << "using Base = " << name << ";" << std::endl; - break; - } } }; @@ -170,8 +160,7 @@ namespace else container = L"std::list"; - os << "// " << name << std::endl - << "public:" << std::endl; + os << "public:" << std::endl; if (c.max () != 1) @@ -192,17 +181,25 @@ namespace switch(this->cppmode_) { case CPPMODE::CPP03: - os << "typedef " << name << "_container_type::iterator " << name << "_iterator;"; + if (!this->read_only_) + os << "typedef " << name << "_container_type::iterator " << name << "_iterator;"; os << "typedef " << name << "_container_type::const_iterator " << name << "_const_iterator;"; - os << name << "_iterator begin_" << name << " ();"; - os << name << "_iterator end_" << name << " ();"; + if (!this->read_only_) + { + os << name << "_iterator begin_" << name << " ();"; + os << name << "_iterator end_" << name << " ();"; + } break; case CPPMODE::CPP11: case CPPMODE::CPP17: - os << "using " << name << "_iterator = " << name << "_container_type::iterator;"; + if (!this->read_only_) + os << "using " << name << "_iterator = " << name << "_container_type::iterator;"; os << "using " << name << "_const_iterator = " << name << "_container_type::const_iterator;"; - os << name << "_iterator begin_" << name << " ();"; - os << name << "_iterator end_" << name << " ();"; + if (!this->read_only_) + { + os << name << "_iterator begin_" << name << " ();"; + os << name << "_iterator end_" << name << " ();"; + } break; } @@ -212,45 +209,69 @@ namespace switch(this->cppmode_) { case CPPMODE::CPP03: - os << "void add_" << name << " (" << name << "_value_type const&);"; - os << "void del_" << name << " (" << name << "_value_type const&);"; + if (!this->read_only_) + { + os << "void add_" << name << " (" << name << "_value_type const&);"; + os << "void del_" << name << " (" << name << "_value_type const&);"; + } break; case CPPMODE::CPP11: case CPPMODE::CPP17: break; } //Return referenced item if an IDREF - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << "XSCRT::Type* get_" << name << "_ptr (const " << string_type <<"& idref);"; os << "void set_" << name << "_ptr (const " << string_type << "& idref);"; } - os << "size_t count_" << name << " () const;"; + os << "size_t count_" << name << " () const" + << (this->cppmode_ == CPPMODE::CPP17 ? " noexcept;" : ";"); os << std::endl - << "protected:" << std::endl; + << (this->read_only_ ? "private:" : "protected:") << std::endl; - os << name << "_container_type " << id(name) << "_;"; + os << name << "_container_type " << id(name) << "_" + << (this->read_only_ && this->cppmode_ != CPPMODE::CPP03 ? L" {};" : L";"); } else if (c.min () == 0) { // optional // - os << "bool " << name << "_p () const;"; - os << type << " const& " << id (name) << " () const;"; + if (!this->optional_via_if_set ()) + { + os << "bool " << name << "_p () const;"; + os << type << " const& " << id (name) << " () const;"; + } + else + { + string noexcept_suffix (this->cppmode_ == CPPMODE::CPP03 ? L"" : L" noexcept"); + os << type << " const* " << id (name) << "_if_set () const" + << noexcept_suffix << ";"; + if (!this->read_only_) + os << type << "* " << id (name) << "_if_set ()" + << noexcept_suffix << ";"; + } // os << type << "& " << id (name) << " ();"; // Lets just have one mutator - os << "void " << id (name) << " (" << type << " const&);"; + if (this->read_only_) + os << "private:" << std::endl; + else + os << "void " << id (name) << " (" << type << " const&);"; //Added for IDREF case if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) { - os << "::XSCRT::Type* get_" << id (name) << "_ptr ();\n"; - os << "void set_" << id (name) << "_ptr (const " << string_type << "& idref);"; + if (!this->read_only_) + { + os << "::XSCRT::Type* get_" << id (name) << "_ptr ();\n"; + os << "void set_" << id (name) << "_ptr (const " << string_type << "& idref);"; + } } - os << std::endl - << "protected:" << std::endl; + if (!this->read_only_) + os << std::endl << "protected:" << std::endl; switch(this->cppmode_) { case CPPMODE::CPP03: @@ -260,7 +281,8 @@ namespace case CPPMODE::CPP11: case CPPMODE::CPP17: os << "using " << id (name) << "_type = std::unique_ptr<" << type << ">;"; - os << id (name) << "_type " << id (name) << "_;"; + os << id (name) << "_type " << id (name) << "_" + << (this->read_only_ ? L" {};" : L";"); break; } } @@ -270,17 +292,21 @@ namespace // os << type << " const& " << id (name) << " () const;"; // os << type << "& " << id (name) << " ();"; // Lets just have one mutator. - os << "void " << id (name) << " (" << type << " const&);"; + if (this->read_only_) + os << "private:" << std::endl; + else + os << "void " << id (name) << " (" << type << " const&);"; //Added for IDREF case - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << "::XSCRT::Type* get_" << id (name) << "_ptr ( void );\n"; os << "void set_" << id(name) << "_ptr (const " << string_type << "& idref);"; } - os << std::endl - << "protected:" << std::endl; + if (!this->read_only_) + os << std::endl << "protected:" << std::endl; switch(this->cppmode_) { @@ -291,7 +317,8 @@ namespace case CPPMODE::CPP11: case CPPMODE::CPP17: os << "using " << id (name) << "_type = std::unique_ptr<" << type << ">;"; - os << id (name) << "_type " << id (name) << "_;"; + os << id (name) << "_type " << id (name) << "_" + << (this->read_only_ ? L" {};" : L";"); break; } } @@ -333,26 +360,41 @@ namespace std::wstring idref_str (L"::XMLSchema::IDREF<"); idref_ptr = type.find(idref_str); - os << "// " << name << std::endl - << "public:" << std::endl; + os << "public:" << std::endl; if (a.optional ()) { - os << "bool " << name << "_p () const;"; - os << type << " const& " << id (name) << " () const;"; - os << type << "& " << id (name) << " ();"; - os << "void " << id (name) << " (" << type << " const&);"; + if (!this->optional_via_if_set ()) + { + os << "bool " << name << "_p () const;"; + os << type << " const& " << id (name) << " () const;"; + os << type << "& " << id (name) << " ();"; + } + else + { + string noexcept_suffix (this->cppmode_ == CPPMODE::CPP03 ? L"" : L" noexcept"); + os << type << " const* " << id (name) << "_if_set () const" + << noexcept_suffix << ";"; + if (!this->read_only_) + os << type << "* " << id (name) << "_if_set ()" + << noexcept_suffix << ";"; + } + if (this->read_only_) + os << "private:" << std::endl; + else + os << "void " << id (name) << " (" << type << " const&);"; //Added for IDREF case - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << "::XSCRT::Type* get_" << id (name) << "_ptr ();\n"; os << "void set_" << id(name) << "_ptr (const " << string_type << "& idref);"; } - os << std::endl - << "protected:" << std::endl; + if (!this->read_only_) + os << std::endl << "protected:" << std::endl; switch(this->cppmode_) { @@ -363,25 +405,31 @@ namespace case CPPMODE::CPP11: case CPPMODE::CPP17: os << "using " << id (name) << "_type = std::unique_ptr<" << type << ">;"; - os << id (name) << "_type " << id (name) << "_;"; + os << id (name) << "_type " << id (name) << "_" + << (this->read_only_ ? L" {};" : L";"); break; } } else { os << type << " const& " << id (name) << " () const;"; - os << type << "& " << id (name) << " ();"; - os << "void " << id (name) << " (" << type << " const&);"; + if (!this->read_only_) + os << type << "& " << id (name) << " ();"; + if (this->read_only_) + os << "private:" << std::endl; + else + os << "void " << id (name) << " (" << type << " const&);"; //Added for IDREF case - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << "::XSCRT::Type* get_" << id (name) << "_ptr ( void );\n"; os << "void set_" << id (name) << "_ptr (const " << string_type << "& idref);"; } - os << std::endl - << "protected:" << std::endl; + if (!this->read_only_) + os << std::endl << "protected:" << std::endl; switch(this->cppmode_) { @@ -392,7 +440,8 @@ namespace case CPPMODE::CPP11: case CPPMODE::CPP17: os << "using " << id (name) << "_type = std::unique_ptr<" << type << ">;"; - os << id (name) << "_type " << id (name) << "_;"; + os << id (name) << "_type " << id (name) << "_" + << (this->read_only_ ? L" {};" : L";"); break; } } @@ -453,9 +502,7 @@ namespace inherits_none (Type &c) override { os << " : public ::XSCRT::Type" - << "{" - << (this->cppmode_ != CPPMODE::CPP03 ? "using Base = ::XSCRT::Type;" : "typedef ::XSCRT::Type Base;" ) - << std::endl; + << "{" << std::endl; switch(this->cppmode_) { case CPPMODE::CPP03: @@ -545,12 +592,27 @@ namespace // c-tor (all-non-optional-members) // - os << name << " ("; + if (this->read_only_) + { + if (this->cppmode_ == CPPMODE::CPP03) + os << "private:" << std::endl + << name << " ();" + << "public:" << std::endl; + else + os << name << " () = delete;"; + } - ctor_args_.traverse (c); + if (!this->read_only_) + { + os << name << " ("; - os << ");" - << std::endl; + ctor_args_.traverse (c); + + bool const default_constructor (this->cppmode_ != CPPMODE::CPP03 && + !has_constructor_required_members (c)); + os << ")" << (default_constructor ? " = default;" : ";") + << std::endl; + } // c-tor (Element const&) // @@ -594,19 +656,46 @@ namespace // copy c-tor // - os << name << " (" << name << " const& s);"; - - // operator= - // - os << name << "& operator= (" << name << " const& s);" - << std::endl; + if (this->read_only_) + { + if (this->cppmode_ == CPPMODE::CPP03) + os << "private:" << std::endl + << name << " (" << name << " const&);"; + else + { + os << name << " (" << name << " const&) = delete;"; + os << name << " (" << name << "&&) = delete;"; + } - if (this->cppmode_ != CPPMODE::CPP03) + if (this->cppmode_ == CPPMODE::CPP03) + os << "private:" << std::endl + << name << "& operator= (" << name << " const&);"; + else + { + os << name << "& operator= (" << name << " const&) = delete;"; + os << name << "& operator= (" << name << "&&) = delete;"; + } + } + else { - os << name << " (" << name << "&&) = default;"; - os << name << "& operator= (" << name << "&&) = default;" - << std::endl; + bool const default_copy (this->cppmode_ == CPPMODE::CPP17 && + !has_copy_required_members (c)); + + os << name << " (" << name << " const& s)" + << (default_copy ? " = default;" : ";"); + + // operator= + // + os << name << "& operator= (" << name << " const& s)" + << (default_copy ? " = default;" : ";"); + + if (this->cppmode_ != CPPMODE::CPP03) + { + os << name << " (" << name << "&&) = default;"; + os << name << "& operator= (" << name << "&&) = default;"; + } } + os << std::endl; // Closing brace for the class declaration // Example: class Foo { @@ -719,11 +808,20 @@ namespace name = id (e.name ()); os << "class " << ex_sp_ << name << " : public ::XSCRT::Type" - << "{" - << "public:" << std::endl; + << "{" << "public:" << std::endl; enter_scope (name); + if (this->read_only_) + { + if (this->cppmode_ == CPPMODE::CPP03) + os << "private:" << std::endl + << name << " ();" + << "public:" << std::endl; + else + os << name << " () = delete;"; + } + // c-tor (Element const&) // os << "explicit " << name << " (" << xml_element_type << " const&);"; @@ -744,20 +842,29 @@ namespace label_.reset (); names (e, names_labels_); - os << std::endl << "};" - << std::endl; + os << L"};\nValue integral () const;\n"; - os << "Value" << std::endl - << "integral () const;" - << std::endl; + if (this->read_only_) + { + if (this->cppmode_ == CPPMODE::CPP03) + os << "private:" << std::endl + << name << " (" << name << " const&);" + << name << "& operator= (" << name << " const&);"; + else + { + os << name << " (" << name << " const&) = delete;"; + os << name << " (" << name << "&&) = delete;"; + os << name << "& operator= (" << name << " const&) = delete;"; + os << name << "& operator= (" << name << "&&) = delete;"; + } + } - os << "friend bool " << ex_ << std::endl + os << "friend bool " << ex_sp_ << "operator== (" << name << " const& a, " << name << " const& b);" - << std::endl; - - os << "friend bool " << ex_ << std::endl + << L'\n' + << "friend bool " << ex_sp_ << "operator!= (" << name << " const& a, " << name << " const& b);" - << std::endl; + << L'\n'; os << "private:" << std::endl; diff --git a/XSC/be/CXX/Inline.cpp b/XSC/be/CXX/Inline.cpp index 35f57da..e7b03ea 100644 --- a/XSC/be/CXX/Inline.cpp +++ b/XSC/be/CXX/Inline.cpp @@ -44,37 +44,36 @@ namespace std::wstring idref_str (L"::XMLSchema::IDREF<"); idref_ptr = type.find(idref_str); - os << "// " << scope << std::endl; - if (e.min () == 0 && e.max () == 1) { // optional // - os << i - << "bool " << scope << "::" << std::endl - << name << "_p () const" - << "{"; - - if (this->cppmode_ != CPPMODE::CPP03) + if (this->optional_via_if_set ()) { - os << "return !!" << id (name) << "_;"; + string noexcept_suffix (this->cppmode_ == CPPMODE::CPP03 ? L"" : L" noexcept"); + os << i << type << " const* " << scope << "::" << id (name) + << "_if_set () const" << noexcept_suffix + << "{return " << id (name) << "_.get ();}"; + + if (!this->read_only_) + os << i << type << "* " << scope << "::" << id (name) + << "_if_set ()" << noexcept_suffix + << "{return " << id (name) << "_.get ();}"; } else { - os << "return " << id (name) << "_.get () != 0;"; - } - - os << "}"; + os << i + << "bool " << scope << "::" << name << "_p () const" + << "{return " << id (name) << "_.get () != 0;}"; - os << i - << type << " const& " << scope << "::" << std::endl - << id (name) << " () const" - << "{" - << "return *" << id (name) << "_;" - << "}"; + os << i + << type << " const& " << scope << "::" << id (name) << " () const" + << "{return *" << id (name) << "_;}"; + } // Return referenced item if an IDREF - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << i << "::XSCRT::Type* " << scope << "::get_" @@ -95,15 +94,15 @@ namespace } /* Lets just have one accessor. WRO os << i - << type << "& " << scope << "::" << std::endl - << id (name) << " ()" + << type << "& " << scope << "::" << id (name) << " ()" << "{" << "return *" << id (name) << "_;" << "}"; */ + if (!this->read_only_) + { os << i - << "void " << scope << "::" << std::endl - << id (name) << " (" << type << " const& e)" + << "void " << scope << "::" << id (name) << " (" << type << " const& e)" << "{"; if (this->cppmode_ != CPPMODE::CPP03) @@ -134,18 +133,19 @@ namespace } os << "}" << "}"; + } } else if (e.min () == 1 && e.max () == 1) { // one // os << i - << type << " const& " << scope << "::" << std::endl - << id (name) << " () const" + << type << " const& " << scope << "::" << id (name) << " () const" << "{" << "return *" << id (name) << "_;" << "}"; - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << i << "::XSCRT::Type* " << scope << "::get_" @@ -165,24 +165,24 @@ namespace << "}\n"; } - os << i - << "void " << scope << "::" << std::endl - << id (name) << " (" << type << " const& e)" - << "{" - << "*" << id (name) << "_ = e;" - << "}"; + if (!this->read_only_) + os << i + << "void " << scope << "::" << id (name) << " (" << type << " const& e)" + << "{" + << "*" << id (name) << "_ = e;" + << "}"; } else { // sequence // + if (!this->read_only_) { // begin_typename // os << i - << scope << "::" << name << "_iterator " << scope << "::" << std::endl - << "begin_" << name << " ()" + << scope << "::" << name << "_iterator " << scope << "::begin_" << name << " ()" << "{" << "return " << id(name) << "_.begin ();" << "}"; @@ -190,8 +190,7 @@ namespace // end_typename // os << i - << scope << "::" << name << "_iterator " << scope << "::" << std::endl - << "end_" << name << " ()" + << scope << "::" << name << "_iterator " << scope << "::end_" << name << " ()" << "{" << "return " << id(name) << "_.end ();" << "}"; @@ -199,8 +198,7 @@ namespace // begin_typename const os << i - << scope << "::" << name << "_const_iterator " << scope << "::" << std::endl - << "begin_" << name << " () const" + << scope << "::" << name << "_const_iterator " << scope << "::begin_" << name << " () const" << "{"; if (this->cppmode_ != CPPMODE::CPP03) @@ -215,8 +213,7 @@ namespace // end_typename const os << i - << scope << "::" << name << "_const_iterator " << scope << "::" << std::endl - << "end_" << name << " () const" + << scope << "::" << name << "_const_iterator " << scope << "::end_" << name << " () const" << "{"; if (this->cppmode_ != CPPMODE::CPP03) @@ -230,7 +227,8 @@ namespace os << "}"; // add IDREF access method - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << i << "XSCRT::Type* " << scope << "::get_" << name @@ -248,19 +246,17 @@ namespace << "}\n"; } - if (this->cppmode_ == CPPMODE::CPP03) + if (!this->optional_via_if_set ()) { // add_typename os << i - << "void " << scope << "::" << std::endl - << "add_" << name << " (" << scope << "::" << name << "_value_type const& e)" + << "void " << scope << "::add_" << name << " (" << scope << "::" << name << "_value_type const& e)" << "{"; os << id(name) << "_.push_back (e);"; os << "}"; // del_typename os << i - << "void " << scope << "::" << std::endl - << "del_" << name << " (" << scope << "::" << name << "_value_type const& e)" + << "void " << scope << "::del_" << name << " (" << scope << "::" << name << "_value_type const& e)" << "{"; os << id(name) << "_.remove (e);"; os << "}"; @@ -270,8 +266,8 @@ namespace // count_typename // os << i - << "size_t " << scope << "::" << std::endl - << "count_" << name << "() const" + << "size_t " << scope << "::count_" << name << "() const" + << (this->cppmode_ == CPPMODE::CPP17 ? " noexcept" : "") << "{" << "return " << id(name) << "_.size ();" << "}"; @@ -285,8 +281,6 @@ namespace string name (a.name ()); string type (type_name (a)); - os << "// " << scope << std::endl; - //Check if the type is an IDREF std::string::size_type idref_ptr = 0; std::wstring idref_str (L"::XMLSchema::IDREF<"); @@ -294,41 +288,41 @@ namespace if (a.optional ()) { - if (this->cppmode_ != CPPMODE::CPP03) + if (this->optional_via_if_set ()) { - os << i - << "bool " << scope << "::" << std::endl - << name << "_p () const" - << "{" - << "return !!" << id (name) << "_;" - << "}"; + string noexcept_suffix (this->cppmode_ == CPPMODE::CPP03 ? L"" : L" noexcept"); + os << i << type << " const* " << scope << "::" << id (name) + << "_if_set () const" << noexcept_suffix + << "{return " << id (name) << "_.get ();}"; + + if (!this->read_only_) + os << i << type << "* " << scope << "::" << id (name) + << "_if_set ()" << noexcept_suffix + << "{return " << id (name) << "_.get ();}"; } else { os << i - << "bool " << scope << "::" << std::endl - << name << "_p () const" + << "bool " << scope << "::" << name << "_p () const" << "{" << "return " << id (name) << "_.get () != 0;" << "}"; } - os << i - << type << " const& " << scope << "::" << std::endl - << id (name) << " () const" - << "{" - << "return *" << id (name) << "_;" - << "}"; + if (!this->optional_via_if_set ()) + { + os << i + << type << " const& " << scope << "::" << id (name) << " () const" + << "{return *" << id (name) << "_;}"; - os << i - << type << "& " << scope << "::" << std::endl - << id (name) << " ()" - << "{" - << "return *" << id (name) << "_;" - << "}"; + os << i + << type << "& " << scope << "::" << id (name) << " ()" + << "{return *" << id (name) << "_;}"; + } // Return a pointer to the referenced item - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << i << "::XSCRT::Type* " << scope << "::get_" @@ -348,9 +342,10 @@ namespace << "}\n"; } + if (!this->read_only_) + { os << i - << "void " << scope << "::" << std::endl - << id (name) << " (" << type << " const& e)" + << "void " << scope << "::" << id (name) << " (" << type << " const& e)" << "{"; if (this->cppmode_ != CPPMODE::CPP03) @@ -379,25 +374,26 @@ namespace } os << "}" << "}"; + } } else { os << i - << type << " const& " << scope << "::" << std::endl - << id (name) << " () const" + << type << " const& " << scope << "::" << id (name) << " () const" << "{" << "return *" << id (name) << "_;" << "}"; - os << i - << type << "& " << scope << "::" << std::endl - << id (name) << " ()" - << "{" - << "return *" << id (name) << "_;" - << "}"; + if (!this->read_only_) + os << i + << type << "& " << scope << "::" << id (name) << " ()" + << "{" + << "return *" << id (name) << "_;" + << "}"; // Return a pointer to the referenced item - if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03)) + if ((idref_ptr != std::string::npos) && (this->cppmode_ == CPPMODE::CPP03) && + !this->read_only_) { os << i << "::XSCRT::Type* " << scope << "::get_" @@ -417,12 +413,12 @@ namespace << "}\n"; } - os << i - << "void " << scope << "::" << std::endl - << id (name) << " (" << type << " const& e)" - << "{" - << "*" << id (name) << "_ = e;" - << "}"; + if (!this->read_only_) + os << i + << "void " << scope << "::" << id (name) << " (" << type << " const& e)" + << "{" + << "*" << id (name) << "_ = e;" + << "}"; } } @@ -565,89 +561,96 @@ namespace { string type (name); - os << "// " << scope << std::endl - << std::endl; - - // c-tor - // - os << i - << scope << "::" << name << " ("; + bool const has_base (c.inherits_begin () != c.inherits_end ()); + bool const default_constructor (this->cppmode_ != CPPMODE::CPP03 && + !has_constructor_required_members (c)); - ctor_args_.traverse (c); + if (!this->read_only_ && !default_constructor) + { + // c-tor + // + os << i + << scope << "::" << name << " ("; - os << ")" << std::endl; + ctor_args_.traverse (c); - bool const has_base (c.inherits_begin () != c.inherits_end ()); + os << ")" << std::endl; - inherits (c, ctor_base_); + inherits (c, ctor_base_); - // Resets a flag that determines if a Complex Type's constructor - // has inherited from the base XSCRT::Type class. Right now, this - // is commented out since it was producing a bug when complex types - // extended another complete type. + // Resets a flag that determines if a Complex Type's constructor + // has inherited from the base XSCRT::Type class. Right now, this + // is commented out since it was producing a bug when complex types + // extended another complete type. - ctor_member__.reset_base_class_initialization (has_base); - names (c, ctor_member_); + ctor_member__.reset_base_class_initialization (has_base); + names (c, ctor_member_); - os << "{"; + os << "{"; - names (c, ctor_body_); + names (c, ctor_body_); - os << "}"; + os << "}"; + } - // copy c-tor - // - os << i - << scope << "::" - << name << " (" << type << " const& s)" << std::endl; + bool const default_copy (this->cppmode_ == CPPMODE::CPP17 && + !has_copy_required_members (c)); - if (!has_base) + if (!this->read_only_ && !default_copy) { - os << ": ::XSCRT::Type (s)" << std::endl; - } + // copy c-tor + // + os << i + << scope << "::" + << name << " (" << type << " const& s)" << std::endl; - // Resets a flag that determines if a Complex Type's - // copy constructor has inherited from the base XSCRT::Type - // class. - copy_.reset_base_class_initialization (); + if (!has_base) + { + os << ": ::XSCRT::Type (s)" << std::endl; + } - inherits (c, copy_base_); + // Resets a flag that determines if a Complex Type's + // copy constructor has inherited from the base XSCRT::Type + // class. + copy_.reset_base_class_initialization (); - names (c, copy_member_); + inherits (c, copy_base_); - os << "{"; + names (c, copy_member_); - names (c, copy_body_member_); + os << "{"; - os << "}"; + names (c, copy_body_member_); - std::wstring selfcheck; - if (this->cppmode_ != CPPMODE::CPP03) - { - selfcheck = L"if (std::addressof(s) != this)"; - } - else - { - selfcheck = L"if (&s != this)"; - } + os << "}"; - // operator= - // - os << i - << scope << "&" << std::endl - << scope << "::operator= (" << type << " const& s)" - << "{" - << selfcheck - << "{"; + std::wstring selfcheck; + if (this->cppmode_ != CPPMODE::CPP03) + { + selfcheck = L"if (std::addressof(s) != this)"; + } + else + { + selfcheck = L"if (&s != this)"; + } + + // operator= + // + os << i + << scope << "& " << scope << "::operator= (" << type << " const& s)" + << "{" + << selfcheck + << "{"; - inherits (c, assign_base_); - names (c, assign_member_); + inherits (c, assign_base_); + names (c, assign_member_); - os << "}" - << "return *this;" - << "}"; + os << "}" + << "return *this;" + << "}"; - os << std::endl; + os << std::endl; + } } void @@ -682,10 +685,7 @@ namespace string type (type_name (c)); if (this->cdr_reader_generation_) - os << "bool" << std::endl - << "operator >> (::XMLSchema::CDR_InputStream &stream," - << std::endl - << " ::XMLSchema::cdr_arg_traits < " + os << "bool operator >> (::XMLSchema::CDR_InputStream &stream, ::XMLSchema::cdr_arg_traits < " << type << " >::inout_type element)" << std::endl << "{" @@ -695,10 +695,7 @@ namespace << "}"; if (this->cdr_writer_generation_) - os << "bool" << std::endl - << "operator << (::XMLSchema::CDR_OutputStream &stream," - << std::endl - << " ::XMLSchema::cdr_arg_traits < " + os << "bool operator << (::XMLSchema::CDR_OutputStream &stream, ::XMLSchema::cdr_arg_traits < " << type << " >::in_type element)" << std::endl << "{" @@ -721,15 +718,15 @@ namespace } void - traverse (SemanticGraph::Enumeration&) override + traverse (SemanticGraph::Enumeration& e) override { - os << ": Base (b__)" << std::endl; + os << ": " << type_name (e) << " (b__)" << std::endl; } void - traverse (SemanticGraph::Type&) override + traverse (SemanticGraph::Type& t) override { - os << ": Base ()" << std::endl; + os << ": " << type_name (t) << " ()" << std::endl; } void @@ -948,11 +945,11 @@ namespace } void - traverse (SemanticGraph::Type&) override + traverse (SemanticGraph::Type& t) override { if (!this->base_class_initialized_) { - os << ": Base (s)" << std::endl; + os << ": " << type_name (t) << " (s)" << std::endl; this->base_class_initialized_ = true; } } @@ -1138,9 +1135,9 @@ namespace } void - traverse (SemanticGraph::Type&) override + traverse (SemanticGraph::Type& t) override { - os << "Base::operator= (s);" << std::endl; + os << type_name (t) << "::operator= (s);" << std::endl; } void @@ -1160,7 +1157,7 @@ namespace os << "if (s." << name << "_)" << std::endl << " " << name << " (*(s." << name << "_));" << "else" << std::endl - << " " << name << "_.release ();" + << " " << name << "_.reset ();" << std::endl; } else @@ -1203,7 +1200,7 @@ namespace { os << "if (s." << name << "_) " << name << " (*(s." << name << "_));" - << "else " << name << "_.release ();" + << "else " << name << "_.reset ();" << std::endl; } else @@ -1268,34 +1265,27 @@ namespace string type (type_name (e)); - os << "// " << scope << std::endl - << std::endl; - os << i - << scope << "::Value " << scope << "::" << std::endl - << "integral () const" + << scope << "::Value " << scope << "::integral () const" << "{" << "return v_;" << "}"; os << i - << "bool" << std::endl - << "operator== (" << type << " const& a, " << type << " const& b)" + << "bool operator== (" << type << " const& a, " << type << " const& b)" << "{" << "return a.v_ == b.v_;" << "}"; os << i - << "bool" << std::endl - << "operator!= (" << type << " const& a, " << type << " const& b)" + << "bool operator!= (" << type << " const& a, " << type << " const& b)" << "{" << "return a.v_ != b.v_;" << "}"; os << i - << scope << "::" << std::endl - << name << " (" << scope << "::Value v)" << std::endl + << scope << "::" << name << " (" << scope << "::Value v)" << std::endl << ": v_ (v)" << std::endl << "{" << "}"; @@ -1304,10 +1294,7 @@ namespace // CDR Insertion extraction operations if needed if (this->cdr_reader_generation_) - os << "bool" << std::endl - << "operator >> (::XMLSchema::CDR_InputStream &stream," - << std::endl - << " ::XMLSchema::cdr_arg_traits < " + os << "bool operator >> (::XMLSchema::CDR_InputStream &stream, ::XMLSchema::cdr_arg_traits < " << type << " >::inout_type element)" << std::endl << "{" @@ -1317,10 +1304,7 @@ namespace << "}"; if (this->cdr_writer_generation_) - os << "bool" << std::endl - << "operator << (::XMLSchema::CDR_OutputStream &stream," - << std::endl - << " ::XMLSchema::cdr_arg_traits < " + os << "bool operator << (::XMLSchema::CDR_OutputStream &stream, ::XMLSchema::cdr_arg_traits < " << type << " >::in_type element)" << std::endl << "{" diff --git a/XSC/be/CXX/ParserHeader.cpp b/XSC/be/CXX/ParserHeader.cpp index a871c44..0f7db85 100644 --- a/XSC/be/CXX/ParserHeader.cpp +++ b/XSC/be/CXX/ParserHeader.cpp @@ -25,7 +25,7 @@ namespace os << "namespace reader" << "{" << e - << type << std::endl + << type << " " << id (name) << " (xercesc::DOMDocument const*);" << "}" << std::endl; diff --git a/XSC/be/CXX/ParserSource.cpp b/XSC/be/CXX/ParserSource.cpp index db8f3b2..54e2056 100644 --- a/XSC/be/CXX/ParserSource.cpp +++ b/XSC/be/CXX/ParserSource.cpp @@ -52,22 +52,30 @@ namespace os << "xercesc::DOMElement* dom_element = d->getDocumentElement ();" << "if (!dom_element)" << "{" - << "throw 1;" + << "throw std::runtime_error (\"XML document has no root element\");" << "}" << xml_element_type << " e (dom_element);" << "if (e.name () == " << compare_name << ")" - << "{" - << type << " r (e);\n"; + << "{"; + + if (!this->read_only_) + os << type << " r (e);"; if (this->cppmode_ == CPPMODE::CPP03) { os << "(*TSS_ID_Map)->resolve_idref();" << std::endl; } - os << "return r;" - << "}" + + if (this->read_only_) + os << "return " << type << " (e);"; + else + os << "return r;"; + + os << "}" << "else" << "{" - << "throw 1;" + << "throw std::runtime_error (\"unexpected XML root element; expected <" + << name << ">\");" << "}" << "}" << "}"; diff --git a/XSC/be/CXX/Source.cpp b/XSC/be/CXX/Source.cpp index 06c27b2..3478dfb 100644 --- a/XSC/be/CXX/Source.cpp +++ b/XSC/be/CXX/Source.cpp @@ -26,8 +26,14 @@ namespace struct Element : Traversal::Element, protected virtual Context { explicit Element (Context& c) - : Context (c) + : Context (c), first_ (true) + { + } + + void + reset () { + first_ = true; } virtual void @@ -55,8 +61,10 @@ namespace //@@ need to use FQ-names. // - os << "if (n == " << compare_name << ")" + os << (first_ ? "if (n == " : "else if (n == ") + << compare_name << ")" << "{"; + first_ = false; if (c.max () != 1) { @@ -64,22 +72,34 @@ namespace // if (this->cppmode_ != CPPMODE::CPP03) { - os << type << " t (e);"; - os << id (name) << "_.push_back (t);"; + os << id (name) << "_.emplace_back (e);"; } else { os << name << "_value_type t (new " << type << " (e));"; - os << "add_" << name << " (t);"; + if (this->read_only_) + os << id (name) << "_.push_back (t);"; + else + os << "add_" << name << " (t);"; } } else if (c.min () == 0) { // optional // - os << type << " t (e);" - << id (name) << " (t);"; + if (this->read_only_) + { + if (this->cppmode_ != CPPMODE::CPP03) + os << id (name) << "_ = std::make_unique<" << type << "> (e);"; + else + os << id (name) << "_ = " << scope << "::" << id(name) + << "_type (new " << type << " (e));" + << id (name) << "_->container (this);"; + } + else + os << type << " t (e);" + << id (name) << " (t);"; } else { @@ -195,18 +215,26 @@ namespace } - os <<"}" - << "else "; + os << "}"; } + + private: + bool first_; }; struct Attribute : Traversal::Attribute, protected virtual Context { explicit Attribute (Context& c) - : Context (c) + : Context (c), first_ (true) { } + void + reset () + { + first_ = true; + } + virtual void traverse (Type& a) { @@ -215,13 +243,25 @@ namespace //@@ need to use FQ-names. // - os << "if (n == " << L << " (\"" << name << "\"))" + os << (first_ ? "if (n == " : "else if (n == ") + << L << " (\"" << name << "\"))" << "{"; + first_ = false; if (a.optional ()) { - os << type << " t (a);" - << id (name) << " (t);"; + if (this->read_only_) + { + if (this->cppmode_ != CPPMODE::CPP03) + os << id (name) << "_ = std::make_unique<" << type << "> (a);"; + else + os << id (name) << "_ = " << scope << "::" << id(name) + << "_type (new " << type << " (a));" + << id (name) << "_->container (this);"; + } + else + os << type << " t (a);" + << id (name) << " (t);"; } else { @@ -294,9 +334,11 @@ namespace << ", this);"; } - os << "}" - << "else "; + os << "}"; } + + private: + bool first_; }; // Traverser for CDR write operations @@ -346,7 +388,7 @@ namespace // Convert it to its base type. This will // have an operator << defined to // serialize this type - os << "stream << static_cast < const Base& > (*this);" << std::endl; + os << "stream << static_cast < const " << type << "& > (*this);" << std::endl; } // Helper method implementation @@ -359,26 +401,40 @@ namespace // Write length first os << "// " << name << std::endl; os << "size_t " << name << "_size = " - << "this->" << name << "_.size ();" + << "this->" << id (name) << "_.size ();" << "stream << " << name << "_size;" << std::endl; // Write each member next - os << "for (" << name << "_const_iterator " - << name << "_iter = " << "this->begin_" << name << " ();" - << " " << name << "_iter != this->end_" << name - << " ();" - << " ++" << name << "_iter)" - << "{"; + if (this->cppmode_ == CPPMODE::CPP03) + { + os << "for (" << name << "_const_iterator " + << name << "_iter = " << "this->begin_" << name << " ();" + << " " << name << "_iter != this->end_" << name + << " ();" + << " ++" << name << "_iter)" + << "{"; - // Check if the type being written is a boolean - // type - if (type_is_boolean (type)) - os << "stream.write_boolean (*" << name << ");"; + if (type_is_boolean (type)) + os << "stream.write_boolean (*" << name << "_iter);"; + else + os << "stream << (*" << name << "_iter);"; + + os << "}"; + } else - os << "stream << (*" << name << "_iter);"; + { + os << "for (auto const& " << name << "_value : this->" + << id (name) << "_)" + << "{"; - os << "}"; + if (type_is_boolean (type)) + os << "stream.write_boolean (" << name << "_value);"; + else + os << "stream << " << name << "_value;"; + + os << "}"; + } } virtual void @@ -445,16 +501,36 @@ namespace // optional // os << " // " << name << std::endl; - os << "bool " << name << "_p = this->" << name << "_p ();"; - os << "stream.write_boolean (" << name << "_p" << ");"; - - os << "if (" << name << "_p)" - << "{"; + if (!this->optional_via_if_set ()) + { + os << "bool " << name << "_p = this->" << name << "_p ();"; + os << "stream.write_boolean (" << name << "_p" << ");"; + os << "if (" << name << "_p)" << "{"; + } + else + { + if (this->cppmode_ == CPPMODE::CPP03) + os << type << " const* " << name << "_value = this->" << name + << "_if_set ();"; + else + os << "auto const* " << name << "_value = this->" << name + << "_if_set ();"; + os << "stream.write_boolean (" << name << "_value != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") << ");"; + os << "if (" << name << "_value != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") << ")" << "{"; + } // check if the type is a boolean type - if (type_is_boolean (type)) - os << "stream.write_boolean (this->" << name - << " ());" << std::endl; + if (this->optional_via_if_set ()) + { + if (type_is_boolean (type)) + os << "stream.write_boolean (*" << name << "_value);" << std::endl; + else + os << "stream << *" << name << "_value;"; + } + else if (type_is_boolean (type)) + os << "stream.write_boolean (this->" << name << " ());" << std::endl; else os << "stream << this->" << name << " ();"; @@ -510,13 +586,39 @@ namespace os << "// " << name << std::endl; // First write out the boolean value - os << "stream.write_boolean (" << name << "_p ());"; - - os << "if (" << name << "_p ())" - << std::endl; + if (!this->optional_via_if_set ()) + { + os << "stream.write_boolean (" << name << "_p ());"; + os << "if (" << name << "_p ())" << std::endl; + } + else + { + if (this->cppmode_ == CPPMODE::CPP03) + os << type << " const* " << id (name) << "_value = this->" + << id (name) << "_if_set ();"; + else + os << "auto const* " << id (name) << "_value = this->" + << id (name) << "_if_set ();"; + os << "stream.write_boolean (" << id (name) + << "_value != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") + << ");"; + os << "if (" << id (name) << "_value != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") + << ")" + << std::endl; + } // check if the type is a boolean type - if (type_is_boolean (type)) + if (this->optional_via_if_set ()) + { + if (type_is_boolean (type)) + os << " stream.write_boolean (*" << id (name) + << "_value);" << std::endl; + else + os << " stream << *" << id (name) << "_value;" << std::endl; + } + else if (type_is_boolean (type)) os << " stream.write_boolean (this->" << name << " ());" << std::endl; else @@ -583,6 +685,20 @@ namespace } } + string + smart_pointer_type () const + { + return this->cppmode_ == CPPMODE::CPP03 + ? L"std::auto_ptr" + : L"std::unique_ptr"; + } + + string + null_pointer () const + { + return this->cppmode_ == CPPMODE::CPP03 ? L"0" : L"nullptr"; + } + /* * Reading a pointer type. * A type which is read in via the pointer semantics. This @@ -599,7 +715,7 @@ namespace read_pointer_type (string &element_name, string &type) { os << "stream >> " << element_name << "_tmp;" - << "std::auto_ptr < " << type << "::CDR_Type__ > " + << this->smart_pointer_type () << " < " << type << "::CDR_Type__ > " << "auto_" << element_name << " (" << element_name << "_tmp);" << type << " " << element_name << " (" << element_name << "_tmp);" @@ -614,7 +730,7 @@ namespace read_complex_type (string &element_name, string &type) { os << "stream >> " << element_name << ";" - << "std::auto_ptr < " << type << " > " + << this->smart_pointer_type () << " < " << type << " > " << "auto_" << element_name << " (" << element_name << ");" << std::endl; } @@ -653,7 +769,8 @@ namespace bool pointer_semantics = read_type_as_pointer (type); if (pointer_semantics) - os << type << "::CDR_Type__ *" << element_name << "_tmp (0)" + os << type << "::CDR_Type__ *" << element_name << "_tmp (" + << this->null_pointer () << ")" << ";" ; else os << type << "::CDR_Type__ " << element_name << "_tmp" @@ -682,13 +799,18 @@ namespace bool pointer_semantics = read_type_as_pointer (type); if (pointer_semantics) - os << type << "::CDR_Type__ *" << element_name << "_tmp (0)" - << ";" - << "std::auto_ptr < " << type << "::CDR_Type__ > " - << "auto_" << element_name << " (" << element_name << "_tmp);"; + { + os << type << "::CDR_Type__ *" << element_name << "_tmp (" + << this->null_pointer () << ")" + << ";" + << this->smart_pointer_type () << " < " << type << "::CDR_Type__ > " + << "auto_" << element_name << " (" << element_name << "_tmp);"; + } else - os << type << "::CDR_Type__ " << element_name << "_tmp" - << ";" ; + { + os << type << "::CDR_Type__ " << element_name << "_tmp" + << ";"; + } os << "if (" << element_name << "_p)" << "{"; @@ -754,7 +876,7 @@ namespace if (b == e) { - os << type << " *" << name << " (0);"; + os << type << " *" << name << " (" << this->null_pointer () << ");"; read_complex_type (name, type); this->type_name_list_.push_back (L"*" + name); return; @@ -771,7 +893,7 @@ namespace if (has (*c) || dynamic_cast (&t)) { - os << type << " *" << name << "(0);"; + os << type << " *" << name << " (" << this->null_pointer () << ");"; read_complex_type (name, type); this->type_name_list_.push_back (L"*" + name); return; @@ -786,7 +908,8 @@ namespace string base_type (type_name ((**b).inheritee ())); if (read_type_as_pointer (base_type)) { - os << base_type << "::CDR_Type__ *" << name << "_tmp (0);"; + os << base_type << "::CDR_Type__ *" << name << "_tmp (" + << this->null_pointer () << ");"; read_pointer_type (name, base_type); } else @@ -802,7 +925,8 @@ namespace // Simple type: i.e. XMLSchema::boolean, XMLSchema::integer if (read_type_as_pointer (type)) { - os << type << "::CDR_Type__ *" << name << "_tmp (0);"; + os << type << "::CDR_Type__ *" << name << "_tmp (" + << this->null_pointer () << ");"; read_pointer_type (name, type); } else @@ -1141,14 +1265,9 @@ namespace { string type (type_name (c)); - os << "// " << scope << std::endl - << std::endl; - - os << scope << "::" << std::endl - << name << " (" << xml_element_type << " const& element)" << std::endl - << ":" << "Base (element)" - << "{" - << std::endl; + os << scope << "::" << name << " (" << xml_element_type << " const& element)" << std::endl + << ": " << base_type_name (c) << " (element)" + << "{"; } using Traversal::Complex::names; @@ -1169,13 +1288,13 @@ namespace os << "while (p.more_elements ())" << "{" << xml_element_type << " e (p.next_element ());" - << string_type << " n (::XSCRT::XML::uq_name (e.name ()));" + << string_type << " const n (::XSCRT::XML::uq_name (e.name ()));" << std::endl; + element_.reset (); names (c, names_elements_); - os << "{}" // else block - << "}"; // while loop + os << "}"; // while loop } if (ha) @@ -1183,12 +1302,12 @@ namespace os << "while (p.more_attributes ())" << "{" << xml_attribute_type << " a (p.next_attribute ());" - << string_type << " n (::XSCRT::XML::uq_name (a.name ()));"; + << string_type << " const n (::XSCRT::XML::uq_name (a.name ()));"; + attribute_.reset (); names (c, names_attributes_); - os << "{}" // else block - << "}"; // while loop + os << "}"; // while loop } } } @@ -1226,7 +1345,7 @@ namespace // pre os << "// write " << name << std::endl; - os << "bool" << std::endl << name << "::write_" << name + os << "bool " << name << "::write_" << name << " (::XMLSchema::CDR_OutputStream &stream) const" << "{"; @@ -1252,15 +1371,9 @@ namespace { // pre os << "// read " << name << std::endl; - os << "bool" << std::endl << name << "::" << std::endl - << "read_" << name - << " (::XMLSchema::CDR_InputStream &stream," << std::endl; - - for (size_t j =0; j < name.length () + 5; j++) - os << " "; - - os << "::XMLSchema::cdr_arg_traits < " << name - << " >::inout_type element)" + os << "bool " << name << "::read_" << name + << " (::XMLSchema::CDR_InputStream &stream, ::XMLSchema::cdr_arg_traits < " + << name << " >::inout_type element)" << "{"; { @@ -1348,12 +1461,11 @@ namespace virtual void - pre (Type&) + pre (Type& c) { - os << scope << "::" << std::endl - << name << " (" << xml_attribute_type << " const& a)" << std::endl + os << scope << "::" << name << " (" << xml_attribute_type << " const& a)" << std::endl << ":" << std::endl - << "Base (a)" << std::endl + << base_type_name (c) << " (a)" << std::endl << "{"; } @@ -1420,13 +1532,9 @@ namespace enter_scope (name); - os << "// " << scope << std::endl - << std::endl; - // c-tor (Element const&) // - os << scope << "::" << std::endl - << name << " (" << xml_element_type << " const& e)" << std::endl + os << scope << "::" << name << " (" << xml_element_type << " const& e)" << std::endl << ": ::XSCRT::Type (e)" << std::endl << "{" << string_type << " v (e.value ());" @@ -1439,8 +1547,7 @@ namespace // c-tor (Attribute const&) // - os << scope << "::" << std::endl - << name << " (" << xml_attribute_type << " const& a)" << std::endl + os << scope << "::" << name << " (" << xml_attribute_type << " const& a)" << std::endl << ": ::XSCRT::Type (a)" << std::endl << "{" << string_type << " v (a.value ());" @@ -1460,7 +1567,7 @@ namespace { // pre os << "// write " << name << std::endl; - os << "bool" << std::endl << name << "::write_" << name + os << "bool " << name << "::write_" << name << " (::XMLSchema::CDR_OutputStream &stream) const" << "{"; @@ -1482,10 +1589,8 @@ namespace { // pre os << "// read " << name << std::endl; - os << "bool" << std::endl << name << "::read_" << name - << " (::XMLSchema::CDR_InputStream &stream, " - << std::endl - << "::XMLSchema::cdr_arg_traits < " << name + os << "bool " << name << "::read_" << name + << " (::XMLSchema::CDR_InputStream &stream, ::XMLSchema::cdr_arg_traits < " << name << " >::inout_type element)" << std::endl << "{"; diff --git a/XSC/be/CXX/TraversalHeader.cpp b/XSC/be/CXX/TraversalHeader.cpp index 2d7a569..6577c28 100644 --- a/XSC/be/CXX/TraversalHeader.cpp +++ b/XSC/be/CXX/TraversalHeader.cpp @@ -26,6 +26,12 @@ namespace { } + void + declaration (string const& name, string const& type) + { + os << "virtual void " << name << " (" << type << ");" << std::endl; + } + virtual void traverse (SemanticGraph::Element& e) { @@ -43,59 +49,34 @@ namespace // name // - os << "virtual void" << std::endl - << id (name) << " (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << id (name) << " (Type const&);" - << std::endl; + declaration (id (name), L"Type&"); + declaration (id (name), L"Type const&"); // name_pre // - os << "virtual void" << std::endl - << name << "_pre (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_pre (Type const&);" - << std::endl; + declaration (name + L"_pre", L"Type&"); + declaration (name + L"_pre", L"Type const&"); // name_next // - os << "virtual void" << std::endl - << name << "_next (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_next (Type const&);" - << std::endl; + declaration (name + L"_next", L"Type&"); + declaration (name + L"_next", L"Type const&"); // name_post // - os << "virtual void" << std::endl - << name << "_post (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_post (Type const&);" - << std::endl; + declaration (name + L"_post", L"Type&"); + declaration (name + L"_post", L"Type const&"); // name_none // if (e.min () == 0) { - os << "virtual void" << std::endl - << name << "_none (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_none (Type const&);" - << std::endl; + declaration (name + L"_none", L"Type&"); + declaration (name + L"_none", L"Type const&"); } } else if (e.min () == 0) @@ -105,24 +86,14 @@ namespace // name // - os << "virtual void" << std::endl - << id (name) << " (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << id (name) << " (Type const&);" - << std::endl; + declaration (id (name), L"Type&"); + declaration (id (name), L"Type const&"); // name_none // - os << "virtual void" << std::endl - << name << "_none (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_none (Type const&);" - << std::endl; + declaration (name + L"_none", L"Type&"); + declaration (name + L"_none", L"Type const&"); } else { @@ -131,13 +102,8 @@ namespace // name // - os << "virtual void" << std::endl - << id (name) << " (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << id (name) << " (Type const&);" - << std::endl; + declaration (id (name), L"Type&"); + declaration (id (name), L"Type const&"); } } @@ -156,35 +122,20 @@ namespace { // name // - os << "virtual void" << std::endl - << id (name) << " (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << id (name) << " (Type const&);" - << std::endl; + declaration (id (name), L"Type&"); + declaration (id (name), L"Type const&"); // name_none // - os << "virtual void" << std::endl - << name << "_none (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << name << "_none (Type const&);" - << std::endl; + declaration (name + L"_none", L"Type&"); + declaration (name + L"_none", L"Type const&"); } else { // name // - os << "virtual void" << std::endl - << id (name) << " (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << id (name) << " (Type const&);" - << std::endl; + declaration (id (name), L"Type&"); + declaration (id (name), L"Type const&"); } } }; @@ -258,6 +209,7 @@ namespace virtual void pre (Type& c) { + string virtual_string (this->cppmode_ == CPPMODE::CPP03 ? L"virtual " : L""); string override_string (this->cppmode_ != CPPMODE::CPP03 ? L" override" : L""); os << "struct " << e << name_ @@ -266,23 +218,15 @@ namespace // traverse () // - os << "virtual void" << std::endl - << "traverse (Type&)" << override_string << ";" + os << virtual_string << "void traverse (Type&)" << override_string << ";" << std::endl; - - os << "virtual void" << std::endl - << "traverse (Type const&)" << override_string << ";" + os << virtual_string << "void traverse (Type const&)" << override_string << ";" << std::endl; // pre () // - os << "virtual void" << std::endl - << "pre (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << "pre (Type const&);" - << std::endl; + os << "virtual void pre (Type&);" << std::endl; + os << "virtual void pre (Type const&);" << std::endl; } virtual void @@ -290,13 +234,8 @@ namespace { // post () // - os << "virtual void" << std::endl - << "post (Type&);" - << std::endl; - - os << "virtual void" << std::endl - << "post (Type const&);" - << std::endl; + os << "virtual void post (Type&);" << std::endl; + os << "virtual void post (Type const&);" << std::endl; os << "};"; } diff --git a/XSC/be/CXX/TraversalSource.cpp b/XSC/be/CXX/TraversalSource.cpp index 23da4ae..dd8d28b 100644 --- a/XSC/be/CXX/TraversalSource.cpp +++ b/XSC/be/CXX/TraversalSource.cpp @@ -26,6 +26,38 @@ namespace { } + void + optional_member (string const& name, string const& type) + { + os << "void " << scope << "::" + << id (name) << " (Type& o)" << "{"; + + if (!this->optional_via_if_set ()) + os << "dispatch (o." << id (name) << " ());"; + else if (this->cppmode_ == CPPMODE::CPP03) + os << type << " const* value = o." << id (name) + << "_if_set (); if (value) dispatch (*value);"; + else + os << "if (auto* value = o." << id (name) + << "_if_set ()) dispatch (*value);"; + + os << "}"; + + os << "void " << scope << "::" + << id (name) << " (Type const& o)" << "{"; + + if (!this->optional_via_if_set ()) + os << "dispatch (o." << id (name) << " ());"; + else if (this->cppmode_ == CPPMODE::CPP03 || this->read_only_) + os << type << " const* value = o." << id (name) + << "_if_set (); if (value) dispatch (*value);"; + else + os << "if (auto const* value = o." << id (name) + << "_if_set ()) dispatch (*value);"; + + os << "}"; + } + virtual void traverse (SemanticGraph::Element& e) { @@ -45,26 +77,16 @@ namespace // name // - os << "void " << scope << "::" << std::endl - << id (name) << " (Type& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; - - os << "void " << scope << "::" << std::endl - << id (name) << " (Type const& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; + optional_member (name, type); // name_none // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type const&)" << "{" << "}"; @@ -76,17 +98,13 @@ namespace // name // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; + << "{dispatch (o." << id (name) << " ());}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type const& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; + << "{dispatch (o." << id (name) << " ());}"; } else { @@ -95,11 +113,12 @@ namespace // name // - os << "void " << scope << "::" << std::endl - << id (name) << " (Type& o)" + string iterator_type (fq_name (e, L"", false)); + iterator_type += this->read_only_ ? L"_const_iterator" : L"_iterator"; + + os << "void " << scope << "::" << id (name) << " (Type& o)" << "{" - << "// VC6 anathema strikes again" << std::endl - << fq_name (e, L"", false) << "_iterator " + << (this->cppmode_ == CPPMODE::CPP03 ? iterator_type : L"auto") << " " << "b (o.begin_" << name << "()), " << "e (o.end_" << name << "());" << std::endl @@ -107,11 +126,6 @@ namespace << "{" << name << "_pre (o);" - //@@ VC6 - // - // << "iterate_and_dispatch< " << scope << ", Type > " << - //"(b, e, *this, &" << scope << "::" << name << "_next, o);" - << "for (; b != e;)" << "{" << (this->cppmode_ == CPPMODE::CPP03 ? "dispatch (*(*b));" : "dispatch (*b);") @@ -127,11 +141,11 @@ namespace os << "}"; - os << "void " << scope << "::" << std::endl - << id (name) << " (Type const& o)" + os << "void " << scope << "::" << id (name) << " (Type const& o)" << "{" - << "// VC6 anathema strikes again" << std::endl - << fq_name (e, L"", false) << "_const_iterator " + << (this->cppmode_ == CPPMODE::CPP03 + ? fq_name (e, L"", false) + L"_const_iterator" + : L"auto") << " " << "b (o.begin_" << name << "()), " << "e (o.end_" << name << "());" << std::endl @@ -139,11 +153,6 @@ namespace << "{" << name << "_pre (o);" - //@@ VC6 - // - // << "iterate_and_dispatch< " << scope << ", Type const > " << - //"(b, e, *this, &" << scope << "::" << name << "_next, o);" - << "for (; b != e;)" << "{" << (this->cppmode_ == CPPMODE::CPP03 ? "dispatch (*(*b));" : "dispatch (*b);") @@ -161,12 +170,12 @@ namespace // name_pre // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_pre (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_pre (Type const&)" << "{" << "}"; @@ -174,12 +183,12 @@ namespace // name_next // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_next (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_next (Type const&)" << "{" << "}"; @@ -187,12 +196,12 @@ namespace // name_post // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_post (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_post (Type const&)" << "{" << "}"; @@ -201,12 +210,12 @@ namespace // if (e.min () == 0) { - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type const&)" << "{" << "}"; @@ -230,26 +239,16 @@ namespace { // name // - os << "void " << scope << "::" << std::endl - << id (name) << " (Type& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; - - os << "void " << scope << "::" << std::endl - << id (name) << " (Type const& o)" - << "{" - << "dispatch (o." << id (name) << " ());" - << "}"; + optional_member (name, type_name (a)); // name_none // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_none (Type const&)" << "{" << "}"; @@ -258,14 +257,14 @@ namespace { // name // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type& o)" << "{" << "dispatch (o." << id (name) << " ());" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type const& o)" << "{" << "dispatch (o." << id (name) << " ());" @@ -318,8 +317,14 @@ namespace { // optional // - os << "if (o." << name << "_p ()) " << id (name) << " (o);" - << "else " << name << "_none (o);"; + if (!this->optional_via_if_set ()) + os << "if (o." << name << "_p ()) " << id (name) << " (o);" + << "else " << name << "_none (o);"; + else + os << "if (o." << id (name) << "_if_set () != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") << ") " + << id (name) << " (o);" + << "else " << name << "_none (o);"; } else if (e.min () == 1 && e.max () == 1) { @@ -348,8 +353,14 @@ namespace { // optional // - os << "if (o." << name << "_p ()) " << id (name) << " (o);" - << "else " << name << "_none (o);"; + if (!this->optional_via_if_set ()) + os << "if (o." << name << "_p ()) " << id (name) << " (o);" + << "else " << name << "_none (o);"; + else + os << "if (o." << id (name) << "_if_set () != " + << (this->cppmode_ == CPPMODE::CPP03 ? "0" : "nullptr") << ") " + << id (name) << " (o);" + << "else " << name << "_none (o);"; } else { @@ -435,12 +446,9 @@ namespace //enter_scope (name); - os << "// " << scope << std::endl - << std::endl; - // traverse (Type&) // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "traverse (Type& o)" << "{" << "pre (o);"; @@ -453,7 +461,7 @@ namespace // traverse (Type const&) // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "traverse (Type const& o)" << "{" << "pre (o);"; @@ -467,12 +475,12 @@ namespace // pre () // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "pre (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "pre (Type const&)" << "{" << "}"; @@ -485,12 +493,12 @@ namespace // post () // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "post (Type&)" << "{" << "}"; - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "post (Type const&)" << "{" << "}"; diff --git a/XSC/be/CXX/WriterHeader.cpp b/XSC/be/CXX/WriterHeader.cpp index b6a4edc..930de3a 100644 --- a/XSC/be/CXX/WriterHeader.cpp +++ b/XSC/be/CXX/WriterHeader.cpp @@ -280,11 +280,12 @@ namespace << "}"; } + string virtual_string (this->cppmode_ == CPPMODE::CPP03 ? L"virtual " : L""); string override_string (this->cppmode_ != CPPMODE::CPP03 ? L" override" : L""); // traverse // - os << "virtual void" << std::endl + os << virtual_string << "void" << std::endl << "traverse (Type const&)" << override_string << ";" << std::endl; } @@ -323,6 +324,7 @@ namespace { string name ((this->name_ != L"") ? name_ : id (e.name ())); string type (type_name (e)); + string virtual_string (this->cppmode_ == CPPMODE::CPP03 ? L"virtual " : L""); string override_string (this->cppmode_ != CPPMODE::CPP03 ? L" override" : L""); string default_string (this->cppmode_ != CPPMODE::CPP03 ? L" = default" : L""); @@ -350,7 +352,7 @@ namespace // traverse // - os << "virtual void" << std::endl + os << virtual_string << "void" << std::endl << "traverse (Type const&)" << override_string << ";" << std::endl; diff --git a/XSC/be/CXX/WriterSource.cpp b/XSC/be/CXX/WriterSource.cpp index f9d3b7a..dd7f9e2 100644 --- a/XSC/be/CXX/WriterSource.cpp +++ b/XSC/be/CXX/WriterSource.cpp @@ -47,7 +47,7 @@ namespace // pre // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_pre (Type const&)" << "{" << "push_ (" << xml_element_type << " (" << @@ -58,7 +58,7 @@ namespace // next // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_next (Type const& o)" << "{" << name << "_post (o);" @@ -68,7 +68,7 @@ namespace // post // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << name << "_post (Type const&)" << "{" << "pop_ ();" @@ -78,7 +78,7 @@ namespace { // optional & one // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type const& o)" << "{" << "push_ (" << xml_element_type << " (" << @@ -114,7 +114,7 @@ namespace bool q (a.qualified ()); - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << id (name) << " (Type const& o)" << "{" << xml_attribute_type << " a (" << @@ -229,11 +229,9 @@ namespace { string name (id (name_)); - os << "// " << name << std::endl; - // c-tor (XML::Element&) // - os << scope << "::" << std::endl + os << scope << "::" << name << " (" << xml_element_type << "& e)" << std::endl << ": ::XSCRT::Writer<" << char_type << "> (e)" << std::endl << "{" @@ -243,7 +241,7 @@ namespace // if (this->cppmode_ == CPPMODE::CPP03) { - os << scope << "::" << std::endl + os << scope << "::" << name << " ()" << "{" << "}"; @@ -251,7 +249,7 @@ namespace // traverse // - os << "void " << scope << "::" << std::endl + os << "void " << scope << "::" << "traverse (Type const& o)" << "{"; @@ -286,9 +284,9 @@ namespace string name (e.name ()); string type (type_name (e)); - os << "if (o == " << type << "::" << id (name) << ") " << - "s = " << L << " (\"" << name << "\")" << ";" - << "else "; + os << "case " << type << "::" << id (name) << "_l: " + << "s = " << L << " (\"" << name << "\"); " + << "break;"; } }; @@ -307,12 +305,9 @@ namespace { string name ((this->name_ != L"") ? id(name_) : id (c.name ())); - os << "// " << name << std::endl - << std::endl; - // c-tor (XML::Element&) // - os << name << "::" << std::endl + os << name << "::" << name << " (" << xml_element_type << "& e)" << std::endl << ": ::XSCRT::Writer<" << char_type << "> (e)" << std::endl << "{" @@ -322,7 +317,7 @@ namespace // if (this->cppmode_ == CPPMODE::CPP03) { - os << name << "::" << std::endl + os << name << "::" << name << " ()" << "{" << "}"; @@ -330,15 +325,17 @@ namespace // traverse // - os << "void " << name << "::" << std::endl + os << "void " << name << "::" << "traverse (Type const& o)" << "{" << string_type << " s;" - << std::endl; + << "switch (o.integral ())" + << "{"; names (c, names_); - os << "{}" + os << "default: break;" + << "}" << "if (::XSCRT::XML::Attribute< " << char_type << " >* a = attr_ ())" << "{" << "a->value (s);" @@ -540,12 +537,13 @@ namespace << "xercesc::DOMElement* dom_element = d->getDocumentElement ();" << "if (!dom_element)" << "{" - << "throw 1;" + << "throw std::runtime_error (\"XML document has no root element\");" << "}" << xml_element_type << " e (dom_element);" << "if (e.name () != " << L << " (\"" << name << "\"))" << "{" - << "throw 1;" + << "throw std::runtime_error (\"unexpected XML root element; expected <" + << name << ">\");" << "}"; os << "struct W : "; diff --git a/XSC/be/IDL/Generator.cpp b/XSC/be/IDL/Generator.cpp index a9ba7ae..f51425a 100644 --- a/XSC/be/IDL/Generator.cpp +++ b/XSC/be/IDL/Generator.cpp @@ -6,6 +6,7 @@ #include "Declaration.hpp" #include "Definition.hpp" #include "XSC/SemanticGraph.hpp" +#include "XSC/Version.hpp" #include "CCF/CodeGenerationKit/Regex.hpp" #include "CCF/CodeGenerationKit/IndentationIDL.hpp" #include "CCF/CodeGenerationKit/IndentationImplanter.hpp" @@ -55,6 +56,16 @@ namespace IDL return; } + idl << L"// Generated by XSC version " << XSC::wide_version << std::endl + << L"// Arguments: "; + std::string const& arguments {options.value ("arguments")}; + for (char c : arguments) + { + unsigned char const u {static_cast (c)}; + idl << (u < 0x80 ? static_cast (u) : L'?'); + } + idl << std::endl; + // Banner. // { @@ -78,7 +89,6 @@ namespace IDL } } - // // string char_type; diff --git a/XSC/utils/XML_Helper.h b/XSC/utils/XML_Helper.h deleted file mode 100644 index 3b1c571..0000000 --- a/XSC/utils/XML_Helper.h +++ /dev/null @@ -1,90 +0,0 @@ -//============================================================ -/** - * @file XML_Helper.h - * - * @brief Some helper functions for XML - * - * @author Bala Natarajan - * @author William R. Otte - */ -//============================================================ -#ifndef CIAO_XML_HELPER_H -#define CIAO_XML_HELPER_H - -#include "XML_Error_Handler.h" -#include "XML_Schema_Resolver.h" - -#include - -#include "xercesc/util/XercesDefs.hpp" -#include "xercesc/parsers/XercesDOMParser.hpp" - -namespace XSC -{ - namespace XML - { - /** - * @class XML_Helper - * - * @brief Helper class for some routine XML stuff. - */ - template , - typename Error_Handler = XML_Error_Handler> - class XML_Helper - { - public: - // XML_Helper (); - - // Initialize the resolver we should use. - XML_Helper (Resolver &resolver, Error_Handler &eh); - - ~XML_Helper (); - - /// Create a DOM tree - xercesc::DOMDocument * - create_dom (const char *uri) const; - - xercesc::DOMDocument * - create_dom (const char *root, - const char *ns, - xercesc::DOMDocumentType * doctype = nullptr) const; - - xercesc::DOMDocumentType * - create_doctype (const char *qn, - const char *pid, - const char *sid) const; - - //Writes out a DOMDocument to an XML file - bool write_DOM (xercesc::DOMDocument *doc, - const char *file) const; - - bool is_initialized () const; - - protected: - /// Intialize the parser - void init_parser (); - - /// Terminate the parser - void terminate_parser (); - - private: - XML_Helper (XML_Helper const&) = delete; - XML_Helper& operator= (XML_Helper const&) = delete; - XML_Helper (XML_Helper&&) = delete; - XML_Helper& operator= (XML_Helper&&) = delete; - - bool initialized_ {}; - xercesc::DOMImplementation *impl_ {}; - mutable std::unique_ptr parser_; - - Resolver &resolver_; - Error_Handler &e_handler_; - }; - - - } -} - -#include "XML_Helper_T.cpp" - -#endif/*CIAO_CONFIG_HANDLERS_XML_HELPER_H*/ diff --git a/XSC/utils/XML_Helper_T.cpp b/XSC/utils/XML_Helper_T.cpp deleted file mode 100644 index ec4b0d6..0000000 --- a/XSC/utils/XML_Helper_T.cpp +++ /dev/null @@ -1,243 +0,0 @@ -#include "XML_Helper.h" -#include "XML_Error_Handler.h" -#include "XML_Schema_Resolver.h" -#include "XercesString.h" -#include "xercesc/dom/DOM.hpp" -#include "xercesc/util/XMLUniDefs.hpp" - -namespace XSC -{ - namespace XML - { - using xercesc::XMLException; - using xercesc::XMLString; - using xercesc::DOMImplementation; - using xercesc::DOMImplementationRegistry; -// using xercesc::DOMBuilder; - using xercesc::DOMDocument; - using xercesc::DOMException; - using xercesc::DOMDocumentType; -/* - template - XML_Helper::XML_Helper () - { - this->init_parser (); - } -*/ - // TODO this is stub implementation - template - XML_Helper::XML_Helper (Resolver &resolver, Error &eh) - : resolver_ (resolver), - e_handler_ (eh) - { - this->init_parser (); - } - - template - XML_Helper::~XML_Helper () - { - this->terminate_parser (); - } - - template - bool - XML_Helper::is_initialized () const - { - return this->initialized_ == true; - } - - template - void - XML_Helper::init_parser () - { - if (this->initialized_) - return; - - /*ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Initializing the Xerces runtime \n"));*/ - // Initialize the Xerces run-time - try - { - xercesc::XMLPlatformUtils::Initialize(); - } - catch (const XMLException& e) - { - char* message = - XMLString::transcode (e.getMessage()); - // ACE_Auto_Basic_Array_Ptr cleanup_message (message); - XMLString::release (std::addressof (message)); - - throw; - } - catch (...) - { - /*ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Some other exception," - " returning\n"));*/ - - return; - } - - // Instantiate the DOM parser. - static const XMLCh gLS[] = { xercesc::chLatin_L, - xercesc::chLatin_S, - xercesc::chNull }; - - // Get an implementation of the Load-Store (LS) interface - // and cache it for later use - impl_ = - DOMImplementationRegistry::getDOMImplementation(gLS); - - this->initialized_ = true; - return; - } - - template - xercesc::DOMDocument * - XML_Helper::create_dom (const char *root, - const char *ns, - DOMDocumentType *doctype) const - { - if (root == nullptr || ns == nullptr) - return nullptr; - - return this->impl_->createDocument (XStr (ns), - XStr (root), - doctype); - } - - template - xercesc::DOMDocumentType * - XML_Helper::create_doctype (const char *qn, - const char *pid, - const char *sid) const - { - return this->impl_->createDocumentType (XStr (qn), - XStr (pid), - XStr (sid)); - } - template - xercesc::DOMDocument * - XML_Helper::create_dom (const char *url) const - { - - if (url == nullptr) - return nullptr; - - try - { - if (this->parser_.get () == nullptr) - this->parser_ = std::make_unique (); - - // Perform Namespace processing. - this->parser_->setDoNamespaces (true); - - // Discard comment nodes in the document - this->parser_->setCreateCommentNodes (false); - - // Disable datatype normalization. The XML 1.0 attribute value - // normalization always occurs though. - // this->parser_->setFeature (XMLUni::fgDOMDatatypeNormalization, true); - - // Do not create EntityReference nodes in the DOM tree. No - // EntityReference nodes will be created, only the nodes - // corresponding to their fully expanded sustitution text will be - // created. - this->parser_->setCreateEntityReferenceNodes (false); - - // Perform Validation - this->parser_->setValidationScheme (xercesc::AbstractDOMParser::Val_Always); - - // Do not include ignorable whitespace in the DOM tree. - this->parser_->setIncludeIgnorableWhitespace (false); - - // Enable the parser's schema support. - this->parser_->setDoSchema (true); - - // Enable full schema constraint checking, including checking which - // may be time-consuming or memory intensive. Currently, particle - // unique attribution constraint checking and particle derivation - // restriction checking are controlled by this option. - this->parser_->setValidationSchemaFullChecking (true); - - // The parser will treat validation error as fatal and will exit. - this->parser_->setValidationConstraintFatal (true); - - this->parser_->setErrorHandler (std::addressof (e_handler_)); - - this->parser_->setEntityResolver (std::addressof (resolver_)); - - this->parser_->parse (url); - - if (e_handler_.getErrors ()) - return nullptr; - - return this->parser_->adoptDocument (); - } - catch (const DOMException& e) - { - const unsigned int maxChars = 2047; - XMLCh errText[maxChars + 1]; - - if (DOMImplementation::loadDOMExceptionMsg (e.code, - errText, - maxChars)) - { - char* message = - XMLString::transcode (errText); -// ACE_Auto_Basic_Array_Ptr cleanup_message (message); - XMLString::release (std::addressof (message)); - } - return nullptr; - - } - catch (const XMLException& e) - { - char* message = XMLString::transcode (e.getMessage()); - // ACE_Auto_Basic_Array_Ptr cleanup_message (message); - XMLString::release (std::addressof (message)); - throw; - } - catch (...) - { - /*ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Caught an unknown exception \n"));*/ - throw; - } - - return nullptr; - } - - template - void - XML_Helper::terminate_parser () - { - try - { - xercesc::XMLPlatformUtils::Terminate(); - } - catch (const XMLException& e) - { - char* message = - XMLString::transcode (e.getMessage()); - //ACE_Auto_Basic_Array_Ptr cleanup_message (message); - XMLString::release (std::addressof (message)); - - throw; - } - - this->initialized_ = false; - return; - } - - template - bool - XML_Helper::write_DOM (xercesc::DOMDocument *doc, - const char *file) const - { - (void) doc; - (void) file; - return false; - } - } -} diff --git a/XSC/utils/XML_Schema_Resolver.h b/XSC/utils/XML_Schema_Resolver.h index 775d2aa..8e76200 100644 --- a/XSC/utils/XML_Schema_Resolver.h +++ b/XSC/utils/XML_Schema_Resolver.h @@ -10,7 +10,6 @@ #include "XSC_Utils_export.h" #include "XercesString.h" -#include "XML_Error_Handler.h" #include "xercesc/sax/EntityResolver.hpp" #include "ace/ace_wchar.h" #include diff --git a/XSC/utils/XSC_Utils.mpc b/XSC/utils/XSC_Utils.mpc index d854131..d52bae9 100644 --- a/XSC/utils/XSC_Utils.mpc +++ b/XSC/utils/XSC_Utils.mpc @@ -8,7 +8,6 @@ project (XSC_Utils) : acelib, xsc_common { } Template_Files { - XML_Helper_T.cpp XML_Schema_Resolver.cpp } } diff --git a/XSC/xsc.cpp b/XSC/xsc.cpp index 3142305..61315d4 100644 --- a/XSC/xsc.cpp +++ b/XSC/xsc.cpp @@ -27,11 +27,14 @@ #include #include #include +#include +#include #include #include #include "ace/Get_Opt.h" #include "XSC/Options.hpp" +#include "XSC/Version.hpp" #include "XSC/Parser.hpp" #include "XSC/be/CXX/Validator.hpp" #include "XSC/be/CXX/Generator.hpp" @@ -39,8 +42,6 @@ using namespace XSC; -wchar_t const* const version = L"0.0.8"; - /** * @class ErrorDetector * @@ -140,6 +141,8 @@ namespace {"cxx-cpp03", ACE_Get_Opt::NO_ARG, "Generate C++03-compatible code."}, {"cxx-cpp11", ACE_Get_Opt::NO_ARG, "Generate C++11 code."}, {"cxx-cpp17", ACE_Get_Opt::NO_ARG, "Generate C++17 code."}, + {"cxx-read-only", ACE_Get_Opt::NO_ARG, + "Generate read-only C++ data types (omit CDR reader APIs)."}, {"idl-char-type", ACE_Get_Opt::ARG_REQUIRED, "Generated IDL character type."}, {"idl-namespace-regex", ACE_Get_Opt::ARG_REQUIRED, "IDL namespace mapping regex (repeatable)."}, {"idl-file-suffix", ACE_Get_Opt::ARG_REQUIRED, "Generated IDL suffix."}, @@ -154,6 +157,34 @@ namespace name == "idl-namespace-regex"; } + std::string + shell_quote (std::string_view argument) + { + std::string quoted ("'"); + for (char c : argument) + { + if (c == '\'') + quoted += "'\\''"; + else + quoted += c; + } + quoted += '\''; + return quoted; + } + + std::string + invocation (int argc, char* argv[]) + { + std::string result; + for (int i {1}; i != argc; ++i) + { + if (i != 1) + result += ' '; + result += shell_quote (argv[i]); + } + return result; + } + void print_help (std::string_view backend) { @@ -187,6 +218,7 @@ int main (int argc, char* argv[]) { try { + std::string const original_arguments {invocation (argc, argv)}; XSC::Options command_line; ACE_Get_Opt get_opt (argc, argv, "", 1, 0, ACE_Get_Opt::PERMUTE_ARGS); @@ -219,7 +251,7 @@ int main (int argc, char* argv[]) if (command_line.count ("version")) { - std::wcerr << "XML Schema compiler " << version << std::endl; + std::wcerr << "XML Schema compiler " << XSC::wide_version << std::endl; return 0; } @@ -235,6 +267,7 @@ int main (int argc, char* argv[]) return 1; } + command_line.set ("arguments", original_arguments); command_line.set ("input-file", get_opt.argv ()[get_opt.opt_ind ()]); auto set_default = [&command_line] (std::string const& name, std::string const& value) @@ -352,6 +385,11 @@ int main (int argc, char* argv[]) return 0; } + catch (std::exception const& e) + { + std::cerr << "error: " << e.what () << std::endl; + return 1; + } catch (...) { std::wcerr << "caught unknown exception" << std::endl; diff --git a/XSCRT/XMLSchema/Traversal.hpp b/XSCRT/XMLSchema/Traversal.hpp deleted file mode 100644 index f03b843..0000000 --- a/XSCRT/XMLSchema/Traversal.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// file : XMLSchema/Traversal.hpp -// author : Boris Kolpackov - -#ifndef XMLSCHEMA_TRAVERSAL_HPP -#define XMLSCHEMA_TRAVERSAL_HPP - -#include -#include - -namespace XMLSchema -{ - namespace Traversal - { - // Automatic traversal of IDREFs. - // - // - struct IDREF : - XSCRT::Traversal::Traverser - { - virtual void - traverse (XMLSchema::IDREF_Base& r) - { - if (r.get ()) dispatch (*(r.get ())); - } - - virtual void - traverse (XMLSchema::IDREF_Base const& r) - { - if (r.get ()) dispatch (*(r.get ())); - } - }; - - - template - struct Traverser : XSCRT::Traversal::Traverser - { - }; - - typedef Traverser byte; - typedef Traverser unsignedByte; - - typedef Traverser short_; - typedef Traverser unsignedShort; - - typedef Traverser int_; - typedef Traverser unsignedInt; - - typedef Traverser long_; - typedef Traverser unsignedLong; - - typedef Traverser boolean; - - typedef Traverser float_; - typedef Traverser double_; - - template - struct string : Traverser > - { - }; - - template - struct ID : Traverser > - { - }; - - template - struct anyURI : Traverser > - { - }; - } -} - -#include - -#endif // XMLSCHEMA_TRAVERSAL_HPP diff --git a/XSCRT/XMLSchema/Traversal.tpp b/XSCRT/XMLSchema/Traversal.tpp deleted file mode 100644 index 9a8a219..0000000 --- a/XSCRT/XMLSchema/Traversal.tpp +++ /dev/null @@ -1,10 +0,0 @@ -// file : XMLSchema/Traversal.tpp -// author : Boris Kolpackov - -namespace XMLSchema -{ - namespace Traversal - { - - } -} diff --git a/XSCRT/XMLSchema/TypeInfo.hpp b/XSCRT/XMLSchema/TypeInfo.hpp deleted file mode 100644 index bfc1e33..0000000 --- a/XSCRT/XMLSchema/TypeInfo.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// file : XMLSchema/TypeInfo.hpp -// author : Boris Kolpackov - -#ifndef XMLSCHEMA_TYPE_INFO_HPP -#define XMLSCHEMA_TYPE_INFO_HPP - -#include - -namespace XMLSchema -{ - template - struct TypeInfoInitializer - { - TypeInfoInitializer (XSCRT::ExtendedTypeInfoMap&); - }; -} - -#include - -#endif // XMLSCHEMA_TYPE_INFO_HPP diff --git a/XSCRT/XMLSchema/TypeInfo.tpp b/XSCRT/XMLSchema/TypeInfo.tpp deleted file mode 100644 index 3f4a8d2..0000000 --- a/XSCRT/XMLSchema/TypeInfo.tpp +++ /dev/null @@ -1,100 +0,0 @@ -// file : XMLSchema/TypeInfo.tpp -// author : Boris Kolpackov - -namespace XMLSchema -{ - //@@ VC6 - // - template - void - add_info (XSCRT::ExtendedTypeInfoMap& map, T*) - { - using XSCRT::TypeId; - using XSCRT::ExtendedTypeInfo; - using std::make_pair; - - TypeId id (typeid (T)); - ExtendedTypeInfo info (id); - - info.add_base (ExtendedTypeInfo::Access::public_, - false, - typeid (XSCRT::Type)); - - map.insert (make_pair (id, info)); - } - - - template - inline - TypeInfoInitializer:: - TypeInfoInitializer (XSCRT::ExtendedTypeInfoMap& map) - { - using XSCRT::TypeId; - using XSCRT::ExtendedTypeInfo; - using std::make_pair; - - // XSCRT::Type - // - { - TypeId id (typeid (XSCRT::Type)); - map.insert (make_pair (id, ExtendedTypeInfo (id))); - } - - //@@ VC6 - - add_info (map, 0); - add_info (map, 0); - - add_info (map, 0); - add_info (map, 0); - - add_info (map, 0); - add_info (map, 0); - - add_info (map, 0); - add_info (map, 0); - - add_info (map, 0); - - add_info (map, 0);; - add_info (map, 0); - - add_info > (map, 0); - - add_info > (map, 0); - add_info > (map, 0); - add_info > (map, 0); - add_info > (map, 0); - add_info > (map, 0); - - add_info > (map, 0); - - add_info > (map, 0); - - // IDREF_Base - // - { - TypeId id (typeid (IDREF_Base)); - ExtendedTypeInfo info (id); - - info.add_base (ExtendedTypeInfo::Access::public_, - false, - typeid (XSCRT::Type)); - - map.insert (make_pair (id, info)); - } - - // IDREF - // - { - TypeId id (typeid (IDREF)); - ExtendedTypeInfo info (id); - - info.add_base (ExtendedTypeInfo::Access::public_, - false, - typeid (IDREF_Base)); - - map.insert (make_pair (id, info)); - } - } -} diff --git a/XSCRT/XMLSchema/Types.hpp b/XSCRT/XMLSchema/Types.hpp deleted file mode 100644 index a60df08..0000000 --- a/XSCRT/XMLSchema/Types.hpp +++ /dev/null @@ -1,629 +0,0 @@ -// file : XMLSchema/Types.hpp -// author : Boris Kolpackov - -#ifndef XMLSCHEMA_TYPES_HPP -#define XMLSCHEMA_TYPES_HPP - -#include -#include - -namespace XMLSchema -{ - typedef XSCRT::FundamentalType byte; - typedef XSCRT::FundamentalType unsignedByte; - - typedef XSCRT::FundamentalType short_; - typedef XSCRT::FundamentalType unsignedShort; - - typedef XSCRT::FundamentalType int_; - typedef XSCRT::FundamentalType unsignedInt; - - //@@ VC6 -#if defined (_MSC_VER) && (_MSC_VER < 1300) - - typedef XSCRT::FundamentalType<__int64> long_; - typedef XSCRT::FundamentalType unsignedLong; - -#else - - typedef XSCRT::FundamentalType long_; - typedef XSCRT::FundamentalType unsignedLong; - -#endif - - //@@ It would be nice to use some arbitrary-length integer class. - // - typedef long_ decimal; - typedef decimal integer; - typedef integer nonPositiveInteger; - typedef integer nonNegativeInteger; - typedef nonNegativeInteger positiveInteger; - typedef nonPositiveInteger negativeInteger; - - - typedef XSCRT::FundamentalType boolean; - - typedef XSCRT::FundamentalType float_; - typedef XSCRT::FundamentalType double_; - - // Just to make GCC 3.3 and other broken compilers shutup. - // - using std::basic_string; - - template - class string : public XSCRT::Type, public basic_string - { - protected: - typedef basic_string Base__ ; - - public: - // Trait for marshaling string - typedef C CDR_Type__; - - //@@ VC6 does not inject XSCRT::Type into the scope so I have - // to qualify it all the time. - // - - string () - { - } - - string (XSCRT::XML::Element const& e) - : Base__ (e.value ()) - { - } - - string (XSCRT::XML::Attribute const& a) - : Base__ (a.value ()) - { - } - - explicit string (Base__ const& x) - : Base__ (x) - { - } - - explicit string (C const* x) - : Base__ (x) - { - } - - string& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - - template - class normalizedString : public string - { - protected: - typedef typename string::Base__ Base__; - - public: - normalizedString () - { - } - - explicit normalizedString (XSCRT::XML::Element const& e) - : string (e) - { - } - - normalizedString (XSCRT::XML::Attribute const& a) - : string (a) - { - } - - normalizedString (Base__ const& x) - : string (x) - { - } - - normalizedString (C const* x) - : string (x) - { - } - - normalizedString& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - - template - class token : public normalizedString - { - protected: - typedef typename normalizedString::Base__ Base__; - - public: - token () - { - } - - explicit token (XSCRT::XML::Element const& e) - : normalizedString (e) - { - } - - token (XSCRT::XML::Attribute const& a) - : normalizedString (a) - { - } - - token (Base__ const& x) - : normalizedString (x) - { - } - - token (C const* x) - : normalizedString (x) - { - } - - token& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - - template - class NMTOKEN : public token - { - protected: - typedef typename token::Base__ Base__; - - public: - NMTOKEN () - { - } - - NMTOKEN (XSCRT::XML::Element const& e) - : token (e) - { - } - - NMTOKEN (XSCRT::XML::Attribute const& a) - : token (a) - { - } - - NMTOKEN (Base__ const& x) - : token (x) - { - } - - NMTOKEN (C const* x) - : token (x) - { - } - - NMTOKEN& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - template - class Name: public token - { - protected: - typedef typename token::Base__ Base__; - - public: - Name() - { - } - - Name(XSCRT::XML::Element const& e) - : token (e) - { - } - - Name(XSCRT::XML::Attribute const& a) - : token (a) - { - } - - Name(Base__ const& x) - : token (x) - { - } - - Name (C const* x) - : token (x) - { - } - - Name& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - - template - class NCName: public Name - { - protected: - typedef typename Name::Base__ Base__; - - public: - NCName() - { - } - - explicit NCName(XSCRT::XML::Element const& e) - : Name (e) - { - } - - explicit NCName(XSCRT::XML::Attribute const& a) - : Name (a) - { - } - - explicit NCName(Base__ const& x) - : Name (x) - { - } - - NCName (C const* x) - : Name (x) - { - } - - NCName& - operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; - - template - struct IdentityProvider : XSCRT::IdentityProvider - { - IdentityProvider (NCName const& id) - : id_ (id) - { - } - - virtual ~IdentityProvider () - { - - } - - virtual bool - before (XSCRT::IdentityProvider const& y) const - { - return id_ < dynamic_cast (y).id_; - } - - private: - NCName const& id_; - - private: - IdentityProvider (IdentityProvider const&); - - IdentityProvider& - operator= (IdentityProvider const&); - }; - - - template - class ID : public NCName - { - protected: - typedef typename NCName::Base__ Base__; - - public: - virtual ~ID() - { - unregister_id (); - } - - ID () - : id_provider_ (*this) - { - } - - explicit ID (XSCRT::XML::Element const& e) - : NCName (e), id_provider_ (*this) - { - } - - explicit ID (XSCRT::XML::Attribute const& a) - : NCName (a), id_provider_ (*this) - { - } - - ID (ID const& x) - : NCName (x), id_provider_ (*this) - { - } - - ID (Base__ const& x) - : NCName (x), id_provider_ (*this) - { - } - - ID (C const* x) - : NCName (x), id_provider_ (*this) - { - } - - ID& - operator= (Base__ const& x) - { - unregister_id (); - - static_cast&>(*this) = x; - - register_id (); - - return *this; - } - - ID& - operator= (ID const& x) - { - unregister_id (); - - static_cast&>(*this) = static_cast const&>(x); - - register_id (); - - return *this; - } - - public: - using NCName::container; - - virtual void - container (XSCRT::Type* c) - { - unregister_id (); - - NCName::container (c); - - register_id (); - } - - private: - using NCName::empty; - using NCName::root; - - void - register_id () - { - if (container () != this && !empty ()) - { - //std::wcerr << "registering " << container () - // << " as '" << *this - // << "' on " << container () << std::endl; - container ()->register_id (id_provider_, container ()); - } - } - - void - unregister_id () - { - if (container () != this && !empty ()) - { - //std::wcerr << "un-registering " << container () - // << " as '" << *this - // << "' on " << container () << std::endl; - container ()->unregister_id (id_provider_); - } - } - - private: - IdentityProvider id_provider_; - }; - - struct IDREF_Base : public XSCRT::Type - { - virtual XSCRT::Type const* - get () const = 0; - - virtual XSCRT::Type* - get () = 0; - }; - - template - class IDREF : public IDREF_Base - { - public: - // Trait for marshaling IDREF - typedef C CDR_Type__; - IDREF () - : id_provider_ (id_) - { - } - - IDREF (XSCRT::XML::Element const& e) - : id_ (e), id_provider_ (id_) - { - } - - IDREF (XSCRT::XML::Attribute const& a) - : id_ (a), id_provider_ (id_) - { - } - - IDREF (IDREF const& x) - : id_ (x.id_), id_provider_ (id_) - { - } - - IDREF (basic_string const& id) - : id_ (id), id_provider_ (id_) - { - } - - IDREF (C const* id) - : id_ (id), id_provider_ (id_) - { - } - - IDREF& - operator= (IDREF const& x) - { - id_ = x.id_; - return *this; - } - - IDREF& - operator= (basic_string const& x) - { - id_ = x; - return *this; - } - - public: - NCName - id () const - { - return id_; - } - - public: - XSCRT::Type const* - operator-> () const - { - return get (); - } - - XSCRT::Type* - operator-> () - { - return get (); - } - - XSCRT::Type const& - operator* () const - { - return *(get ()); - } - - XSCRT::Type& - operator* () - { - return *(get ()); - } - - virtual XSCRT::Type const* - get () const - { - if (!id_.empty () && container () != this) - { - return root ()->lookup_id (id_provider_); - } - else - { - return 0; - } - } - - virtual XSCRT::Type* - get () - { - if (!id_.empty () && container () != this) - { - return root ()->lookup_id (id_provider_); - } - else - { - return 0; - } - } - - // conversion to bool - // - typedef void (IDREF::*bool_convertable)(); - - operator bool_convertable () const - { - return get () ? &IDREF::true_ : 0; - } - - private: - void true_ () - { - } - - private: - NCName id_; - IdentityProvider id_provider_; - }; - - template - class anyURI : public XSCRT::Type, public basic_string - { - protected: - typedef basic_string Base__ ; - - public: - // Trait for marshaling string - typedef C CDR_Type__; - - //@@ VC6 does not inject XSCRT::Type into the scope so I have - // to qualify it all the time. - // - - anyURI () - { - } - - anyURI (XSCRT::XML::Element const& e) - : Base__ (e.value ()) - { - } - - explicit anyURI (XSCRT::XML::Attribute const& a) - : Base__ (a.value ()) - { - } - - anyURI (Base__ const& x) - : Base__ (x) - { - } - - anyURI (C const * x) - : Base__ (x) - { - } - - anyURI (const anyURI& s) - : Base__ (s) - { - - } - - anyURI & operator= (Base__ const& x) - { - static_cast (*this) = x; - return *this; - } - }; -} - -#include - -#endif // XMLSCHEMA_TYPES_HPP diff --git a/XSCRT/XMLSchema/Types.tpp b/XSCRT/XMLSchema/Types.tpp deleted file mode 100644 index 0a42460..0000000 --- a/XSCRT/XMLSchema/Types.tpp +++ /dev/null @@ -1,8 +0,0 @@ -// file : XMLSchema/Types.tpp -// author : Boris Kolpackov - -namespace XMLSchema -{ - -} - diff --git a/XSCRT/XMLSchema/Writer.hpp b/XSCRT/XMLSchema/Writer.hpp deleted file mode 100644 index 40e481f..0000000 --- a/XSCRT/XMLSchema/Writer.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// file : XMLSchema/Writer.hpp -// author : Boris Kolpackov - -#ifndef XMLSCHEMA_WRITER_HPP -#define XMLSCHEMA_WRITER_HPP - -#include - -#include - -#include -#include - -namespace XMLSchema -{ - namespace Writer - { - template - struct FundamentalType : Traversal::Traverser, - virtual XSCRT::Writer - { - FundamentalType (XSCRT::XML::Element& e) - : XSCRT::Writer (e) - { - } - - using XSCRT::Writer::top_; - using XSCRT::Writer::attr_; - - virtual void - traverse (T const& o) - { - using namespace XSCRT::XML; - - std::basic_ostringstream os; - - os << o; - - if (Attribute* a = attr_ ()) - { - a->value (os.str ()); - } - else - { - top_().value (os.str ()); - } - } - - protected: - FundamentalType () - { - } - }; - - - template - struct IDREF : Traversal::Traverser >, - virtual XSCRT::Writer - { - IDREF (XSCRT::XML::Element& e) - : XSCRT::Writer (e) - { - } - - using XSCRT::Writer::top_; - using XSCRT::Writer::attr_; - - virtual void - traverse ( - typename Traversal::Traverser >::Type const& o) - { - using namespace XSCRT::XML; - - if (Attribute* a = attr_ ()) - { - a->value (o.id ()); - } - else - { - top_().value (o.id ()); - } - } - - protected: - IDREF () - { - } - }; - } -} - -#include - -#endif // XMLSCHEMA_WRITER_HPP diff --git a/XSCRT/XMLSchema/Writer.tpp b/XSCRT/XMLSchema/Writer.tpp deleted file mode 100644 index be4736b..0000000 --- a/XSCRT/XMLSchema/Writer.tpp +++ /dev/null @@ -1,9 +0,0 @@ -// file : XMLSchema/Writer.tpp -// author : Boris Kolpackov - -namespace XMLSchema -{ - namespace Writer - { - } -} diff --git a/XSCRT/XMLSchema/id_map.hpp b/XSCRT/XMLSchema/id_map.hpp deleted file mode 100644 index 74a0f7d..0000000 --- a/XSCRT/XMLSchema/id_map.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// -*- C++ -*- -// - -//============================================================================= -/** - * @file id_map.hpp - * - * This file contains the ID_Map class which has the responsibility of linking - * XML IDREF objects to their XML ID counterparts. In the output files, this - * means that a _ptr() will return a pointer to the identified - * object. - * - * Exception NULL_PTR_Entry is thrown when a program attempts to add a NULL_PTR - * to either the id_map or idref_map. - * - * Exception Unresolved_IDREF is thrown if an element in an XML document attempts - * to reference an ID that does not exist. - * - * @author Jason R. Cody - */ -//============================================================================= - -#ifndef _ID_MAP_H -#define _ID_MAP_H - -//ID_Map makes use of the Types::idref_ data member to set it to the appropriate -//object created during parsing -#include "XMLSchema/Types.hpp" - -//The ID_Map is a Thread Specific Storage element. -#include "ace/TSS_T.h" -#include "ace/ace_wchar.h" - - /** - * @class ID_Map - * - * @brief A class that handles the mapping of IDREF objects to objects with the - * respective ID. - */ - class ID_Map - { - public: - - //Trait to allow for ease of thread specific storage. - typedef ACE_TSS TSS_ID_Map; - typedef std::map, XSCRT::Type*>::iterator id_iterator; - typedef std::multimap, XSCRT::Type*>::iterator idref_iterator; - typedef std::map, XSCRT::Type*> ID_MAP; - typedef std::multimap, XSCRT::Type*> IDREF_MAP; - - - //Exception Classes - //NULL_PTR_Entry thrown when a NULL PTR is added to the - //ID_Map - class NULL_PTR_Entry {}; - - //Unresolved_IDREF thrown when there are IDREF's in the - //XML document. - class Unresolved_IDREF { - public: - explicit Unresolved_IDREF(const std::basic_string &message) : message(message) - {} - ~Unresolved_IDREF(){} - std::basic_string get_message () const - { - return message; - } - private: - std::basic_string message; - }; - - //Only a default constructor and destructor are needed - //Constructor - ID_Map () - { - } - - //Destructor - ~ID_Map () - { - } - - //Add an ID to the ID map - void add_id (const std::basic_string& id, XSCRT::Type *obj_ref) - { - if (obj_ref) - { - this->id_map_.insert (ID_MAP::value_type(id, obj_ref)); - } - else - { - throw NULL_PTR_Entry(); - } - return; - } - - //Add an IDREF to the IDREF map - void add_idref (const std::basic_string& idref, XSCRT::Type *obj_ref) - { - if (obj_ref) - { - this->idref_map_.insert (IDREF_MAP::value_type(idref, obj_ref)); - } - else - { - throw NULL_PTR_Entry(); - } - return; - } - - void resolve_single_idref (const std::basic_string& idref, ::XSCRT::Type * element) - { - ID_Map::id_iterator id_iterator = this->id_map_.find(idref); - if (id_iterator != this->id_map_.end()) - { - element->set_idref(idref, id_iterator->second); - } - else - { - throw Unresolved_IDREF(idref); - } - } - - //Sets the referencing elements XSCRT::Type::idref_ to point to the - //referenced element. - //Note: The pointer is of type "XSCRT::Type*" - void resolve_idref () - { - //Declare iterators to navigate the maps - ID_Map::id_iterator id_iterator; - ID_Map::idref_iterator idref_iterator; - - for (idref_iterator = this->idref_map_.begin(); - idref_iterator != this->idref_map_.end(); - ++idref_iterator) - { - //Find the ID that matches the IDREF element - id_iterator = this->id_map_.find(idref_iterator->first); - if (id_iterator != this->id_map_.end()) - { - //Add the IDREF identifier and the reference to the - //identified object - std::basic_string temp_id = id_iterator->first; - idref_iterator->second->set_idref(temp_id, id_iterator->second); - } - else - { - std::basic_string temp (idref_iterator->first); - throw Unresolved_IDREF(temp); - } - } - } - - private: - //id_map_: maps the ID string to the element with the - // ID attribute - //idref_map_: multimap that maps the IDREF string to the - // element with the IDREF attribute - ID_MAP id_map_; - IDREF_MAP idref_map_; - }; - -#endif /* _ID_MAP_HPP */ diff --git a/XSCRT/XSCRT/Elements.hpp b/XSCRT/XSCRT/Elements.hpp deleted file mode 100644 index 689e50e..0000000 --- a/XSCRT/XSCRT/Elements.hpp +++ /dev/null @@ -1,438 +0,0 @@ -// file : XSCRT/Elements.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_ELEMENTS_HPP -#define XSCRT_ELEMENTS_HPP - -#include -#include -#include -#include -#include "ace/ace_wchar.h" -// #include //@@ tmp - -#include -#include "ace/Refcounted_Auto_Ptr.h" - -namespace XSCRT -{ - struct IdentityProvider - { - virtual bool - before (IdentityProvider const&) const = 0; - - virtual ~IdentityProvider () = default; - }; - - class Type - { - public: - - virtual ~Type () = default; - - protected: - Type () - : container_ (nullptr) - { - } - - template - Type (XML::Element const&) - : container_ (nullptr) - { - } - - template - Type (XML::Attribute const&) - : container_ (nullptr) - { - } - - Type (Type const&) - : container_ (nullptr) - { - } - - Type& - operator= (Type const&) - { - return *this; - } - - public: - Type const* - container () const - { - return container_ ? container_ : this; - } - - Type* - container () - { - return container_ ? container_ : this; - } - - - Type const* - root () const - { - Type const* r = container (); - - //@@ VC6 can't handle this inside the loop. - // - Type const* c = r->container (); - - for (; c != r; c = c->container ()) r = c; - - return r; - } - - Type* - root () - { - Type* r = container (); - - for (Type* c = r->container (); c != r; c = c->container ()) r = c; - - return r; - } - - //@@ - //protected: - - public: - virtual void - container (Type* c) - { - if (container_ == c) return; - - // Revoke registrations from our old container. - // - if (container_ != nullptr && map_) - { - for (Map_::iterator i (map_->begin ()); i != map_->end (); ++i) - { - //std::wcerr << "revoking " << i->second - // << " to " << container_ << std::endl; - - container_->unregister_id (*(i->first)); - } - } - - // Copy registrations to our new container. - // - if (c != nullptr && map_) - { - for (Map_::iterator i (map_->begin ()); i != map_->end (); ++i) - { - //std::wcerr << "copying " << i->second - // << " to " << c << std::endl; - - c->register_id (*(i->first), i->second); - } - } - - container_ = c; - } - - //@@ - //protected: - - public: - void - register_id (IdentityProvider const& id, Type* t) - { - if (!map_) - { - map_ = std::make_unique (); - } - - if (!map_->insert ( - std::pair (&id, t)).second) - { - throw 1; - } - - if (container () != this) container ()->register_id (id, t); - } - - void - unregister_id (IdentityProvider const& id) - { - if (map_) - { - Map_::iterator it (map_->find (&id)); - - if (it != map_->end ()) - { - map_->erase (it); - - if (container () != this) container ()->unregister_id (id); - - return; - } - } - - throw 1; - } - - Type* - lookup_id (IdentityProvider const& id) const - { - if (map_) - { - Map_::const_iterator it (map_->find (&id)); - - if (it != map_->end ()) - { - return it->second; - } - } - - return nullptr; - } - - Type* get_idref (const std::basic_string& name) - { - std::map, XSCRT::Type*>::iterator i = - this->idref_map_.find(name); - if (i != idref_map_.end()) - { - return i->second; - } - else - { - return nullptr; - } - } - - //Get and set methods for the idref_map_ data member - Type* get_idref (const char* name) - { - std::basic_string name_string (ACE_TEXT_CHAR_TO_TCHAR(name)); - std::map, XSCRT::Type*>::iterator i = - this->idref_map_.find(name_string); - if (i != idref_map_.end()) - { - return i->second; - } - else - { - return nullptr; - } - } - - Type* get_idref (const wchar_t *name) - { - std::basic_string name_string (ACE_TEXT_WCHAR_TO_TCHAR(name)); - std::map, XSCRT::Type*>::iterator i = - this->idref_map_.find(name_string); - if (i != idref_map_.end()) - { - return i->second; - } - else - { - return nullptr; - } - } - - void set_idref (std::basic_string name, Type* new_idref) - { - this->idref_map_.insert(std::pair,Type*>(name, new_idref)); - return; - } - - private: - - //Data member to handle unbounded IDREF attributes and elements - std::map, XSCRT::Type*> idref_map_; - - Type* container_; - - struct IdentityComparator - { - bool operator () (IdentityProvider const* x, - IdentityProvider const* y) const - { - return x->before (*y); - } - }; - - typedef - std::map - Map_; - - std::unique_ptr map_; - }; - - // Fundamental types template. - // - // - template - class FundamentalType : public Type - { - public: - // Trait for marshaling a FundamentalType X - using CDR_Type__ = X; - - FundamentalType () - { - } - - template - FundamentalType (XML::Element const& e) - { - std::basic_stringstream s; - s << e.value (); - s >> x_; - } - - template - FundamentalType (XML::Attribute const& a) - { - std::basic_stringstream s; - s << a.value (); - s >> x_; - } - - FundamentalType (X const& x) - : x_ (x) - { - } - - FundamentalType& - operator= (X const& x) - { - x_ = x; - return *this; - } - - public: - operator X const& () const - { - return x_; - } - - operator X& () - { - return x_; - } - - protected: - X x_; - }; - - // Stuff for normal compilers. - // - - // Specialization for `signed char' - // - // - template<> - template - inline - FundamentalType:: - FundamentalType (XML::Element const& e) - { - std::basic_stringstream s; - s << e.value (); - - short t; - s >> t; - - x_ = static_cast (t); - } - - template<> - template - inline - FundamentalType:: - FundamentalType (XML::Attribute const& a) - { - std::basic_stringstream s; - s << a.value (); - - short t; - s >> t; - - x_ = static_cast (t); - } - - // Specialization for `unsigned char' - // - // - template<> - template - inline - FundamentalType:: - FundamentalType (XML::Element const& e) - { - std::basic_stringstream s; - s << e.value (); - - unsigned short t; - s >> t; - - x_ = static_cast (t); - } - - template<> - template - inline - FundamentalType:: - FundamentalType (XML::Attribute const& a) - { - std::basic_stringstream s; - s << a.value (); - - unsigned short t; - s >> t; - - x_ = static_cast (t); - } - - // Specialization for bool. - // - // - - template<> - template<> - inline - FundamentalType:: - FundamentalType (XML::Element const& e) - { - x_ = (e.value () == "true") || (e.value () == "1"); - } - - template<> - template<> - inline - FundamentalType:: - FundamentalType (XML::Element const& e) - { - x_ = (e.value () == L"true") || (e.value () == L"1"); - } - - template<> - template<> - inline - FundamentalType:: - FundamentalType (XML::Attribute const& a) - { - x_ = (a.value () == "true") || (a.value () == "1"); - } - - template<> - template<> - inline - FundamentalType:: - FundamentalType (XML::Attribute const& a) - { - x_ = (a.value () == L"true") || (a.value () == L"1"); - } -} - -#include - -#endif // XSCRT_ELEMENTS_HPP diff --git a/XSCRT/XSCRT/Elements.tpp b/XSCRT/XSCRT/Elements.tpp deleted file mode 100644 index 4b90965..0000000 --- a/XSCRT/XSCRT/Elements.tpp +++ /dev/null @@ -1,6 +0,0 @@ -// file : XSC/Elements.tpp -// author : Boris Kolpackov - -namespace XSC -{ -} diff --git a/XSCRT/XSCRT/ExtendedTypeInfo.hpp b/XSCRT/XSCRT/ExtendedTypeInfo.hpp deleted file mode 100644 index 67cc6d2..0000000 --- a/XSCRT/XSCRT/ExtendedTypeInfo.hpp +++ /dev/null @@ -1,180 +0,0 @@ -// file : XSCRT/ExtendedTypeInfo.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_EXTENDED_TYPE_INFO_HPP -#define XSCRT_EXTENDED_TYPE_INFO_HPP - -#include -#include -#include -#include - -namespace XSCRT -{ - class TypeId - { - public: - template - explicit TypeId (T const& t); - - explicit TypeId (std::type_info const& tid); - - public: - bool - operator == (TypeId const& other) const; - - bool - operator != (TypeId const& other) const; - - bool - operator < (TypeId const& other) const; - - /* - friend std::ostream& - operator << (std::ostream& os, TypeId const& t); - */ - - public: - char const* - name () const - { - return tid_->name (); - } - - private: - std::type_info const* tid_; - }; - - - // - // - // - class ExtendedTypeInfo - { - public: - - // - // - // - struct Access - { - enum Value - { - private_, - protected_, - public_ - }; - }; - - - // - // - // - class BaseInfo - { - public: - BaseInfo (Access::Value access, bool virtual_base, TypeId const& tid); - - public: - ExtendedTypeInfo const& - type_info () const; - - Access::Value - access () const; - - bool - virtual_base () const; - - private: - TypeId tid_; - mutable ExtendedTypeInfo const* ti_; - bool virtual_base_; - Access::Value access_; - }; - - private: - typedef - std::vector - BaseInfoList; - - public: - typedef - BaseInfoList::const_iterator - BaseIterator; - - public: - ExtendedTypeInfo (TypeId const& tid); - - TypeId - type_id () const; - - BaseIterator - begin_base () const; - - BaseIterator - end_base () const; - - void - add_base (Access::Value access, bool virtual_base, TypeId const& tid); - - private: - TypeId tid_; - BaseInfoList base_; - }; - - typedef - std::map - ExtendedTypeInfoMap; - - - ExtendedTypeInfoMap& - extended_type_info_map (); - - - class NotAvailable {}; - - - template - ExtendedTypeInfo const& - extended_type_info (T const& t) - { - return extended_type_info (typeid (t)); - } - - template - ExtendedTypeInfo const& - extended_type_info () - { - return extended_type_info (typeid (T)); - } - - //@@ Had to use function template specialization because VC6 - // cannot handle simply overloaded functions. - // - - template <> - inline - ExtendedTypeInfo const& - extended_type_info (TypeId const& tid) - { - ExtendedTypeInfoMap::const_iterator i ( - extended_type_info_map ().find (tid)); - - if (i == extended_type_info_map ().end ()) - throw NotAvailable (); - - return i->second; - } - - template <> - inline - ExtendedTypeInfo const& - extended_type_info (std::type_info const& tid) - { - return extended_type_info (TypeId (tid)); - } -} - -#include - -#endif // XSCRT_EXTENDED_TYPE_INFO_HPP diff --git a/XSCRT/XSCRT/ExtendedTypeInfo.ipp b/XSCRT/XSCRT/ExtendedTypeInfo.ipp deleted file mode 100644 index 3ef181e..0000000 --- a/XSCRT/XSCRT/ExtendedTypeInfo.ipp +++ /dev/null @@ -1,129 +0,0 @@ -// file : XSCRT/ExtendedTypeInfo.ipp -// author : Boris Kolpackov - -namespace XSCRT -{ - // TypeId - // - // - inline - TypeId:: - TypeId (std::type_info const& tid) - : tid_ (&tid) - { - } - - - inline - bool TypeId:: - operator == (TypeId const& other) const - { - return *tid_ == *other.tid_; - } - - inline - bool TypeId:: - operator != (TypeId const& other) const - { - return *tid_ != *other.tid_; - } - - inline - bool TypeId:: - operator < (TypeId const& other) const - { - return tid_->before (*other.tid_); - } - - - // ExtendedTypeInfo::BaseInfo - // - // - - inline - ExtendedTypeInfo::BaseInfo:: - BaseInfo (Access::Value access, bool virtual_base, TypeId const& tid) - : tid_ (tid), - ti_ (nullptr), - virtual_base_ (virtual_base), - access_ (access) - { - } - - inline - ExtendedTypeInfo const& ExtendedTypeInfo::BaseInfo:: - type_info () const - { - if (ti_ == nullptr) ti_ = std::addressof (extended_type_info (tid_)); - - return *ti_; - } - - - inline - ExtendedTypeInfo::Access::Value ExtendedTypeInfo::BaseInfo:: - access () const - { - return access_; - } - - inline - bool ExtendedTypeInfo::BaseInfo:: - virtual_base () const - { - return virtual_base_; - } - - - // ExtendedTypeInfo - // - // - inline - ExtendedTypeInfo:: - ExtendedTypeInfo (TypeId const& tid) - : tid_ (tid) - { - } - - inline - TypeId ExtendedTypeInfo:: - type_id () const - { - return tid_; - } - - inline - ExtendedTypeInfo::BaseIterator ExtendedTypeInfo:: - begin_base () const - { - return base_.begin (); - } - - - inline - ExtendedTypeInfo::BaseIterator ExtendedTypeInfo:: - end_base () const - { - return base_.end (); - } - - inline - void ExtendedTypeInfo:: - add_base (Access::Value access, bool virtual_base, TypeId const& tid) - { - base_.push_back (BaseInfo (access, virtual_base, tid)); - } - - // ExtendedTypeInfoMap - // - // - - inline - ExtendedTypeInfoMap& - extended_type_info_map () - { - static ExtendedTypeInfoMap extended_type_info_map_; - - return extended_type_info_map_; - } -} diff --git a/XSCRT/XSCRT/Parser.hpp b/XSCRT/XSCRT/Parser.hpp deleted file mode 100644 index fe1fda6..0000000 --- a/XSCRT/XSCRT/Parser.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// file : XSCRT/Parser.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_PARSER_HPP -#define XSCRT_PARSER_HPP - -#include - -#include -#include -#include - -namespace XSCRT -{ - template - class Parser - { - public: - Parser (XML::Element const& e) - : e_ (e.dom_element ()->getChildNodes ()), ei_ (0), - a_ (e.dom_element ()->getAttributes ()), ai_ (0) - { - } - - bool - more_elements () const - { - return e_->getLength () > ei_; - } - - XML::Element - next_element () - { - xercesc::DOMNode * node = e_->item (ei_++); - - return XML::Element ( - dynamic_cast (node)); - } - - bool - more_attributes () const - { - return a_->getLength () > ai_; - } - - XML::Attribute - next_attribute () - { - return XML::Attribute ( - dynamic_cast (a_->item (ai_++))); - } - - private: - xercesc::DOMNodeList const* e_; - unsigned long ei_; - - xercesc::DOMNamedNodeMap const* a_; - unsigned long ai_; - - private: - Parser (Parser const&); - - void - operator= (Parser const&); - }; -} - -#include - -#endif // XSCRT_PARSER_HPP diff --git a/XSCRT/XSCRT/Parser.tpp b/XSCRT/XSCRT/Parser.tpp deleted file mode 100644 index 56e3389..0000000 --- a/XSCRT/XSCRT/Parser.tpp +++ /dev/null @@ -1,6 +0,0 @@ -// file : XSCRT/Parser.tpp -// author : Boris Kolpackov - -namespace XSCRT -{ -} diff --git a/XSCRT/XSCRT/Traversal.hpp b/XSCRT/XSCRT/Traversal.hpp deleted file mode 100644 index 10c2579..0000000 --- a/XSCRT/XSCRT/Traversal.hpp +++ /dev/null @@ -1,273 +0,0 @@ -// file : XSCRT/Traversal.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_TRAVERSAL_HPP -#define XSCRT_TRAVERSAL_HPP - -#include -#include -#include - -// #include -// using std::wcerr; -// using std::endl; - -#include - -namespace XSCRT -{ - namespace Traversal - { - // - // - // - template - class TraverserBase - { - protected: - virtual - ~TraverserBase (); - - //@@ VC6 - public: - virtual void - trampoline (B& n) = 0; - - virtual void - trampoline (B const& n) = 0; - - /*@@ VC6 - template - friend class DispatcherBase; - */ - }; - - - // - // - // - template - class DispatcherBase - { - public: - virtual - ~DispatcherBase (); - - virtual void - dispatch (B& n); - - virtual void - dispatch (B const& n); - - void - map (TypeId id, TraverserBase& t) - { - //wcerr << "map for " << id.name () << " to " << &t - // << " in " << &traversal_map_ << endl; - - //@@ VC6 - Traversers& traversers = traversal_map_[id]; - traversers.push_back (&t); - } - - public: - typedef - std::vector*> - Traversers; - - typedef - std::map - TraversalMap; - - typedef - typename TraversalMap::const_iterator - Iterator; - - Iterator - begin () const - { - return traversal_map_.begin (); - } - - Iterator - end () const - { - return traversal_map_.end (); - } - - private: - struct TypeInfoComparator - { - bool - operator () (ExtendedTypeInfo const& x, - ExtendedTypeInfo const& y) const - { - return x.type_id () < y.type_id (); - } - }; - - typedef - std::map - LevelMap; - - typedef - std::set - TypeInfoSet; - - static unsigned long - compute_levels (ExtendedTypeInfo const& ti, - unsigned long cur, - LevelMap& map); - - static void - flatten_tree (ExtendedTypeInfo const& ti, TypeInfoSet& set); - - private: - TraversalMap traversal_map_; - }; - - - // - // - // - template - class Dispatcher : public virtual DispatcherBase - { - public: - Dispatcher () - : merge_ (true) - { - } - - void - traverser (DispatcherBase& d) - { - for (typename DispatcherBase::Iterator - i (d.begin ()), end (d.end ()); - i != end; ++i) - { - for (typename DispatcherBase::Traversers::const_iterator - t (i->second.begin ()), end (i->second.end ()); - t != end; ++t) - { - dispatcher_.map (i->first, **t); - } - } - } - - public: - virtual void - dispatch (B& n) - { - merge (); - dispatcher_.dispatch (n); - } - - virtual void - dispatch (B const& n) - { - merge (); - dispatcher_.dispatch (n); - } - - using DispatcherBase::begin; - using DispatcherBase::end; - - private: - void - merge () - { - if (merge_) - { - for (typename DispatcherBase::Iterator - i (begin ()), e (end ()); i != e; ++i) - { - for (typename DispatcherBase::Traversers::const_iterator - t (i->second.begin ()), e (i->second.end ()); t != e; ++t) - { - dispatcher_.map (i->first, **t); - } - } - - merge_ = false; - } - } - - protected: - // DispatcherBase& - // traverser () - // { - // return dispatcher_; - // } - - template - void - iterate_and_dispatch (I begin, I end, X& x, void (X::*next)(A&), A& a) - { - for (; begin != end;) - { - dispatch (*begin); - - if (++begin != end) (x.*next) (a); - } - } - - private: - bool merge_; - DispatcherBase dispatcher_; - }; - - - - // - // - // - template - struct Traverser : TraverserBase, virtual Dispatcher - { - typedef - T - Type; - - Traverser () - { - map (typeid (Type), *this); - } - - virtual void - traverse (Type&) - { - abort (); - } - - virtual void - traverse (Type const&) - { - abort (); - } - - protected: - virtual void - trampoline (B& n) - { - //wcerr << "trampoline for " << &n << " to type " - // << typeid (Type).name () << endl; - - traverse (dynamic_cast (n)); - } - - virtual void - trampoline (B const& n) - { - //wcerr << "trampoline for " << &n << " to type " - // << typeid (Type).name () << endl; - - traverse (dynamic_cast (n)); - } - }; - } -} - -#include - -#endif // XSCRT_TRAVERSAL_HPP diff --git a/XSCRT/XSCRT/Traversal.tpp b/XSCRT/XSCRT/Traversal.tpp deleted file mode 100644 index dff306d..0000000 --- a/XSCRT/XSCRT/Traversal.tpp +++ /dev/null @@ -1,194 +0,0 @@ -// file : XSCRT/Traversal.txx -// author : Boris Kolpackov - -namespace XSCRT -{ - namespace Traversal - { - // TraverserBase - // - // - - template - TraverserBase:: - ~TraverserBase () = default; - - // DispatcherBase - // - // - - template - DispatcherBase:: - ~DispatcherBase () = default; - - //@@ merge after dropping VC6 - // - // - template - void DispatcherBase:: - dispatch (B& n) - { - LevelMap levels; - - //@@ VC6 - ExtendedTypeInfo const& ti = extended_type_info (n); - - unsigned long max = compute_levels (ti, 0, levels); - - - //wcerr << "starting dispatch process for " - // << typeid (n).name () << " with " - // << max << " levels" << endl; - - for (unsigned long l = 0; l < max + 1; ++l) - { - TypeInfoSet dispatched; - - for (typename LevelMap::const_iterator - i (levels.begin ()), e (levels.end ()); - i != e; ++i) - { - if (i->second == l) - { - typename TraversalMap::const_iterator v ( - traversal_map_.find (i->first.type_id ())); - - if (v != traversal_map_.end ()) - { - //wcerr << "dispatching traversers for " - // << typeid (n).name () << " as " - // << i->first.type_id ().name () << endl; - - //@@ VC6 - Traversers const& traversers = v->second; - for (typename Traversers::const_iterator - ti (traversers.begin ()), te (traversers.end ()); - ti != te; ++ti) - { - (*ti)->trampoline (n); - } - - flatten_tree (i->first, dispatched); - } - } - } - - // Remove traversed types from the level map. - // - - //@@ VC6 - { - for (typename TypeInfoSet::const_iterator i = dispatched.begin (); - i != dispatched.end (); - ++i) - { - levels.erase (*i); - } - } - } - } - - template - void DispatcherBase:: - dispatch (B const& n) - { - LevelMap levels; - - //@@ VC6 - ExtendedTypeInfo const& ti = extended_type_info (n); - - unsigned long max = compute_levels (ti, 0, levels); - - - //wcerr << "starting dispatch process for " - // << typeid (n).name () << " with " - // << max << " levels" << endl; - - //wcerr << "using " << &traversal_map_ << " traversal map" << endl; - - for (unsigned long l = 0; l < max + 1; ++l) - { - TypeInfoSet dispatched; - - for (typename LevelMap::const_iterator - i (levels.begin ()), e (levels.end ()); - i != e; ++i) - { - if (i->second == l) - { - typename TraversalMap::const_iterator v ( - traversal_map_.find (i->first.type_id ())); - - if (v != traversal_map_.end ()) - { - //wcerr << "dispatching traversers for " - // << typeid (n).name () << " as " - // << i->first.type_id ().name () << endl; - - //@@ VC6 - Traversers const& traversers = v->second; - for (typename Traversers::const_iterator - ti (traversers.begin ()), te (traversers.end ()); - ti != te; ++ti) - { - (*ti)->trampoline (n); - } - - flatten_tree (i->first, dispatched); - } - } - } - - // Remove traversed types from the level map. - // - - //@@ VC6 - { - for (typename TypeInfoSet::const_iterator i = dispatched.begin (); - i != dispatched.end (); - ++i) - { - levels.erase (*i); - } - } - } - } - - template - unsigned long DispatcherBase:: - compute_levels (ExtendedTypeInfo const& ti, - unsigned long cur, - LevelMap& map) - { - unsigned long ret = cur; - - if (map.find (ti) == map.end () || map[ti] < cur) map[ti] = cur; - - for (ExtendedTypeInfo::BaseIterator i = ti.begin_base (); - i != ti.end_base (); - i++) - { - unsigned long t = compute_levels (i->type_info (), cur + 1, map); - - if (t > ret) - ret = t; - } - - return ret; - } - - template - void DispatcherBase:: - flatten_tree (ExtendedTypeInfo const& ti, TypeInfoSet& set) - { - set.insert (ti); - - for (ExtendedTypeInfo::BaseIterator i = ti.begin_base (); - i != ti.end_base (); - i++) - { - flatten_tree (i->type_info (), set); - } - } - } -} diff --git a/XSCRT/XSCRT/Writer.hpp b/XSCRT/XSCRT/Writer.hpp deleted file mode 100644 index 9b852ed..0000000 --- a/XSCRT/XSCRT/Writer.hpp +++ /dev/null @@ -1,79 +0,0 @@ -// file : XSCRT/Writer.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_WRITER_HPP -#define XSCRT_WRITER_HPP - -#include -#include - -#include - -namespace XSCRT -{ - template - class Writer - { - public: - Writer (XML::Element& e) - : attr__ (nullptr) - { - push_ (e); - } - - protected: - // This c-tor should never be called. - // - Writer () - { - abort (); - } - - public: - void - push_ (XML::Element const& e) - { - stack_.push (e); - } - - void - pop_ () - { - stack_.pop (); - } - - XML::Element& - top_ () - { - return stack_.top (); - } - - public: - XML::Attribute* - attr_ () - { - return attr__; - } - - void - attr_ (XML::Attribute* a) - { - attr__ = a; - } - - private: - std::stack > stack_; - - XML::Attribute* attr__; - - private: - Writer (Writer const&); - - void - operator= (Writer const&); - }; -} - -#include - -#endif // XSCRT_WRITER_HPP diff --git a/XSCRT/XSCRT/Writer.tpp b/XSCRT/XSCRT/Writer.tpp deleted file mode 100644 index 120a830..0000000 --- a/XSCRT/XSCRT/Writer.tpp +++ /dev/null @@ -1,6 +0,0 @@ -// file : XSCRT/Writer.tpp -// author : Boris Kolpackov - -namespace XSCRT -{ -} diff --git a/XSCRT/XSCRT/XML.hpp b/XSCRT/XSCRT/XML.hpp deleted file mode 100644 index effcfa4..0000000 --- a/XSCRT/XSCRT/XML.hpp +++ /dev/null @@ -1,468 +0,0 @@ -// file : XSCRT/XML.hpp -// author : Boris Kolpackov - -#ifndef XSCRT_XML_HPP -#define XSCRT_XML_HPP - -#include -#include -#include "xercesc/dom/DOM.hpp" -#include "xercesc/util/XMLString.hpp" - -//@@ VC6 -#if defined (_MSC_VER) && (_MSC_VER < 1300) -namespace std -{ - using size_t = std::size_t; -} -#endif - -namespace XSCRT -{ - namespace XML - { - //@@ VC6 - // - template - std::basic_string - transcode (XMLCh const* s, C*); - - template - XMLCh* - transcode (std::basic_string const& s); - - // - // - // - class string - { - public : - template - string (std::basic_string const& s) - : s_ (XSCRT::XML::transcode (s)) - { - } - - template - string (C const* s) - : s_ (XSCRT::XML::transcode (s)) - { - } - - ~string () - { - delete[] s_; - } - - XMLCh const* - c_str () const - { - return s_; - } - - private : - XMLCh* s_; - }; - - - template <> - inline - std::basic_string - transcode (XMLCh const* s, char*) - { - if (s == 0) return std::basic_string (); - - char* buf = xercesc::XMLString::transcode (s); - - std::basic_string r (buf); - - xercesc::XMLString::release (&buf); - - return r; - } - - template <> - inline - std::basic_string - transcode (XMLCh const* s, wchar_t*) - { - if (s == 0) return std::basic_string (); - - // std::wcerr << s << std::endl; - - std::basic_string r (xercesc::XMLString::stringLen (s), L'0'); - - for (std::size_t i (0); *s != XMLCh (0); ++s, ++i) - { - r[i] = *s; - } - - return r; - } - - template <> - inline - XMLCh* - transcode (std::basic_string const& s) - { - return xercesc::XMLString::transcode (s.c_str ()); - } - - template <> - inline - XMLCh* - transcode (std::basic_string const& s) - { - //@@ VC6 - std::size_t l = s.length (); - - //@@ VC6 - XMLCh* r = new XMLCh[l + 1]; - XMLCh* ir = r; - - for (std::size_t i (0); i < l; ++ir, ++i) - { - *ir = static_cast(s[i]); - //std::wcerr << s[i] << "->" << *ir << std::endl; - //std::wcerr << s[i]; - } - //std::wcerr << std::endl; - - *ir = XMLCh (0); - - //std::wcerr << r << std::endl; - - return r; - } - - - template - class Element; - - template - std::basic_string - ns_prefix (std::basic_string const& ns, Element const& e); - - template - class Element - { - using string_ = std::basic_string; - - public: - Element (xercesc::DOMElement const* e) - : e_ (nullptr), - ce_ (e), - name_ (transcode (e->getLocalName (), 0)), - namespace__ (transcode (e->getNamespaceURI (), 0)) - { - } - - Element (xercesc::DOMElement* e) - : e_ (e), - ce_ (e), - name_ (transcode (e->getLocalName (), 0)), - namespace__ (transcode (e->getNamespaceURI (), 0)) - { - } - - Element (string_ const& name, Element& parent) - : e_ (nullptr), - ce_ (nullptr), - name_ (name) - { - xercesc::DOMDocument* doc ( - parent.dom_element ()->getOwnerDocument ()); - - e_ = doc->createElement (string (name).c_str ()); - - parent.dom_element ()->appendChild (e_); - - ce_ = e_; - } - - Element (string_ const& name, string_ const& ns, Element& parent) - : e_ (nullptr), - ce_ (nullptr), - name_ (name), - namespace__ (ns) - { - string_ prefix (ns_prefix (ns, parent)); - - xercesc::DOMDocument* doc ( - parent.dom_element ()->getOwnerDocument ()); - - e_ = doc->createElementNS ( - string (ns).c_str (), - string (prefix.empty () - ? name - : prefix + string_ (1, ':') + name).c_str ()); - - parent.dom_element ()->appendChild (e_); - - ce_ = e_; - } - - public: - string_ - name () const - { - return name_; - } - - string_ - namespace_ () const - { - return namespace__; - } - - public: - Element - parent () const - { - return dynamic_cast(ce_->getParentNode ()); - } - - public: - string_ - value () const - { - return XML::transcode (dom_element ()->getTextContent (), 0); - } - - void - value (string_ const& v) - { - xercesc::DOMText* text ( - dom_element ()->getOwnerDocument ()->createTextNode( - string (v).c_str ())); - - dom_element ()->appendChild (text); - } - - public: - string_ - operator[] (string_ const& s) const - { - //@@ VC6 - XMLCh const* value = ce_->getAttribute (string (s).c_str ()); - - return transcode (value, 0); - } - - public: - xercesc::DOMElement const* - dom_element () const - { - return ce_; - } - - xercesc::DOMElement* - dom_element () - { - return e_; - } - - private: - xercesc::DOMElement* e_; - xercesc::DOMElement const* ce_; - - string_ name_; - string_ namespace__; - }; - - - template - class Attribute - { - using string_ = std::basic_string; - - public: - Attribute (xercesc::DOMAttr const* a) - : a_ (nullptr), - ca_ (a), - name_ (transcode (a->getLocalName (), 0)), - value_ (transcode (a->getValue (), 0)) - { - } - - Attribute (xercesc::DOMAttr* a) - : a_ (a), - ca_ (a), - name_ (transcode (a->getLocalName (), 0)), - value_ (transcode (a->getValue (), 0)) - { - } - - Attribute (string_ const& name, - string_ const& v, - Element& parent) - : a_ (nullptr), - ca_ (nullptr), - name_ (name), - value_ () - { - xercesc::DOMDocument* doc ( - parent.dom_element ()->getOwnerDocument ()); - - a_ = doc->createAttribute (string (name).c_str ()); - - value (v); - - parent.dom_element ()->setAttributeNode (a_); - - ca_ = a_; - } - - Attribute (string_ const& name, - string_ const& ns, - string_ const& v, - Element& parent) - : a_ (nullptr), - ca_ (nullptr), - name_ (name), - value_ () - { - string_ prefix (ns_prefix (ns, parent)); - - xercesc::DOMDocument* doc ( - parent.dom_element ()->getOwnerDocument ()); - - a_ = doc->createAttributeNS ( - string (ns).c_str (), - string (prefix.empty () - ? name - : prefix + string_ (1, ':') + name).c_str ()); - - value (v); - - parent.dom_element ()->setAttributeNodeNS (a_); - - ca_ = a_; - } - - string_ - name () const - { - return name_; - } - - string_ - value () const - { - return value_; - } - - void - value (string_ const& v) - { - value_ = v; - a_->setValue (string (v).c_str ()); - } - - public: - xercesc::DOMAttr const* - dom_attribute () const - { - return ca_; - } - - xercesc::DOMAttr* - dom_attribute () - { - return a_; - } - - private: - - private: - xercesc::DOMAttr* a_; - xercesc::DOMAttr const* ca_; - - string_ name_; - string_ value_; - }; - - template - std::basic_string - prefix (std::basic_string const& n) - { - std::size_t i (0); - while (i < n.length () && n[i] != ':') ++i; - - //std::wcerr << "prefix " << n << " " - // << std::wstring (n, i == n.length () ? i : 0, i) << std::endl; - - return std::basic_string (n, i == n.length () ? i : 0, i); - } - - template - std::basic_string - uq_name (std::basic_string const& n) - { - std::size_t i (0); - while (i < n.length () && n[i] != ':') ++i; - - return std::basic_string (n.c_str () + (i == n.length () ? 0 : i + 1)); - } - - template - std::basic_string - ns_name (Element const& e, std::basic_string const& n) - { - std::basic_string wp (prefix (n)); - - //@@ VC6 - XMLCh const* xns = e.dom_element ()->lookupNamespaceURI ( - wp.empty () ? 0 : string (wp).c_str ()); - - - std::basic_string ns ( - xns ? transcode (xns, 0) : std::basic_string ()); - - return ns; - - } - - template - std::basic_string - fq_name (Element const& e, std::basic_string const& n) - { - std::basic_string ns (ns_name (e, n)); - std::basic_string un (uq_name (n)); - - return ns.empty () ? un : (ns + C ('#') + un); - } - - class no_prefix {}; - - template - std::basic_string - ns_prefix (std::basic_string const& ns, Element const& e) - { - string xns (ns); - - XMLCh const* p ( - e.dom_element ()->lookupPrefix (xns.c_str ())); - - if (p == 0) - { - bool r (e.dom_element ()->isDefaultNamespace (xns.c_str ())); - - if (r) - { - return std::basic_string (); - } - else - { - throw no_prefix (); - } - } - - return transcode (p, 0); - } - } -} - -#include - -#endif // XSCRT_XML_HPP diff --git a/XSCRT/XSCRT/XML.tpp b/XSCRT/XSCRT/XML.tpp deleted file mode 100644 index 58019d4..0000000 --- a/XSCRT/XSCRT/XML.tpp +++ /dev/null @@ -1,6 +0,0 @@ -// file : XSCRT/XML.tpp -// author : Boris Kolpackov - -namespace XSCRT -{ -} diff --git a/XSCRT/XSCRT/XSCRT.mpc b/XSCRT/XSCRT/XSCRT.mpc deleted file mode 100644 index ae9f33f..0000000 --- a/XSCRT/XSCRT/XSCRT.mpc +++ /dev/null @@ -1,34 +0,0 @@ -project (XSCRT) : xerces, xsc_utils, xsc_common { - sharedname = XSCRT - after += libXSC - - includes += $(XSC_ROOT) $(XSC_ROOT)/XSCRT - - dynamicflags += XSCRT_HAS_DLL XSCRT_BUILD_DLL - staticflags += XSCRT_AS_STATIC_LIBS - - Source_Files { - - } - - Template_Files { - ./*.tpp - ../XMLSchema/*.tpp - - utils/Buffer_Reader_T.cpp - utils/Buffer_Writer_T.cpp - utils/File_T.cpp - utils/File_Reader_T.cpp - utils/File_Writer_T.cpp - utils/Reader_T.cpp - utils/Writer_T.cpp - utils/Reader_Writer_Base_T.cpp - } - - Inline_Files { - } - - Header_Files { - XSCRT_export.h - } -} diff --git a/XSCRT/XSCRT/XSCRT_export.h b/XSCRT/XSCRT/XSCRT_export.h deleted file mode 100644 index 194fc72..0000000 --- a/XSCRT/XSCRT/XSCRT_export.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef XSCRT_EXPORT_H -#define XSCRT_EXPORT_H - -#if !defined(XSCRT_HAS_DLL) -# if defined(XSCRT_AS_STATIC_LIBS) -# define XSCRT_HAS_DLL 0 -# else -# define XSCRT_HAS_DLL 1 -# endif -#endif - -#if (XSCRT_HAS_DLL == 1) -# if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550) -# if defined(XSCRT_BUILD_DLL) -# define XSCRT_Export __symbolic -# else -# define XSCRT_Export __global -# endif -# elif defined(WIN32) || defined(UNDER_CE) || defined(__CYGWIN__) -# if defined(XSCRT_BUILD_DLL) -# define XSCRT_Export __declspec(dllexport) -# else -# define XSCRT_Export __declspec(dllimport) -# endif -# elif (defined(__GNUC__) && (__GNUC__ >= 4)) -# if defined(XSCRT_BUILD_DLL) -# define XSCRT_Export __attribute__((visibility("default"))) -# else -# define XSCRT_Export -# endif -# else -# define XSCRT_Export -# endif -#else -# define XSCRT_Export -#endif - -#endif diff --git a/XSCRT/XSCRT/utils/Buffer_Reader_T.cpp b/XSCRT/XSCRT/utils/Buffer_Reader_T.cpp deleted file mode 100644 index 5db251f..0000000 --- a/XSCRT/XSCRT/utils/Buffer_Reader_T.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "xercesc/framework/MemBufInputSource.hpp" -#include "xercesc/framework/Wrapper4InputSource.hpp" -#include "XSC/utils/XercesString.h" -#include - -namespace XSCRT -{ -namespace utils -{ -// -// Buffer_Reader_T -// -template -Buffer_Reader_T :: -Buffer_Reader_T (typename reader_function ::result_type reader, - const CHAR_TYPE * fake_id) -: Reader_T (reader), - fake_id_ (fake_id) -{ - -} - -// -// ~Buffer_Reader_T -// -template -Buffer_Reader_T ::~Buffer_Reader_T () = default; - -// -// open -// -template -bool Buffer_Reader_T ::read (const char * buffer, size_t size) -{ - using namespace xercesc; - - // Open the file for reading. - MemBufInputSource input (reinterpret_cast (buffer), - size, - this->fake_id_); - - this->parser_->parse (input); - - // Get the document. - this->document_ = this->parser_->adoptDocument (); - return this->document_ != nullptr; -} - -} -} diff --git a/XSCRT/XSCRT/utils/Buffer_Reader_T.h b/XSCRT/XSCRT/utils/Buffer_Reader_T.h deleted file mode 100644 index c688d9b..0000000 --- a/XSCRT/XSCRT/utils/Buffer_Reader_T.h +++ /dev/null @@ -1,68 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file Buffer_Reader_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_BUFFER_READER_T_H_ -#define _XSCRT_BUFFER_READER_T_H_ - -#include "Reader_T.h" -#include "XSC/utils/XercesString.h" - -namespace XSCRT -{ -namespace utils -{ -/** - * @class Buffer_Reader_T - * - * Utility class for reading a XML document from a file. - */ -template -class Buffer_Reader_T : public Reader_T -{ -public: - /// Type definition of the character type. - using char_type = typename Reader_T::char_type; - - /// Type definition of the entity type. - using entity_type = typename Reader_T::entity_type; - - /** - * Initializing constructor. - * - * @param[in] reader Target reader function - */ - Buffer_Reader_T (typename reader_function ::result_type reader, - const CHAR_TYPE * fake_id); - - /// Destructor. - ~Buffer_Reader_T (); - - /** - * Open the file for reading. This will open the \a filename if - * it exists, and populate contained Xerces-C document. - * - * @param[in] buffer Buffer with XML document. - * @param[in] size Size of XML document. - * @retval true Successfully read XML document. - * @retval false Failed to read XML document. - */ - bool read (const char * buffer, size_t size); - -private: - /// Fake system id for the reader. - XSC::XStr fake_id_; -}; - -} -} - -#include "Buffer_Reader_T.cpp" - -#endif // !defined _XSCRT_BUFFER_READER_T_H_ diff --git a/XSCRT/XSCRT/utils/Buffer_Writer_T.cpp b/XSCRT/XSCRT/utils/Buffer_Writer_T.cpp deleted file mode 100644 index 28f4e23..0000000 --- a/XSCRT/XSCRT/utils/Buffer_Writer_T.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include - -namespace XSCRT -{ -namespace utils -{ -// -// Buffer_Writer_T -// -template -Buffer_Writer_T :: -Buffer_Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer) -: Writer_T (ns, root, writer), - target_ (std::make_unique ()) -{ - this->output_.reset ( - static_cast (this->impl_)->createLSOutput ()); - this->output_->setByteStream (this->target_.get ()); -} - -// -// Buffer_Writer_T -// -template -Buffer_Writer_T ::~Buffer_Writer_T () = default; - -// -// open -// -template -bool Buffer_Writer_T ::write (char * buffer, size_t & size) -{ - // Get the size of the XML document. - size_t copy_n = this->get_buffer_size (); - - if (copy_n > size) - return false; - - // Copy the buffer, and set the size. - ::memcpy (buffer, this->target_->getRawBuffer (), copy_n); - size = copy_n; - return true; -} - -// -// operator <<= -// -template -void Buffer_Writer_T ::operator <<= (const T & entity) -{ - // First, let the base class construct the DOM object. - Writer_T ::operator <<= (entity); - - // Now, save the XML document into an internal buffer. - if (this->dom_writer_) - this->dom_writer_->write (this->document_, this->output_.get ()); -} - -// -// get_buffer_size -// -template -size_t Buffer_Writer_T ::get_buffer_size () const -{ - return this->target_->getLen (); -} - -} -} diff --git a/XSCRT/XSCRT/utils/Buffer_Writer_T.h b/XSCRT/XSCRT/utils/Buffer_Writer_T.h deleted file mode 100644 index 0aa5614..0000000 --- a/XSCRT/XSCRT/utils/Buffer_Writer_T.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file Buffer_Writer_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_BUFFER_WRITER_H_ -#define _XSCRT_BUFFER_WRITER_H_ - -#include - -#include "Writer_T.h" -#include "xercesc/framework/MemBufFormatTarget.hpp" - -namespace XSCRT -{ -namespace utils -{ - -/** - * @class Buffer_Writer_T - */ -template -class Buffer_Writer_T : public Writer_T -{ -public: - /** - * Initializing constructor. - * - * @param[in] ns Target namespace - * @param[in] root Name of root element - * @param[in] writer Writer function - */ - Buffer_Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer); - - /// Destructor. - ~Buffer_Writer_T (); - - bool write (char * buffer, size_t & size); - - /** - * Insertion operator. - * - * @param[in] entity Target entity. - * @return Reference to the file reader. - */ - void operator <<= (const T & entity); - - /** - * Get the size of the buffer. - * - * @return Size of the buffer in bytes. - */ - size_t get_buffer_size () const; - -private: - std::unique_ptr target_; - - std::unique_ptr output_; -}; - -} -} - -#include "Buffer_Writer_T.cpp" - -#endif // !defined _XSCRT_BUFFER_WRITER_H_ diff --git a/XSCRT/XSCRT/utils/File_Reader_T.cpp b/XSCRT/XSCRT/utils/File_Reader_T.cpp deleted file mode 100644 index deb9f1f..0000000 --- a/XSCRT/XSCRT/utils/File_Reader_T.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "XSC/utils/XercesString.h" - -namespace XSCRT -{ -namespace utils -{ -// -// File_Reader_T -// -template -File_Reader_T :: -File_Reader_T (typename reader_function ::result_type reader) -: Reader_T (reader) -{ - -} - -// -// ~File_Reader_T -// -template -File_Reader_T ::~File_Reader_T () = default; - -// -// open -// -template -bool File_Reader_T ::read (const CHAR_TYPE * filename) -{ - // Parse the specified file. - this->parser_->parse (filename); - this->document_ = this->parser_->adoptDocument (); - - return this->document_ != nullptr; -} - -} -} diff --git a/XSCRT/XSCRT/utils/File_Reader_T.h b/XSCRT/XSCRT/utils/File_Reader_T.h deleted file mode 100644 index bab3eec..0000000 --- a/XSCRT/XSCRT/utils/File_Reader_T.h +++ /dev/null @@ -1,61 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file File_Reader_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_FILE_READER_T_H_ -#define _XSCRT_FILE_READER_T_H_ - -#include "Reader_T.h" - -namespace XSCRT -{ -namespace utils -{ -/** - * @class File_Reader_T - * - * Utility class for reading a XML document from a file. - */ -template -class File_Reader_T : public Reader_T -{ -public: - /// Type definition of the character type. - using char_type = typename Reader_T::char_type; - - /// Type definition of the entity type. - using entity_type = typename Reader_T::entity_type; - - /** - * Initializing constructor. - * - * @param[in] reader Target reader function - */ - File_Reader_T (typename reader_function ::result_type reader); - - /// Destructor. - ~File_Reader_T (); - - /** - * Open the file for reading. This will open the \a filename if - * it exists, and populate contained Xerces-C document. - * - * @param[in] filename Name of the XML file. - * @retval true Successfully opened file. - * @retval false Failed to open file. - */ - bool read (const CHAR_TYPE * filename); -}; - -} -} - -#include "File_Reader_T.cpp" - -#endif // !defined _XSCRT_FILE_READER_T_H_ diff --git a/XSCRT/XSCRT/utils/File_Writer_T.cpp b/XSCRT/XSCRT/utils/File_Writer_T.cpp deleted file mode 100644 index a2f6a63..0000000 --- a/XSCRT/XSCRT/utils/File_Writer_T.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -#include "xercesc/framework/LocalFileFormatTarget.hpp" - -namespace XSCRT -{ -namespace utils -{ -// -// File_Writer_T -// -template -File_Writer_T :: -File_Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer) -: Writer_T (ns, root, writer) -{ - -} - -// -// File_Writer_T -// -template -File_Writer_T ::~File_Writer_T () = default; - -// -// open -// -template -bool File_Writer_T ::write (const CHAR_TYPE * filename) -{ - auto target_file = std::make_unique ( - XSC::XStr (filename)); - - // Write the element to the target. - if (this->dom_writer_) - return this->dom_writer_->writeNode (target_file.get (), *this->document_); - - return false; -} - -} -} diff --git a/XSCRT/XSCRT/utils/File_Writer_T.h b/XSCRT/XSCRT/utils/File_Writer_T.h deleted file mode 100644 index 50e4369..0000000 --- a/XSCRT/XSCRT/utils/File_Writer_T.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file File_Writer_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_FILE_WRITER_H_ -#define _XSCRT_FILE_WRITER_H_ - -#include "Writer_T.h" - -namespace XSCRT -{ -namespace utils -{ - -/** - * @class File_Writer_T - */ -template -class File_Writer_T : public Writer_T -{ -public: - /** - * Initializing constructor. - * - * @param[in] ns Target namespace - * @param[in] root Name of root element - * @param[in] writer Writer function - */ - File_Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer); - - /// Destructor. - ~File_Writer_T (); - - bool write (const CHAR_TYPE * filename); -}; - -} -} - -#include "File_Writer_T.cpp" - -#endif // !defined _XSCRT_FILE_WRITER_H_ diff --git a/XSCRT/XSCRT/utils/Reader_T.cpp b/XSCRT/XSCRT/utils/Reader_T.cpp deleted file mode 100644 index 104d91d..0000000 --- a/XSCRT/XSCRT/utils/Reader_T.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "xercesc/util/XMLUniDefs.hpp" - -namespace XSCRT -{ -namespace utils -{ -// -// File_Reader_T -// -template -Reader_T :: -Reader_T (typename reader_function ::result_type reader) -: parser_ (std::make_unique ()), - reader_ (reader) -{ -} - -// -// ~File_Reader_T -// -template -Reader_T ::~Reader_T () = default; - -// -// operator >>= -// -template -void Reader_T ::operator >>= (T & entity) const -{ - if (this->reader_ && this->document_) - entity = (*this->reader_) (this->document_); -} - -// -// parser -// -template -xercesc::XercesDOMParser * Reader_T ::operator -> () -{ - return this->parser_.get (); -} - -} -} diff --git a/XSCRT/XSCRT/utils/Reader_T.h b/XSCRT/XSCRT/utils/Reader_T.h deleted file mode 100644 index 14a23e4..0000000 --- a/XSCRT/XSCRT/utils/Reader_T.h +++ /dev/null @@ -1,87 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file Reader_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_READER_T_H_ -#define _XSCRT_READER_T_H_ - -#include "Reader_Writer_Base_T.h" -#include "xercesc/util/XercesDefs.hpp" -#include "xercesc/parsers/XercesDOMParser.hpp" -#include - -namespace XSCRT -{ -namespace utils -{ -/** - * @struct reader_function - * - * Trait for determining an XSC element's reader function signature. - */ -template -struct reader_function -{ - /// Type definition of the reading function signature. - using result_type = T (*) (const xercesc::DOMDocument *); -}; - -/** - * @class Reader_T - * - * Base class for reading data from an XML document. - */ -template -class Reader_T : public Reader_Writer_Base_T -{ -public: - /// Type definition of the entity type. - using entity_type = typename Reader_Writer_Base_T::entity_type; - - /// Type definition of the character type. - using char_type = typename Reader_Writer_Base_T::char_type; - - /// Destructor. - virtual ~Reader_T (); - - /** - * Extraction operator. - * - * @param[in] entity Target entity. - */ - void operator >>= (T & entity) const; - - /** - * Get the underlying parser. This will allow the client to - * modify its properties. - * - * @return Pointer to the parser. - */ - xercesc::XercesDOMParser * operator -> (); - -protected: - /** - * Default constructor. - * - * @param[in] reader Reader function. - */ - Reader_T (typename reader_function ::result_type reader); - - /// DOM parser for the reader. - std::unique_ptr parser_; - - /// The entity read from the document. - typename reader_function ::result_type reader_; -}; -} -} - -#include "Reader_T.cpp" - -#endif // !defined _XSCRT_READER_T_H_ diff --git a/XSCRT/XSCRT/utils/Reader_Writer_Base_T.cpp b/XSCRT/XSCRT/utils/Reader_Writer_Base_T.cpp deleted file mode 100644 index 69de7fb..0000000 --- a/XSCRT/XSCRT/utils/Reader_Writer_Base_T.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "xercesc/util/XMLUniDefs.hpp" - -namespace XSCRT -{ -namespace utils -{ -// -// Reader_Writer_Base_T -// -template -Reader_Writer_Base_T ::Reader_Writer_Base_T () -: impl_ (nullptr), - document_ (nullptr) -{ - xercesc::XMLPlatformUtils::Initialize (); - - // Get default implementation, which is Load-Store (LS) interface. - static const XMLCh gLS[] = { xercesc::chLatin_L, - xercesc::chLatin_S, - xercesc::chNull }; - - this->impl_ = - xercesc::DOMImplementationRegistry::getDOMImplementation (gLS); -} - -// -// ~Reader_Writer_Base_T -// -template -Reader_Writer_Base_T ::~Reader_Writer_Base_T () -{ - if (this->document_ != nullptr) - this->document_->release (); -} - -template -xercesc::DOMDocument * const -Reader_Writer_Base_T ::document () -{ - return this->document_; -} - -} -} diff --git a/XSCRT/XSCRT/utils/Reader_Writer_Base_T.h b/XSCRT/XSCRT/utils/Reader_Writer_Base_T.h deleted file mode 100644 index 0916d70..0000000 --- a/XSCRT/XSCRT/utils/Reader_Writer_Base_T.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file Reader_Writer_Base_T.h - * - * - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _READER_WRITER_BASE_T_H_ -#define _READER_WRITER_BASE_T_H_ - -#include "xercesc/dom/DOM.hpp" - -namespace XSCRT -{ -namespace utils -{ -/** - * @class Reader_Writer_Base_T - */ -template -class Reader_Writer_Base_T -{ -public: - /// Type definition of the entity type. - using entity_type = T; - - /// Type definition of the char type. - using char_type = CHAR_TYPE; - - /// Destructor. - ~Reader_Writer_Base_T (); - - xercesc::DOMDocument * const document (); - -protected: - /// Default constructor. - Reader_Writer_Base_T (); - - /// Implementation shared between all files. - xercesc::DOMImplementation * impl_; - - /// The underlying Xerces-C document. - xercesc::DOMDocument * document_; -}; - -} -} - -#include "Reader_Writer_Base_T.cpp" - -#endif // !defined _READER_WRITER_BASE_T_H_ diff --git a/XSCRT/XSCRT/utils/Writer_T.cpp b/XSCRT/XSCRT/utils/Writer_T.cpp deleted file mode 100644 index 13229bc..0000000 --- a/XSCRT/XSCRT/utils/Writer_T.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "XSC/utils/XercesString.h" - -namespace XSCRT -{ -namespace utils -{ - -// -// Writer_T -// -template -Writer_T :: -Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer) -: writer_ (writer), - dom_writer_ (nullptr) -{ - // Create an empty XML document. - this->document_ = - this->impl_->createDocument (XSC::XStr (ns), XSC::XStr (root), nullptr); - - // Create a DOMWriter for this writer. - this->dom_writer_ = - ((xercesc::DOMImplementationLS *)this->impl_)->createLSSerializer (); -} - -// -// ~Writer_T -// -template -Writer_T ::~Writer_T () -{ - if (this->dom_writer_ != nullptr) - this->dom_writer_->release (); -} - -// -// operator <<= -// -template -void Writer_T ::operator <<= (const T & entity) -{ - if (this->writer_ != nullptr && this->document_ != nullptr) - (*this->writer_) (entity, this->document_); -} - -// -// writer -// -template -xercesc::DOMLSSerializer * const Writer_T ::writer () -{ - return this->dom_writer_; -} - -} -} diff --git a/XSCRT/XSCRT/utils/Writer_T.h b/XSCRT/XSCRT/utils/Writer_T.h deleted file mode 100644 index 2734c63..0000000 --- a/XSCRT/XSCRT/utils/Writer_T.h +++ /dev/null @@ -1,70 +0,0 @@ -//============================================================================= -/** - * @file Writer_T.h - * - * @author James H. Hill - */ -//============================================================================= - -#ifndef _XSCRT_WRITER_T_H_ -#define _XSCRT_WRITER_T_H_ - -#include -#include "xercesc/framework/XMLFormatter.hpp" -#include "Reader_Writer_Base_T.h" - -namespace XSCRT -{ -namespace utils -{ -/** - * @struct writer_function - * - * Trait for determining an XSC element's writer function signature. - */ -template -struct writer_function -{ - /// Type definition of the writing function signature. - using result_type = void (*) (T const &, xercesc::DOMDocument *); -}; - -/** - * @class Writer_T - */ -template -class Writer_T : public Reader_Writer_Base_T -{ -public: - /// Destructor. - ~Writer_T (); - - /** - * Insertion operator. - * - * @param[in] entity Target entity. - * @return Reference to the file reader. - */ - void operator <<= (const T & entity); - - xercesc::DOMLSSerializer * const writer (); - -protected: - /** - * - */ - Writer_T (const CHAR_TYPE * ns, - const CHAR_TYPE * root, - typename writer_function ::result_type writer); - - typename writer_function ::result_type writer_; - - xercesc::DOMLSSerializer * dom_writer_; -}; - -} -} - -#include "Writer_T.cpp" - -#endif // !defined _XSCRT_WRITER_T_H_