From 19adbffffb2e4221acc4223577fb3a0366373a2d Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Mon, 19 Aug 2019 22:37:22 +0100 Subject: [PATCH] NOTICK - Break up the Property Reader Class into multiple files As having them all live in a single PropertyReader header / source file was getting far too big. Additionally, sue some of our aliased types to shorted lines (sVec, sList, uPtr etc) --- experimental/cpp-serializer/include/types.h | 7 + .../cpp-serializer/src/amqp/CMakeLists.txt | 30 +- .../src/amqp/CompositeFactory.cxx | 3 +- .../src/amqp/CompositeFactory.h | 43 +-- .../descriptors/AMQPDescriptorRegistory.cxx | 12 +- .../src/amqp/descriptors/AMQPDescriptors.cxx | 84 ++--- .../src/amqp/reader/CompositeReader.cxx | 18 +- .../src/amqp/reader/PropertyReader.cxx | 297 +----------------- .../src/amqp/reader/PropertyReader.h | 157 +-------- .../cpp-serializer/src/amqp/reader/Reader.cxx | 20 +- .../cpp-serializer/src/amqp/reader/Reader.h | 33 +- .../src/amqp/reader/RestrictedReader.cxx | 75 +---- .../src/amqp/reader/RestrictedReader.h | 36 --- .../property-readers/BoolPropertyReader.cxx | 87 +++++ .../property-readers/BoolPropertyReader.h | 38 +++ .../property-readers/DoublePropertyReader.cxx | 85 +++++ .../property-readers/DoublePropertyReader.h | 37 +++ .../property-readers/IntPropertyReader.cxx | 93 ++++++ .../property-readers/IntPropertyReader.h | 39 +++ .../property-readers/LongPropertyReader.cxx | 87 +++++ .../property-readers/LongPropertyReader.h | 38 +++ .../property-readers/StringPropertyReader.cxx | 89 ++++++ .../property-readers/StringPropertyReader.h | 37 +++ .../reader/restricted-readers/ListReader.cxx | 75 +++++ .../reader/restricted-readers/ListReader.h | 44 +++ .../src/amqp/schema/Composite.cxx | 8 +- .../src/amqp/schema/Descriptor.cxx | 10 +- .../src/amqp/schema/Envelope.cxx | 2 +- 28 files changed, 898 insertions(+), 686 deletions(-) create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.h diff --git a/experimental/cpp-serializer/include/types.h b/experimental/cpp-serializer/include/types.h index 864f3c7864..a0a320269a 100644 --- a/experimental/cpp-serializer/include/types.h +++ b/experimental/cpp-serializer/include/types.h @@ -3,6 +3,8 @@ /******************************************************************************/ #include +#include +#include #include /******************************************************************************/ @@ -13,6 +15,11 @@ using uPtr = std::unique_ptr; template using sPtr = std::shared_ptr; +template +using sVec = std::vector; + +template +using sList = std::list; template using upStrMap_t = std::map>; diff --git a/experimental/cpp-serializer/src/amqp/CMakeLists.txt b/experimental/cpp-serializer/src/amqp/CMakeLists.txt index 08b2a18f2e..f1c7e53b11 100644 --- a/experimental/cpp-serializer/src/amqp/CMakeLists.txt +++ b/experimental/cpp-serializer/src/amqp/CMakeLists.txt @@ -4,21 +4,27 @@ include_directories (reader) include_directories (.) set (amqp_sources - descriptors/AMQPDescriptors.cxx - descriptors/AMQPDescriptorRegistory.cxx - schema/Schema.cxx - schema/Field.cxx - schema/Envelope.cxx - schema/Composite.cxx - schema/Descriptor.cxx - schema/restricted-types/Restricted.cxx - schema/restricted-types/List.cxx - schema/AMQPTypeNotation.cxx + CompositeFactory.cxx + descriptors/AMQPDescriptors.cxx + descriptors/AMQPDescriptorRegistory.cxx + schema/Schema.cxx + schema/Field.cxx + schema/Envelope.cxx + schema/Composite.cxx + schema/Descriptor.cxx + schema/restricted-types/Restricted.cxx + schema/restricted-types/List.cxx + schema/AMQPTypeNotation.cxx reader/Reader.cxx - reader/PropertyReader.cxx reader/RestrictedReader.cxx reader/CompositeReader.cxx - CompositeFactory.cxx + reader/PropertyReader.cxx + reader/property-readers/StringPropertyReader.cxx + reader/property-readers/IntPropertyReader.cxx + reader/property-readers/DoublePropertyReader.cxx + reader/property-readers/LongPropertyReader.cxx + reader/property-readers/BoolPropertyReader.cxx + reader/restricted-readers/ListReader.cxx ) ADD_LIBRARY ( amqp ${amqp_sources} ) diff --git a/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx b/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx index bd78d53de2..1c176dc530 100644 --- a/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx +++ b/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx @@ -12,9 +12,10 @@ #include "amqp/reader/IReader.h" #include "reader/Reader.h" -#include "reader/PropertyReader.h" +#include "amqp/reader/PropertyReader.h" #include "reader/CompositeReader.h" #include "reader/RestrictedReader.h" +#include "reader/restricted-readers/ListReader.h" #include "schema/restricted-types/List.h" diff --git a/experimental/cpp-serializer/src/amqp/CompositeFactory.h b/experimental/cpp-serializer/src/amqp/CompositeFactory.h index 67d0a22c2d..9bbdf44ab8 100644 --- a/experimental/cpp-serializer/src/amqp/CompositeFactory.h +++ b/experimental/cpp-serializer/src/amqp/CompositeFactory.h @@ -11,41 +11,42 @@ #include "amqp/schema/Schema.h" #include "amqp/schema/Envelope.h" #include "amqp/schema/Composite.h" -#include "amqp/reader/PropertyReader.h" #include "amqp/reader/CompositeReader.h" /******************************************************************************/ namespace amqp::internal { -class CompositeFactory : public ICompositeFactory { - private : - using CompositePtr = uPtr; - using EnvelopePtr = uPtr; + class CompositeFactory + : public ICompositeFactory + { + private : + using CompositePtr = uPtr; + using EnvelopePtr = uPtr; - /** - * - */ - spStrMap_t m_readersByType; - spStrMap_t m_readersByDescriptor; + spStrMap_t m_readersByType; + spStrMap_t m_readersByDescriptor; - public : - CompositeFactory() = default; + public : + CompositeFactory() = default; - void process(const SchemaType &) override; + void process (const SchemaType &) override; - const std::shared_ptr byType(const std::string &) override; + const std::shared_ptr byType ( + const std::string &) override; - const std::shared_ptr byDescriptor(const std::string &) override; + const std::shared_ptr byDescriptor ( + const std::string &) override; - private : - std::shared_ptr process(const amqp::internal::schema::AMQPTypeNotation &); + private : + std::shared_ptr process ( + const schema::AMQPTypeNotation &); - std::shared_ptr - processComposite(const amqp::internal::schema::AMQPTypeNotation &); + std::shared_ptr processComposite ( + const schema::AMQPTypeNotation &); - std::shared_ptr - processRestricted(const amqp::internal::schema::AMQPTypeNotation &); + std::shared_ptr processRestricted ( + const schema::AMQPTypeNotation &); }; } diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx index 5910affccc..46502dee5d 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx @@ -6,19 +6,16 @@ /******************************************************************************/ -namespace amqp { -namespace internal { +namespace amqp::internal { const uint64_t DESCRIPTOR_TOP_32BITS = 0xc562L << (32 + 16); } -} /******************************************************************************/ -namespace amqp { -namespace internal { +namespace amqp::internal { const int ENVELOPE = 1; const int SCHEMA = 2; @@ -33,7 +30,6 @@ namespace internal { const int TRANSFORM_ELEMENT_KEY = 11; } -} /******************************************************************************/ @@ -134,7 +130,7 @@ amqp::stripCorda (uint64_t id) { /******************************************************************************/ std::string -amqp::describedToString(uint64_t val_) { +amqp::describedToString (uint64_t val_) { switch (val_) { case (1L | internal::DESCRIPTOR_TOP_32BITS) : return "ENVELOPE"; case (2L | internal::DESCRIPTOR_TOP_32BITS) : return "SCHEMA"; @@ -154,7 +150,7 @@ amqp::describedToString(uint64_t val_) { /******************************************************************************/ std::string -amqp::describedToString(uint32_t val_) { +amqp::describedToString (uint32_t val_) { return describedToString(val_ | internal::DESCRIPTOR_TOP_32BITS); } diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx index d8cb24dde2..7d2d9102c2 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx @@ -28,13 +28,13 @@ namespace { /** - * Look up a described type by its ID in the AMQPDescriptorRegistory and - * return the coresponding schema type. Specialised below to avoid + * Look up a described type by its ID in the AMQPDescriptorRegistry and + * return the corresponding schema type. Specialised below to avoid * the cast and re-owning of the unigue pointer when we're happy - * with a simple std::unique_ptr + * with a simple uPtr */ template - std::unique_ptr + uPtr dispatchDescribed (pn_data_t * data_) { proton::is_described(data_); proton::auto_enter p (data_); @@ -42,7 +42,7 @@ namespace { auto id = pn_data_get_ulong(data_); - return std::unique_ptr ( + return uPtr ( static_cast(amqp::AMQPDescriptorRegistory[id]->build(data_).release())); } @@ -83,7 +83,7 @@ namespace { * ******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: EnvelopeDescriptor::build(pn_data_t * data_) const { DBG ("ENVELOPE" << std::endl); // NOLINT @@ -120,7 +120,7 @@ EnvelopeDescriptor::build(pn_data_t * data_) const { /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: SchemaDescriptor::build(pn_data_t * data_) const { DBG ("SCHEMA" << std::endl); // NOLINT @@ -156,7 +156,7 @@ SchemaDescriptor::build(pn_data_t * data_) const { /** * */ -std::unique_ptr +uPtr amqp::internal:: ObjectDescriptor::build(pn_data_t * data_) const { DBG ("DESCRIPTOR" << std::endl); // NOLINT @@ -176,7 +176,7 @@ ObjectDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: FieldDescriptor::build(pn_data_t * data_) const { DBG ("FIELD" << std::endl); // NOLINT @@ -186,12 +186,12 @@ FieldDescriptor::build(pn_data_t * data_) const { proton::auto_enter ae (data_); /* name: String */ - auto name = proton::get_string(data_); + auto name = proton::get_string (data_); pn_data_next(data_); /* type: String */ - auto type = proton::get_string(data_); + auto type = proton::get_string (data_); pn_data_next(data_); @@ -207,18 +207,18 @@ FieldDescriptor::build(pn_data_t * data_) const { pn_data_next(data_); /* default: String? */ - auto def = proton::get_string(data_, true); + auto def = proton::get_string (data_, true); pn_data_next(data_); /* label: String? */ - auto label = proton::get_string(data_, true); + auto label = proton::get_string (data_, true); pn_data_next(data_); /* mandatory: Boolean - copes with the Kotlin concept of nullability. If something is mandatory then it cannot be null */ - auto mandatory = proton::get_boolean(data_); + auto mandatory = proton::get_boolean (data_); pn_data_next(data_); @@ -235,9 +235,9 @@ FieldDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -CompositeDescriptor::build(pn_data_t * data_) const { +CompositeDescriptor::build (pn_data_t * data_) const { DBG ("COMPOSITE" << std::endl); // NOLINT validateAndNext(data_); @@ -250,7 +250,7 @@ CompositeDescriptor::build(pn_data_t * data_) const { pn_data_next(data_); /* Label Name - Nullable String */ - auto label = proton::get_string(data_, true); + auto label = proton::get_string (data_, true); pn_data_next(data_); @@ -271,11 +271,11 @@ CompositeDescriptor::build(pn_data_t * data_) const { pn_data_next(data_); /* fields: List*/ - std::vector> fields; + std::vector> fields; fields.reserve (pn_data_get_list (data_)); { proton::auto_list_enter p2 (data_); - while (pn_data_next(data_)) { + while (pn_data_next (data_)) { fields.emplace_back (dispatchDescribed(data_)); } } @@ -301,9 +301,9 @@ CompositeDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -RestrictedDescriptor::build(pn_data_t * data_) const { +RestrictedDescriptor::build (pn_data_t * data_) const { DBG ("RESTRICTED" << std::endl); // NOLINT validateAndNext(data_); @@ -322,8 +322,8 @@ RestrictedDescriptor::build(pn_data_t * data_) const { pn_data_next (data_); - auto source = proton::readAndNext(data_); - auto descriptor = dispatchDescribed(data_); + auto source = proton::readAndNext (data_); + auto descriptor = dispatchDescribed (data_); // SKIP the choices section **FOR NOW** @@ -337,62 +337,62 @@ RestrictedDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -ChoiceDescriptor::build(pn_data_t * data_) const { +ChoiceDescriptor::build (pn_data_t * data_) const { validateAndNext(data_); DBG ("CHOICE " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return uPtr (nullptr); } /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -ReferencedObjectDescriptor::build(pn_data_t * data_) const { - validateAndNext(data_); +ReferencedObjectDescriptor::build (pn_data_t * data_) const { + validateAndNext (data_); DBG ("REFERENCED OBJECT " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return uPtr (nullptr); } /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -TransformSchemaDescriptor::build(pn_data_t * data_) const { - validateAndNext(data_); +TransformSchemaDescriptor::build (pn_data_t * data_) const { + validateAndNext (data_); DBG ("TRANSFORM SCHEMA " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return uPtr (nullptr); } /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -TransformElementDescriptor::build(pn_data_t * data_) const { - validateAndNext(data_); +TransformElementDescriptor::build (pn_data_t * data_) const { + validateAndNext (data_); DBG ("TRANSFORM ELEMENT " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return uPtr (nullptr); } /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal:: -TransformElementKeyDescriptor::build(pn_data_t * data_) const { - validateAndNext(data_); +TransformElementKeyDescriptor::build (pn_data_t * data_) const { + validateAndNext (data_); DBG ("TRANSFORM ELEMENT KEY" << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return uPtr (nullptr); } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx index a0079534ec..8ce375cab8 100644 --- a/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx @@ -27,7 +27,7 @@ CompositeReader::m_name { // NOLINT amqp::internal::reader:: CompositeReader::CompositeReader ( std::string type_, - std::vector> & readers_ + sVec> & readers_ ) : m_readers (readers_) , m_type (std::move (type_)) { @@ -78,7 +78,7 @@ CompositeReader::readString (pn_data_t * data_) const { /******************************************************************************/ -std::vector> +sVec> amqp::internal::reader:: CompositeReader::_dump ( pn_data_t * data_, @@ -88,14 +88,14 @@ CompositeReader::_dump ( proton::is_described (data_); proton::auto_enter ae (data_); - const auto & it = schema_.fromDescriptor(proton::get_symbol(data_)); - auto & fields = dynamic_cast(*(it->second.get())).fields(); + const auto & it = schema_.fromDescriptor (proton::get_symbol(data_)); + auto & fields = dynamic_cast(*(it->second.get())).fields(); assert (fields.size() == m_readers.size()); pn_data_next (data_); - std::vector> read; + sVec> read; read.reserve (fields.size()); proton::is_list (data_); @@ -120,14 +120,14 @@ CompositeReader::_dump ( /******************************************************************************/ -std::unique_ptr +uPtr amqp::internal::reader:: CompositeReader::dump ( const std::string & name_, pn_data_t * data_, const SchemaType & schema_) const { - return std::make_unique>>> ( + return std::make_unique>>> ( name_, _dump(data_, schema_)); } @@ -137,13 +137,13 @@ CompositeReader::dump ( /** * */ -std::unique_ptr +uPtr amqp::internal::reader:: CompositeReader::dump ( pn_data_t * data_, const SchemaType & schema_) const { - return std::make_unique>>> ( + return std::make_unique>>> ( _dump (data_, schema_)); } diff --git a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx index 85a300dcd8..4da3f678a0 100644 --- a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx @@ -1,5 +1,11 @@ #include "PropertyReader.h" +#include "amqp/reader/property-readers/IntPropertyReader.h" +#include "amqp/reader/property-readers/BoolPropertyReader.h" +#include "amqp/reader/property-readers/LongPropertyReader.h" +#include "amqp/reader/property-readers/StringPropertyReader.h" +#include "amqp/reader/property-readers/DoublePropertyReader.h" + #include #include #include @@ -52,68 +58,6 @@ namespace { /******************************************************************************/ -const std::string -amqp::internal::reader:: -StringPropertyReader::m_name { // NOLINT - "String Reader" -}; - -const std::string -amqp::internal::reader:: -StringPropertyReader::m_type { // NOLINT - "string" -}; - -const std::string -amqp::internal::reader:: -IntPropertyReader::m_name { // NOLINT - "Int Reader" -}; - -const std::string -amqp::internal::reader:: -IntPropertyReader::m_type { // NOLINT - "int" -}; - -const std::string -amqp::internal::reader:: -BoolPropertyReader::m_name { // NOLINT - "Bool Reader" -}; - -const std::string -amqp::internal::reader:: -BoolPropertyReader::m_type { // NOLINT - "bool" -}; - -const std::string -amqp::internal::reader:: -LongPropertyReader::m_name { // NOLINT - "Long Reader" -}; - -const std::string -amqp::internal::reader:: -LongPropertyReader::m_type { // NOLINT - "long" -}; - -const std::string -amqp::internal::reader:: -DoublePropertyReader::m_name { // NOLINT - "Double Reader" -}; - -const std::string -amqp::internal::reader:: -DoublePropertyReader::m_type { // NOLINT - "double" -}; - -/******************************************************************************/ - /** * Static factory method */ @@ -131,235 +75,6 @@ PropertyReader::make (const std::string & type_) { return propertyMap[type_](); } -/****************************************************************************** - * - * StringPropertyReader - * - ******************************************************************************/ - -std::any -amqp::internal::reader:: -StringPropertyReader::read (pn_data_t * data_) const { - return std::any ("hello"); -} - /******************************************************************************/ -std::string -amqp::internal::reader:: -StringPropertyReader::readString (pn_data_t * data_) const { - return proton::readAndNext (data_); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -StringPropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - name_, - "\"" + proton::readAndNext (data_) + "\""); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -StringPropertyReader::dump ( - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - "\"" + proton::readAndNext (data_) + "\""); -} - -/****************************************************************************** - * - * IntPropertyReader - * - ******************************************************************************/ - -std::any -amqp::internal::reader:: -IntPropertyReader::read (pn_data_t * data_) const { - return std::any (1); -} - -/******************************************************************************/ - -std::string -amqp::internal::reader:: -IntPropertyReader::readString (pn_data_t * data_) const { - return std::to_string (proton::readAndNext (data_)); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -IntPropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - name_, - std::to_string (proton::readAndNext (data_))); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -IntPropertyReader::dump ( - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - std::to_string (proton::readAndNext (data_))); -} - -/****************************************************************************** - * - * BoolPropertyReader - * - ******************************************************************************/ - -std::any -amqp::internal::reader:: -BoolPropertyReader::read (pn_data_t * data_) const { - return std::any (true); -} - -/******************************************************************************/ - -std::string -amqp::internal::reader:: -BoolPropertyReader::readString (pn_data_t * data_) const { - return std::to_string (proton::readAndNext (data_)); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -BoolPropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - name_, - std::to_string (proton::readAndNext (data_))); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -BoolPropertyReader::dump ( - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - std::to_string (proton::readAndNext (data_))); -} - -/****************************************************************************** - * - * LongPropertyReader - * - ******************************************************************************/ - -std::any -amqp::internal::reader:: -LongPropertyReader::read (pn_data_t * data_) const { - return std::any (10L); -} - -/******************************************************************************/ - -std::string -amqp::internal::reader:: -LongPropertyReader::readString (pn_data_t * data_) const { - return std::to_string (proton::readAndNext (data_)); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -LongPropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - name_, - std::to_string (proton::readAndNext (data_))); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -LongPropertyReader::dump ( - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - std::to_string (proton::readAndNext (data_))); -} - -/****************************************************************************** - * - * DoublePropertyReader - * - ******************************************************************************/ - -std::any -amqp::internal::reader:: -DoublePropertyReader::read (pn_data_t * data_) const { - return std::any (10.0); -} - -/******************************************************************************/ - -std::string -amqp::internal::reader:: -DoublePropertyReader::readString (pn_data_t * data_) const { - return std::to_string (proton::readAndNext (data_)); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -DoublePropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - name_, - std::to_string (proton::readAndNext (data_))); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -DoublePropertyReader::dump ( - pn_data_t * data_, - const SchemaType & schema_) const -{ - return std::make_unique> ( - std::to_string (proton::readAndNext (data_))); -} - -/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h index cffc975636..597e404cd9 100644 --- a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h @@ -2,7 +2,6 @@ /******************************************************************************/ -#include #include "Reader.h" #include "amqp/schema/Field.h" @@ -13,7 +12,7 @@ namespace amqp::internal::reader { class PropertyReader : public Reader { private : - using FieldPtr = std::unique_ptr; + using FieldPtr = uPtr; public : /** @@ -41,163 +40,9 @@ namespace amqp::internal::reader { ) const override = 0; const std::string & name() const override = 0; - const std::string & type() const override = 0; }; - - class StringPropertyReader : public PropertyReader { - private : - static const std::string m_name; - static const std::string m_type; - - public : - std::string readString (pn_data_t *) const override; - - std::any read (pn_data_t *) const override; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType & - ) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType & - ) const override; - - const std::string & name() const override { - return m_name; - } - - const std::string & type() const override { - return m_type; - } - }; - - class IntPropertyReader : public PropertyReader { - private : - static const std::string m_name; - static const std::string m_type; - - public : - ~IntPropertyReader() override = default; - - std::string readString (pn_data_t *) const override; - - std::any read (pn_data_t *) const override; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType & - ) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType & - ) const override; - - const std::string & name() const override { - return m_name; - } - - const std::string & type() const override { - return m_type; - } - }; - - class BoolPropertyReader : public PropertyReader { - private : - static const std::string m_name; - static const std::string m_type; - - public : - std::string readString (pn_data_t *) const override; - - std::any read (pn_data_t *) const override; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType & - ) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType & - ) const override; - - const std::string & name() const override { - return m_name; - } - - const std::string & type() const override { - return m_type; - } - }; - - class LongPropertyReader : public PropertyReader { - private : - static const std::string m_name; - static const std::string m_type; - - public : - std::string readString (pn_data_t *) const override; - - std::any read (pn_data_t *) const override; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType & - ) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType & - ) const override; - - const std::string & name() const override { - return m_name; - } - - const std::string & type() const override { - return m_type; - } - }; - - class DoublePropertyReader : public PropertyReader { - private : - static const std::string m_name; - static const std::string m_type; - - public : - std::string readString (pn_data_t *) const override; - - std::any read (pn_data_t *) const override; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType & - ) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType & - ) const override; - - const std::string & name() const override { - return m_name; - } - - const std::string & type() const override { - return m_type; - } - }; - } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/Reader.cxx b/experimental/cpp-serializer/src/amqp/reader/Reader.cxx index ea91d2ccd8..5dedd50678 100644 --- a/experimental/cpp-serializer/src/amqp/reader/Reader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/Reader.cxx @@ -51,7 +51,7 @@ namespace { template std::string - dumpPair(const std::string & name_, const T & begin_, const T & end_) { + dumpPair (const std::string & name_, const T & begin_, const T & end_) { std::stringstream rtn; { Auto am (name_, rtn); @@ -67,7 +67,7 @@ namespace { template std::string - dumpSingle(const T & begin_, const T & end_) { + dumpSingle (const T & begin_, const T & end_) { std::stringstream rtn; { Auto am (rtn); @@ -92,28 +92,28 @@ namespace { template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const { +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const { +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const { +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const { +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } @@ -126,28 +126,28 @@ TypedPair>>::dump() const { template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const { +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const { +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const { +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const { +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } diff --git a/experimental/cpp-serializer/src/amqp/reader/Reader.h b/experimental/cpp-serializer/src/amqp/reader/Reader.h index 56244e5e17..f29d86c949 100644 --- a/experimental/cpp-serializer/src/amqp/reader/Reader.h +++ b/experimental/cpp-serializer/src/amqp/reader/Reader.h @@ -41,11 +41,11 @@ namespace amqp::internal::reader { { } explicit TypedSingle (T && value_) - : Single() - , m_value { std::move (value_) } + : Single() + , m_value { std::move (value_) } { } - explicit TypedSingle (const TypedSingle && value_) noexcept + TypedSingle (const TypedSingle && value_) noexcept : Single() , m_value { std::move (value_.m_value) } { } @@ -73,7 +73,6 @@ namespace amqp::internal::reader { { } std::string dump() const override = 0; - }; @@ -93,7 +92,7 @@ namespace amqp::internal::reader { , m_value (std::move (value_)) { } - explicit TypedPair (TypedPair && pair_) noexcept + TypedPair (TypedPair && pair_) noexcept : Pair (std::move (pair_.m_property)) , m_value (std::move (pair_.m_value)) { } @@ -130,26 +129,26 @@ TypedSingle::dump() const { template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const; +TypedSingle>>::dump() const; template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const; +TypedSingle>>::dump() const; template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const; +TypedSingle>>::dump() const; template<> std::string amqp::internal::reader:: -TypedSingle>>::dump() const; +TypedSingle>>::dump() const; /****************************************************************************** * - * amqp::interanel::reader::TypedPair + * amqp::internal::reader::TypedPair * ******************************************************************************/ @@ -170,23 +169,23 @@ TypedPair::dump() const { template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const; +TypedPair>>::dump() const; template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const; +TypedPair>>::dump() const; template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const; +TypedPair>>::dump() const; template<> std::string amqp::internal::reader:: -TypedPair>>::dump() const; +TypedPair>>::dump() const; /****************************************************************************** * @@ -197,7 +196,7 @@ TypedPair>>::dump() cons namespace amqp::internal::reader { - using IReader = amqp::reader::IReader; + using IReader = amqp::reader::IReader; class Reader : public IReader { public : @@ -209,12 +208,12 @@ namespace amqp::internal::reader { std::any read (struct pn_data_t *) const override = 0; std::string readString (struct pn_data_t *) const override = 0; - std::unique_ptr dump( + uPtr dump( const std::string &, pn_data_t *, const SchemaType &) const override = 0; - std::unique_ptr dump( + uPtr dump( pn_data_t *, const SchemaType &) const override = 0; }; diff --git a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx index b2137453f5..e89ab547d7 100644 --- a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx @@ -26,7 +26,7 @@ RestrictedReader::m_name { // NOLINT std::any amqp::internal::reader:: -RestrictedReader::read(pn_data_t *) const { +RestrictedReader::read (pn_data_t *) const { return std::any(1); } @@ -34,70 +34,12 @@ RestrictedReader::read(pn_data_t *) const { std::string amqp::internal::reader:: -RestrictedReader::readString(pn_data_t * data_) const { +RestrictedReader::readString (pn_data_t * data_) const { return "hello"; } /******************************************************************************/ -std::list> -amqp::internal::reader:: -ListReader::dump_( - pn_data_t * data_, - const SchemaType & schema_ -) const { - proton::is_described (data_); - - std::list> read; - - { - proton::auto_enter ae (data_); - auto it = schema_.fromDescriptor (proton::readAndNext(data_)); - - { - proton::auto_list_enter ale (data_, true); - - for (size_t i { 0 } ; i < ale.elements() ; ++i) { - read.emplace_back (m_reader.lock()->dump (data_, schema_)); - } - } - } - - return read; -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -ListReader::dump ( - const std::string & name_, - pn_data_t * data_, - const SchemaType & schema_ -) const { - proton::auto_next an (data_); - - return std::make_unique>>>( - name_, - dump_ (data_, schema_)); -} - -/******************************************************************************/ - -std::unique_ptr -amqp::internal::reader:: -ListReader::dump( - pn_data_t * data_, - const SchemaType & schema_ -) const { - proton::auto_next an (data_); - - return std::make_unique>>>( - dump_ (data_, schema_)); -} - -/******************************************************************************/ - const std::string & amqp::internal::reader:: RestrictedReader::name() const { @@ -112,17 +54,4 @@ RestrictedReader::type() const { return m_type; } -/****************************************************************************** - * - * - * - ******************************************************************************/ - -amqp::internal::schema::Restricted::RestrictedTypes -amqp::internal::reader:: -ListReader::restrictedType() const { - return internal::schema::Restricted::RestrictedTypes::List; -} - /******************************************************************************/ - diff --git a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h index 0c1db3ae6b..97c838279f 100644 --- a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h @@ -43,40 +43,4 @@ namespace amqp::internal::reader { /******************************************************************************/ -namespace amqp::internal::reader { - - class ListReader : public RestrictedReader { - private : - // How to read the underlying types - std::weak_ptr m_reader; - - std::list> dump_( - pn_data_t *, - const SchemaType &) const; - - public : - ListReader ( - const std::string & type_, - std::weak_ptr reader_ - ) : RestrictedReader (type_) - , m_reader (std::move (reader_)) - { } - - ~ListReader() final = default; - - internal::schema::Restricted::RestrictedTypes restrictedType() const; - - std::unique_ptr dump( - const std::string &, - pn_data_t *, - const SchemaType &) const override; - - std::unique_ptr dump( - pn_data_t *, - const SchemaType &) const override; - }; - -} - -/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx new file mode 100644 index 0000000000..16d050ea73 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx @@ -0,0 +1,87 @@ +#include "BoolPropertyReader.h" + +#include "proton/proton_wrapper.h" + +/****************************************************************************** + * + * BoolPropertyReader statics + * + ******************************************************************************/ + +const std::string + amqp::internal::reader:: + BoolPropertyReader::m_name { // NOLINT + "Bool Reader" +}; + +/******************************************************************************/ + +const std::string + amqp::internal::reader:: + BoolPropertyReader::m_type { // NOLINT + "bool" +}; + +/****************************************************************************** + * + * BoolPropertyReader + * + ******************************************************************************/ + +std::any +amqp::internal::reader:: +BoolPropertyReader::read (pn_data_t * data_) const { + return std::any (true); +} + +/******************************************************************************/ + +std::string +amqp::internal::reader:: +BoolPropertyReader::readString (pn_data_t * data_) const { + return std::to_string (proton::readAndNext (data_)); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +BoolPropertyReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + name_, + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +BoolPropertyReader::dump ( + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +BoolPropertyReader::name() const { + return m_name; +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +BoolPropertyReader::type() const { + return m_type; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.h new file mode 100644 index 0000000000..fad514be34 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.h @@ -0,0 +1,38 @@ +#pragma once + +/******************************************************************************/ + +#include "PropertyReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class BoolPropertyReader : public PropertyReader { + private : + static const std::string m_name; + static const std::string m_type; + + public : + std::string readString (pn_data_t *) const override; + + std::any read (pn_data_t *) const override; + + uPtr dump( + const std::string &, + pn_data_t *, + const SchemaType & + ) const override; + + uPtr dump( + pn_data_t *, + const SchemaType & + ) const override; + + const std::string & name() const override; + const std::string & type() const override; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.cxx new file mode 100644 index 0000000000..cdc37647d1 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.cxx @@ -0,0 +1,85 @@ +#include "DoublePropertyReader.h" + +#include "proton/proton_wrapper.h" + +/****************************************************************************** + * + * DoublePropertyReader statics + * + ******************************************************************************/ + +const std::string +amqp::internal::reader:: +DoublePropertyReader::m_name { // NOLINT + "Double Reader" +}; + +const std::string +amqp::internal::reader:: +DoublePropertyReader::m_type { // NOLINT + "double" +}; + +/****************************************************************************** + * + * DoublePropertyReader + * + ******************************************************************************/ + +std::any +amqp::internal::reader:: +DoublePropertyReader::read (pn_data_t * data_) const { + return std::any (10.0); +} + +/******************************************************************************/ + +std::string +amqp::internal::reader:: +DoublePropertyReader::readString (pn_data_t * data_) const { + return std::to_string (proton::readAndNext (data_)); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +DoublePropertyReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + name_, + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +DoublePropertyReader::dump ( + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +DoublePropertyReader::name() const { + return m_name; +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +DoublePropertyReader::type() const { + return m_type; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.h new file mode 100644 index 0000000000..d7d42e6ba4 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/DoublePropertyReader.h @@ -0,0 +1,37 @@ +#pragma once + +/******************************************************************************/ + +#include "PropertyReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class DoublePropertyReader : public PropertyReader { + private : + static const std::string m_name; + static const std::string m_type; + + public : + std::string readString (pn_data_t *) const override; + + std::any read (pn_data_t *) const override; + + uPtr dump ( + const std::string &, + pn_data_t *, + const SchemaType & + ) const override; + + uPtr dump ( + pn_data_t *, + const SchemaType & + ) const override; + + const std::string & name() const override; + const std::string & type() const override; + }; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.cxx new file mode 100644 index 0000000000..b76506aeb6 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.cxx @@ -0,0 +1,93 @@ + +#include "IntPropertyReader.h" + +#include +#include +#include + +#include "proton/proton_wrapper.h" +#include "amqp/reader/IReader.h" + +/****************************************************************************** + * + * IntPropertyReader statics + * + ******************************************************************************/ + +const std::string +amqp::internal::reader:: +IntPropertyReader::m_name { // NOLINT + "Int Reader" +}; + +/******************************************************************************/ + +const std::string +amqp::internal::reader:: +IntPropertyReader::m_type { // NOLINT + "int" +}; + +/****************************************************************************** + * + * IntPropertyReader + * + ******************************************************************************/ + +std::any +amqp::internal::reader:: +IntPropertyReader::read (pn_data_t * data_) const { + return std::any (1); +} + +/******************************************************************************/ + +std::string +amqp::internal::reader:: +IntPropertyReader::readString (pn_data_t * data_) const { + return std::to_string (proton::readAndNext (data_)); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +IntPropertyReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + name_, + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +IntPropertyReader::dump ( + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +IntPropertyReader::name() const { + return m_name; +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +IntPropertyReader::type() const { + return m_type; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h new file mode 100644 index 0000000000..0b9ba86b95 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h @@ -0,0 +1,39 @@ +#pragma once + +/******************************************************************************/ + +#include "PropertyReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class IntPropertyReader : public PropertyReader { + private : + static const std::string m_name; + static const std::string m_type; + + public : + ~IntPropertyReader() override = default; + + std::string readString(pn_data_t *) const override; + + std::any read(pn_data_t *) const override; + + uPtr dump( + const std::string &, + pn_data_t *, + const SchemaType & + ) const override; + + uPtr dump( + pn_data_t *, + const SchemaType & + ) const override; + + const std::string &name() const override; + const std::string &type() const override; + }; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx new file mode 100644 index 0000000000..23909b866b --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx @@ -0,0 +1,87 @@ +#include "LongPropertyReader.h" + +#include "proton/proton_wrapper.h" + +/****************************************************************************** + * + * LongPropertyReader statics + * + ******************************************************************************/ + +const std::string + amqp::internal::reader:: + LongPropertyReader::m_name { // NOLINT + "Long Reader" +}; + +/******************************************************************************/ + +const std::string + amqp::internal::reader:: + LongPropertyReader::m_type { // NOLINT + "long" +}; + +/****************************************************************************** + * + * LongPropertyReader + * + ******************************************************************************/ + +std::any +amqp::internal::reader:: +LongPropertyReader::read (pn_data_t * data_) const { + return std::any (10L); +} + +/******************************************************************************/ + +std::string +amqp::internal::reader:: +LongPropertyReader::readString (pn_data_t * data_) const { + return std::to_string (proton::readAndNext (data_)); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +LongPropertyReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + name_, + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +LongPropertyReader::dump ( + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + std::to_string (proton::readAndNext (data_))); +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +LongPropertyReader::name() const { + return m_name; +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +LongPropertyReader::type() const { + return m_type; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.h new file mode 100644 index 0000000000..ec68a2e83f --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.h @@ -0,0 +1,38 @@ +#pragma once + +/******************************************************************************/ + +#include "PropertyReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class LongPropertyReader : public PropertyReader { + private : + static const std::string m_name; + static const std::string m_type; + + public : + std::string readString (pn_data_t *) const override; + + std::any read (pn_data_t *) const override; + + uPtr dump( + const std::string &, + pn_data_t *, + const SchemaType & + ) const override; + + uPtr dump( + pn_data_t *, + const SchemaType & + ) const override; + + const std::string & name() const override; + const std::string & type() const override; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx new file mode 100644 index 0000000000..6d0c2d8594 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx @@ -0,0 +1,89 @@ +#include "StringPropertyReader.h" + +#include + +#include "proton/proton_wrapper.h" + +/****************************************************************************** + * + * StringPropertyReader statics + * + ******************************************************************************/ + +const std::string +amqp::internal::reader:: +StringPropertyReader::m_type { // NOLINT + "string" +}; + +/******************************************************************************/ + +const std::string + amqp::internal::reader:: + StringPropertyReader::m_name { // NOLINT + "String Reader" +}; + +/****************************************************************************** + * + * class StringPropertyReader + * + ******************************************************************************/ + +std::any +amqp::internal::reader:: +StringPropertyReader::read (pn_data_t * data_) const { + return std::any ("hello"); +} + +/******************************************************************************/ + +std::string +amqp::internal::reader:: +StringPropertyReader::readString (pn_data_t * data_) const { + return proton::readAndNext (data_); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +StringPropertyReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + name_, + "\"" + proton::readAndNext (data_) + "\""); +} + +/******************************************************************************/ + +uPtr +amqp::internal::reader:: +StringPropertyReader::dump ( + pn_data_t * data_, + const SchemaType & schema_) const +{ + return std::make_unique> ( + "\"" + proton::readAndNext (data_) + "\""); +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +StringPropertyReader::name() const { + return m_name; +} + +/******************************************************************************/ + +const std::string & +amqp::internal::reader:: +StringPropertyReader::type() const { + return m_type; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h new file mode 100644 index 0000000000..56894e9a42 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h @@ -0,0 +1,37 @@ +#pragma once + +/******************************************************************************/ + +#include "PropertyReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class StringPropertyReader : public PropertyReader { + private : + static const std::string m_name; + static const std::string m_type; + + public : + std::string readString (pn_data_t *) const override; + + std::any read (pn_data_t *) const override; + + uPtr dump ( + const std::string &, + pn_data_t *, + const SchemaType & + ) const override; + + uPtr dump ( + pn_data_t *, + const SchemaType & + ) const override; + + const std::string & name() const override; + const std::string & type() const override; + }; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx new file mode 100644 index 0000000000..92f18fed53 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx @@ -0,0 +1,75 @@ +#include "ListReader.h" + +#include "proton/proton_wrapper.h" + +/****************************************************************************** + * + * class ListReader + * + ******************************************************************************/ + +amqp::internal::schema::Restricted::RestrictedTypes +amqp::internal::reader:: +ListReader::restrictedType() const { + return internal::schema::Restricted::RestrictedTypes::List; +} + +/******************************************************************************/ + +std::unique_ptr +amqp::internal::reader:: +ListReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_ +) const { + proton::auto_next an (data_); + + return std::make_unique>>>( + name_, + dump_ (data_, schema_)); +} + +/******************************************************************************/ + +std::unique_ptr +amqp::internal::reader:: +ListReader::dump( + pn_data_t * data_, + const SchemaType & schema_ +) const { + proton::auto_next an (data_); + + return std::make_unique>>>( + dump_ (data_, schema_)); +} + +/******************************************************************************/ + +std::list> +amqp::internal::reader:: +ListReader::dump_( + pn_data_t * data_, + const SchemaType & schema_ +) const { + proton::is_described (data_); + + std::list> read; + + { + proton::auto_enter ae (data_); + auto it = schema_.fromDescriptor (proton::readAndNext(data_)); + + { + proton::auto_list_enter ale (data_, true); + + for (size_t i { 0 } ; i < ale.elements() ; ++i) { + read.emplace_back (m_reader.lock()->dump (data_, schema_)); + } + } + } + + return read; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.h b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.h new file mode 100644 index 0000000000..05e21ef9f5 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.h @@ -0,0 +1,44 @@ +#pragma once + +/******************************************************************************/ + +#include "RestrictedReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class ListReader : public RestrictedReader { + private : + // How to read the underlying types + std::weak_ptr m_reader; + + std::list> dump_( + pn_data_t *, + const SchemaType &) const; + + public : + ListReader ( + const std::string & type_, + std::weak_ptr reader_ + ) : RestrictedReader (type_) + , m_reader (std::move (reader_)) + { } + + ~ListReader() final = default; + + internal::schema::Restricted::RestrictedTypes restrictedType() const; + + std::unique_ptr dump( + const std::string &, + pn_data_t *, + const SchemaType &) const override; + + std::unique_ptr dump( + pn_data_t *, + const SchemaType &) const override; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/Composite.cxx b/experimental/cpp-serializer/src/amqp/schema/Composite.cxx index e0ded66be1..c0cb6d2601 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Composite.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Composite.cxx @@ -38,9 +38,9 @@ amqp::internal::schema:: Composite::Composite ( const std::string & name_, std::string label_, - const std::list & provides_, - std::unique_ptr & descriptor_, - std::vector> & fields_ + const sList & provides_, + uPtr & descriptor_, + std::vector> & fields_ ) : AMQPTypeNotation (name_, descriptor_) , m_label (std::move (label_)) , m_provides (provides_) @@ -49,7 +49,7 @@ Composite::Composite ( /******************************************************************************/ -const std::vector> & +const std::vector> & amqp::internal::schema:: Composite::fields() const { return m_fields; diff --git a/experimental/cpp-serializer/src/amqp/schema/Descriptor.cxx b/experimental/cpp-serializer/src/amqp/schema/Descriptor.cxx index 515e7b783d..a11cfb69d0 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Descriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Descriptor.cxx @@ -4,11 +4,11 @@ namespace amqp::internal::schema { -std::ostream & -operator << (std::ostream & stream_, const Descriptor & desc_) { - stream_ << desc_.m_name; - return stream_; -} + std::ostream & + operator << (std::ostream & stream_, const Descriptor & desc_) { + stream_ << desc_.m_name; + return stream_; + } } diff --git a/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx b/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx index e3ef5fd604..bc896cb2d3 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx @@ -28,7 +28,7 @@ operator << ( amqp::internal::schema:: Envelope::Envelope ( - std::unique_ptr & schema_, + uPtr & schema_, std::string descriptor_ ) : m_schema (std::move (schema_)) , m_descriptor (std::move (descriptor_))