diff --git a/experimental/cpp-serializer/include/ICompositeFactory.h b/experimental/cpp-serializer/include/ICompositeFactory.h deleted file mode 100644 index 3dc49a1745..0000000000 --- a/experimental/cpp-serializer/include/ICompositeFactory.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/******************************************************************************/ - -#include -#include - -#include "types.h" -#include "amqp/schema/Schema.h" -#include "amqp/schema/Envelope.h" -#include "amqp/schema/Composite.h" -#include "amqp/consumer/PropertyReader.h" -#include "amqp/consumer/CompositeReader.h" - -/******************************************************************************/ - -class ICompositeFactory { - public : - using SchemaPtr = uPtr; - - ICompositeFactory() = default; - virtual ~ICompositeFactory() = default; - - virtual void process (const SchemaPtr &) = 0; - - virtual const std::shared_ptr byType (const std::string &) = 0; - virtual const std::shared_ptr byDescriptor (const std::string &) = 0; - -}; - -/******************************************************************************/ - diff --git a/experimental/cpp-serializer/src/amqp/AMQPDescribed.h b/experimental/cpp-serializer/include/amqp/AMQPDescribed.h similarity index 91% rename from experimental/cpp-serializer/src/amqp/AMQPDescribed.h rename to experimental/cpp-serializer/include/amqp/AMQPDescribed.h index 62d8ebd6ef..32ce86d62d 100644 --- a/experimental/cpp-serializer/src/amqp/AMQPDescribed.h +++ b/experimental/cpp-serializer/include/amqp/AMQPDescribed.h @@ -2,7 +2,7 @@ /******************************************************************************/ -namespace amqp::internal { +namespace amqp { class AMQPDescribed { public : diff --git a/experimental/cpp-serializer/include/amqp/ICompositeFactory.h b/experimental/cpp-serializer/include/amqp/ICompositeFactory.h new file mode 100644 index 0000000000..45da49cb7d --- /dev/null +++ b/experimental/cpp-serializer/include/amqp/ICompositeFactory.h @@ -0,0 +1,33 @@ +#pragma once + +/******************************************************************************/ + +#include "types.h" + +#include "amqp/schema/ISchema.h" +#include "amqp/reader/IReader.h" + +/******************************************************************************/ + +namespace amqp { + + template + class ICompositeFactory { + public : + using SchemaType = schema::ISchema; + using ReaderType = reader::IReader; + + ICompositeFactory() = default; + + virtual ~ICompositeFactory() = default; + + virtual void process (const SchemaType &) = 0; + + virtual const std::shared_ptr byType (const std::string &) = 0; + virtual const std::shared_ptr byDescriptor (const std::string &) = 0; + }; + +} + +/******************************************************************************/ + diff --git a/experimental/cpp-serializer/include/amqp/reader/IReader.h b/experimental/cpp-serializer/include/amqp/reader/IReader.h new file mode 100644 index 0000000000..8c53731d1f --- /dev/null +++ b/experimental/cpp-serializer/include/amqp/reader/IReader.h @@ -0,0 +1,75 @@ +#pragma once + +/******************************************************************************/ + +#include + +#include "amqp/AMQPDescribed.h" + +#include "amqp/schema/Schema.h" + +/****************************************************************************** + * + * Forward declarations + * + ******************************************************************************/ + +struct pn_data_t; + +/****************************************************************************** + * + * class amqp::reader::IValue + * + ******************************************************************************/ + +/** + * Used by the dump method on all instantiated instances of amqp readers + * it represents the ability to pull out a value from the blob as determined + * by the reader type and convert it to a string formatted nicely as JSON + */ +namespace amqp::reader { + + class IValue { + public : + virtual std::string dump() const = 0; + + virtual ~IValue() = default; + }; + +} + +/****************************************************************************** + * + * class ampq::reader::IReader + * + ******************************************************************************/ + +namespace amqp::reader { + + template + class IReader { + public : + using SchemaType = amqp::schema::ISchema; + + virtual ~IReader() = default; + + virtual const std::string & name() const = 0; + virtual const std::string & type() const = 0; + + virtual std::any read (pn_data_t *) const = 0; + virtual std::string readString (pn_data_t *) const = 0; + + virtual std::unique_ptr dump( + const std::string &, + pn_data_t *, + const SchemaType &) const = 0; + + virtual std::unique_ptr dump( + pn_data_t *, + const SchemaType &) const = 0; + + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/include/amqp/schema/ISchema.h b/experimental/cpp-serializer/include/amqp/schema/ISchema.h new file mode 100644 index 0000000000..82af7d46c4 --- /dev/null +++ b/experimental/cpp-serializer/include/amqp/schema/ISchema.h @@ -0,0 +1,16 @@ +#pragma once + +#include "types.h" + +#include "amqp/AMQPDescribed.h" + +namespace amqp::schema { + + template + class ISchema { + public : + virtual Iterator fromType (const std::string &) const = 0; + virtual Iterator fromDescriptor (const std::string &) const = 0; + }; + +} \ No newline at end of file diff --git a/experimental/cpp-serializer/src/amqp/AMQPDescriptor.h b/experimental/cpp-serializer/src/amqp/AMQPDescriptor.h index 46d5d00f65..72d13a0070 100644 --- a/experimental/cpp-serializer/src/amqp/AMQPDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/AMQPDescriptor.h @@ -6,7 +6,7 @@ #include #include -#include "AMQPDescribed.h" +#include "amqp/AMQPDescribed.h" /****************************************************************************** * diff --git a/experimental/cpp-serializer/src/amqp/CMakeLists.txt b/experimental/cpp-serializer/src/amqp/CMakeLists.txt index 5a637888ea..08b2a18f2e 100644 --- a/experimental/cpp-serializer/src/amqp/CMakeLists.txt +++ b/experimental/cpp-serializer/src/amqp/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories (descriptors) include_directories (schema) -include_directories (consumer) +include_directories (reader) include_directories (.) set (amqp_sources @@ -14,10 +14,10 @@ set (amqp_sources schema/restricted-types/Restricted.cxx schema/restricted-types/List.cxx schema/AMQPTypeNotation.cxx - consumer/Reader.cxx - consumer/PropertyReader.cxx - consumer/RestrictedReader.cxx - consumer/CompositeReader.cxx + reader/Reader.cxx + reader/PropertyReader.cxx + reader/RestrictedReader.cxx + reader/CompositeReader.cxx CompositeFactory.cxx ) diff --git a/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx b/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx index e8dfce47a3..bd78d53de2 100644 --- a/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx +++ b/experimental/cpp-serializer/src/amqp/CompositeFactory.cxx @@ -10,10 +10,11 @@ #include "debug.h" -#include "consumer/Reader.h" -#include "consumer/PropertyReader.h" -#include "consumer/CompositeReader.h" -#include "consumer/RestrictedReader.h" +#include "amqp/reader/IReader.h" +#include "reader/Reader.h" +#include "reader/PropertyReader.h" +#include "reader/CompositeReader.h" +#include "reader/RestrictedReader.h" #include "schema/restricted-types/List.h" @@ -73,8 +74,8 @@ namespace { */ void amqp::internal:: -CompositeFactory::process (const SchemaPtr & schema_) { - for (const auto & i : *schema_) { +CompositeFactory::process (const SchemaType & schema_) { + for (const auto & i : dynamic_cast(schema_)) { for (const auto & j : i) { process(*j); m_readersByDescriptor[j->descriptor()] = m_readersByType[j->name()]; @@ -84,15 +85,15 @@ CompositeFactory::process (const SchemaPtr & schema_) { /******************************************************************************/ -std::shared_ptr +std::shared_ptr amqp::internal:: CompositeFactory::process( const amqp::internal::schema::AMQPTypeNotation & schema_) { - return computeIfAbsent ( + return computeIfAbsent ( m_readersByType, schema_.name(), - [& schema_, this] () -> std::shared_ptr { + [& schema_, this] () -> std::shared_ptr { switch (schema_.type()) { case amqp::internal::schema::AMQPTypeNotation::Composite : { return processComposite(schema_); @@ -106,12 +107,12 @@ CompositeFactory::process( /******************************************************************************/ -std::shared_ptr +std::shared_ptr amqp::internal:: CompositeFactory::processComposite ( const amqp::internal::schema::AMQPTypeNotation & type_) { - std::vector> readers; + std::vector> readers; const auto & fields = dynamic_cast ( type_).fields(); @@ -122,12 +123,12 @@ CompositeFactory::processComposite ( DBG (" Field: " << field->name() << ": " << field->type() << std::endl); // NOLINT switch (field->fieldType()) { - case amqp::internal::schema::FieldType::PrimitiveProperty : { - auto reader = computeIfAbsent( + case schema::FieldType::PrimitiveProperty : { + auto reader = computeIfAbsent( m_readersByType, field->type(), - [&field]() -> std::shared_ptr { - return amqp::PropertyReader::make(field); + [&field]() -> std::shared_ptr { + return reader::PropertyReader::make(field); }); assert (reader); @@ -143,7 +144,7 @@ CompositeFactory::processComposite ( assert (readers.back().lock()); break; } - case amqp::internal::schema::FieldType::RestrictedProperty : { + case schema::FieldType::RestrictedProperty : { auto reader = m_readersByType[field->requires().front()]; assert (reader); @@ -156,12 +157,12 @@ CompositeFactory::processComposite ( assert (readers.back().lock()); } - return std::make_shared (type_.name(), readers); + return std::make_shared (type_.name(), readers); } /******************************************************************************/ -std::shared_ptr +std::shared_ptr amqp::internal:: CompositeFactory::processRestricted ( const amqp::internal::schema::AMQPTypeNotation & type_) @@ -179,19 +180,19 @@ CompositeFactory::processRestricted ( if (amqp::internal::schema::Field::typeIsPrimitive(list.listOf())) { DBG (" List of Primitives" << std::endl); // NOLINT - auto reader = computeIfAbsent ( + auto reader = computeIfAbsent ( m_readersByType, list.listOf(), - [& list] () -> std::shared_ptr { - return amqp::PropertyReader::make (list.listOf()); + [& list] () -> std::shared_ptr { + return reader::PropertyReader::make (list.listOf()); }); - return std::make_shared (type_.name(), reader); + return std::make_shared (type_.name(), reader); } else { DBG (" List of Composite - " << list.listOf() << std::endl); // NOLINT auto reader = m_readersByType[list.listOf()]; - return std::make_shared (list.name(), reader); + return std::make_shared (list.name(), reader); } } @@ -201,7 +202,7 @@ CompositeFactory::processRestricted ( /******************************************************************************/ -const std::shared_ptr +const std::shared_ptr amqp::internal:: CompositeFactory::byType (const std::string & type_) { auto it = m_readersByType.find (type_); @@ -211,7 +212,7 @@ CompositeFactory::byType (const std::string & type_) { /******************************************************************************/ -const std::shared_ptr +const std::shared_ptr amqp::internal:: CompositeFactory::byDescriptor (const std::string & descriptor_) { auto it = m_readersByDescriptor.find (descriptor_); diff --git a/experimental/cpp-serializer/src/amqp/CompositeFactory.h b/experimental/cpp-serializer/src/amqp/CompositeFactory.h index f39bca8fe7..67d0a22c2d 100644 --- a/experimental/cpp-serializer/src/amqp/CompositeFactory.h +++ b/experimental/cpp-serializer/src/amqp/CompositeFactory.h @@ -7,18 +7,18 @@ #include "types.h" -#include "ICompositeFactory.h" +#include "amqp/ICompositeFactory.h" #include "amqp/schema/Schema.h" #include "amqp/schema/Envelope.h" #include "amqp/schema/Composite.h" -#include "amqp/consumer/PropertyReader.h" -#include "amqp/consumer/CompositeReader.h" +#include "amqp/reader/PropertyReader.h" +#include "amqp/reader/CompositeReader.h" /******************************************************************************/ namespace amqp::internal { - class CompositeFactory : public ICompositeFactory { +class CompositeFactory : public ICompositeFactory { private : using CompositePtr = uPtr; using EnvelopePtr = uPtr; @@ -26,25 +26,25 @@ namespace amqp::internal { /** * */ - spStrMap_t m_readersByType; - spStrMap_t m_readersByDescriptor; + spStrMap_t m_readersByType; + spStrMap_t m_readersByDescriptor; public : CompositeFactory() = default; - void process(const SchemaPtr &) override ; + void process(const SchemaType &) override; - virtual const std::shared_ptr byType(const std::string &) override; + const std::shared_ptr byType(const std::string &) override; - virtual 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 &); + std::shared_ptr process(const amqp::internal::schema::AMQPTypeNotation &); - std::shared_ptr + std::shared_ptr processComposite(const amqp::internal::schema::AMQPTypeNotation &); - std::shared_ptr + std::shared_ptr processRestricted(const amqp::internal::schema::AMQPTypeNotation &); }; diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx index fe0d7e2b99..d8cb24dde2 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx @@ -14,7 +14,7 @@ #include "Composite.h" #include "amqp/schema/restricted-types/Restricted.h" #include "amqp/schema/OrderedTypeNotations.h" -#include "AMQPDescribed.h" +#include "amqp/AMQPDescribed.h" #include "proton/proton_wrapper.h" #include "AMQPDescriptorRegistory.h" @@ -83,7 +83,7 @@ namespace { * ******************************************************************************/ -std::unique_ptr +std::unique_ptr 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 +std::unique_ptr 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 +std::unique_ptr 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 +std::unique_ptr amqp::internal:: FieldDescriptor::build(pn_data_t * data_) const { DBG ("FIELD" << std::endl); // NOLINT @@ -235,7 +235,7 @@ FieldDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: CompositeDescriptor::build(pn_data_t * data_) const { DBG ("COMPOSITE" << std::endl); // NOLINT @@ -301,7 +301,7 @@ CompositeDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: RestrictedDescriptor::build(pn_data_t * data_) const { DBG ("RESTRICTED" << std::endl); // NOLINT @@ -337,62 +337,62 @@ RestrictedDescriptor::build(pn_data_t * data_) const { * ******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: ChoiceDescriptor::build(pn_data_t * data_) const { validateAndNext(data_); DBG ("CHOICE " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return std::unique_ptr (nullptr); } /******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: ReferencedObjectDescriptor::build(pn_data_t * data_) const { validateAndNext(data_); DBG ("REFERENCED OBJECT " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return std::unique_ptr (nullptr); } /******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: TransformSchemaDescriptor::build(pn_data_t * data_) const { validateAndNext(data_); DBG ("TRANSFORM SCHEMA " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return std::unique_ptr (nullptr); } /******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: TransformElementDescriptor::build(pn_data_t * data_) const { validateAndNext(data_); DBG ("TRANSFORM ELEMENT " << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return std::unique_ptr (nullptr); } /******************************************************************************/ -std::unique_ptr +std::unique_ptr amqp::internal:: TransformElementKeyDescriptor::build(pn_data_t * data_) const { validateAndNext(data_); DBG ("TRANSFORM ELEMENT KEY" << data_ << std::endl); // NOLINT - return std::unique_ptr (nullptr); + return std::unique_ptr (nullptr); } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h index 89e8ec60fc..15d6f8b19a 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h @@ -18,7 +18,7 @@ struct pn_data_t; /******************************************************************************/ -namespace amqp:: internal { +namespace amqp::internal { class EnvelopeDescriptor : public AMQPDescriptor { public : diff --git a/experimental/cpp-serializer/src/amqp/consumer/CompositeReader.cxx b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx similarity index 75% rename from experimental/cpp-serializer/src/amqp/consumer/CompositeReader.cxx rename to experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx index f2c99cc9c2..a0079534ec 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/CompositeReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.cxx @@ -7,11 +7,15 @@ #include #include #include "debug.h" +#include "Reader.h" +#include "amqp/reader/IReader.h" #include "proton/proton_wrapper.h" /******************************************************************************/ -const std::string amqp::CompositeReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +CompositeReader::m_name { // NOLINT "Composite Reader" }; @@ -20,15 +24,15 @@ const std::string amqp::CompositeReader::m_name { // NOLINT * ******************************************************************************/ -amqp:: +amqp::internal::reader:: CompositeReader::CompositeReader ( std::string type_, - std::vector> & readers_ + std::vector> & readers_ ) : m_readers (readers_) , m_type (std::move (type_)) { DBG ("MAKE CompositeReader: " << m_type << ": " << m_readers.size() << std::endl); // NOLINT - for (auto reader : m_readers) { + for (auto const reader : m_readers) { assert (reader.lock()); if (auto r = reader.lock()) { DBG (" prop: " << r->name() << " " << r->type() << std::endl); // NOLINT @@ -39,7 +43,7 @@ CompositeReader::CompositeReader ( /******************************************************************************/ const std::string & -amqp:: +amqp::internal::reader:: CompositeReader::name() const { return m_name; } @@ -47,7 +51,7 @@ CompositeReader::name() const { /******************************************************************************/ const std::string & -amqp:: +amqp::internal::reader:: CompositeReader::type() const { return m_type; } @@ -55,7 +59,7 @@ CompositeReader::type() const { /******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: CompositeReader::read (pn_data_t * data_) const { return std::any(1); } @@ -63,7 +67,7 @@ CompositeReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: CompositeReader::readString (pn_data_t * data_) const { pn_data_next (data_); proton::auto_enter ae (data_); @@ -74,24 +78,24 @@ CompositeReader::readString (pn_data_t * data_) const { /******************************************************************************/ -std::vector> -amqp:: +std::vector> +amqp::internal::reader:: CompositeReader::_dump ( pn_data_t * data_, - const std::unique_ptr & schema_ + const SchemaType & schema_ ) const { DBG ("Read Composite: " << m_name << " : " << type() << std::endl); // NOLINT proton::is_described (data_); proton::auto_enter ae (data_); - const auto & it = schema_->fromDescriptor(proton::get_symbol(data_)); + 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; + std::vector> read; read.reserve (fields.size()); proton::is_list (data_); @@ -116,15 +120,14 @@ CompositeReader::_dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: CompositeReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { - - return std::make_unique>>> ( + return std::make_unique>>> ( name_, _dump(data_, schema_)); } @@ -134,14 +137,13 @@ CompositeReader::dump ( /** * */ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: CompositeReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { - - return std::make_unique>>> ( + return std::make_unique>>> ( _dump (data_, schema_)); } diff --git a/experimental/cpp-serializer/src/amqp/consumer/CompositeReader.h b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h similarity index 62% rename from experimental/cpp-serializer/src/amqp/consumer/CompositeReader.h rename to experimental/cpp-serializer/src/amqp/reader/CompositeReader.h index 444a07d871..1c90e897f6 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/CompositeReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h @@ -7,27 +7,24 @@ #include #include #include +#include /******************************************************************************/ -namespace amqp { +namespace amqp::internal::reader { class CompositeReader : public Reader { private : - std::vector> m_readers; + std::vector> m_readers; static const std::string m_name; std::string m_type; - std::vector> _dump ( - pn_data_t * data_, - const std::unique_ptr & schema_) const; - public : CompositeReader ( std::string type_, - std::vector> & readers_ + std::vector> & readers_ ); ~CompositeReader() override = default; @@ -36,17 +33,22 @@ namespace amqp { std::string readString(pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr &) const override; + const SchemaType &) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr &) const override; + const SchemaType &) const override; const std::string & name() const override; const std::string & type() const override; + + private : + std::vector> _dump ( + pn_data_t * data_, + const SchemaType & schema_) const; }; } diff --git a/experimental/cpp-serializer/src/amqp/consumer/PropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx similarity index 64% rename from experimental/cpp-serializer/src/amqp/consumer/PropertyReader.cxx rename to experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx index bb7597ca2f..85a300dcd8 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/PropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx @@ -13,34 +13,37 @@ namespace { - std::map(*)() > propertyMap = { + std::map< + std::string, + std::shared_ptr(*)() + > propertyMap = { // NOLINT { - "int", []() -> std::shared_ptr { - return std::make_shared (); + "int", []() -> std::shared_ptr { + return std::make_shared (); } }, { - "string", []() -> std::shared_ptr { - return std::make_shared ( - amqp::StringPropertyReader()); + "string", []() -> std::shared_ptr { + return std::make_shared ( + amqp::internal::reader::StringPropertyReader()); } }, { - "boolean", []() -> std::shared_ptr { - return std::make_shared ( - amqp::BoolPropertyReader()); + "boolean", []() -> std::shared_ptr { + return std::make_shared ( + amqp::internal::reader::BoolPropertyReader()); } }, { - "long", []() -> std::shared_ptr { - return std::make_shared ( - amqp::LongPropertyReader()); + "long", []() -> std::shared_ptr { + return std::make_shared ( + amqp::internal::reader::LongPropertyReader()); } }, { - "double", []() -> std::shared_ptr { - return std::make_shared ( - amqp::DoublePropertyReader()); + "double", []() -> std::shared_ptr { + return std::make_shared ( + amqp::internal::reader::DoublePropertyReader()); } } }; @@ -49,43 +52,63 @@ namespace { /******************************************************************************/ -const std::string amqp::StringPropertyReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +StringPropertyReader::m_name { // NOLINT "String Reader" }; -const std::string amqp::StringPropertyReader::m_type { // NOLINT +const std::string +amqp::internal::reader:: +StringPropertyReader::m_type { // NOLINT "string" }; -const std::string amqp::IntPropertyReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +IntPropertyReader::m_name { // NOLINT "Int Reader" }; -const std::string amqp::IntPropertyReader::m_type { // NOLINT +const std::string +amqp::internal::reader:: +IntPropertyReader::m_type { // NOLINT "int" }; -const std::string amqp::BoolPropertyReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +BoolPropertyReader::m_name { // NOLINT "Bool Reader" }; -const std::string amqp::BoolPropertyReader::m_type { // NOLINT +const std::string +amqp::internal::reader:: +BoolPropertyReader::m_type { // NOLINT "bool" }; -const std::string amqp::LongPropertyReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +LongPropertyReader::m_name { // NOLINT "Long Reader" }; -const std::string amqp::LongPropertyReader::m_type { // NOLINT - "long" +const std::string +amqp::internal::reader:: +LongPropertyReader::m_type { // NOLINT + "long" }; -const std::string amqp::DoublePropertyReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +DoublePropertyReader::m_name { // NOLINT "Double Reader" }; -const std::string amqp::DoublePropertyReader::m_type { // NOLINT +const std::string +amqp::internal::reader:: +DoublePropertyReader::m_type { // NOLINT "double" }; @@ -94,21 +117,20 @@ const std::string amqp::DoublePropertyReader::m_type { // NOLINT /** * Static factory method */ -std::shared_ptr -amqp:: +std::shared_ptr +amqp::internal::reader:: PropertyReader::make (const FieldPtr & field_) { return propertyMap[field_->type()](); } /******************************************************************************/ -std::shared_ptr -amqp:: +std::shared_ptr +amqp::internal::reader:: PropertyReader::make (const std::string & type_) { return propertyMap[type_](); } - /****************************************************************************** * * StringPropertyReader @@ -116,7 +138,7 @@ PropertyReader::make (const std::string & type_) { ******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: StringPropertyReader::read (pn_data_t * data_) const { return std::any ("hello"); } @@ -124,19 +146,19 @@ StringPropertyReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: StringPropertyReader::readString (pn_data_t * data_) const { return proton::readAndNext (data_); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: StringPropertyReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( name_, @@ -145,11 +167,11 @@ StringPropertyReader::dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: StringPropertyReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( "\"" + proton::readAndNext (data_) + "\""); @@ -162,7 +184,7 @@ StringPropertyReader::dump ( ******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: IntPropertyReader::read (pn_data_t * data_) const { return std::any (1); } @@ -170,19 +192,19 @@ IntPropertyReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: IntPropertyReader::readString (pn_data_t * data_) const { return std::to_string (proton::readAndNext (data_)); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: IntPropertyReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( name_, @@ -191,11 +213,11 @@ IntPropertyReader::dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: IntPropertyReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( std::to_string (proton::readAndNext (data_))); @@ -208,7 +230,7 @@ IntPropertyReader::dump ( ******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: BoolPropertyReader::read (pn_data_t * data_) const { return std::any (true); } @@ -216,19 +238,19 @@ BoolPropertyReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: BoolPropertyReader::readString (pn_data_t * data_) const { return std::to_string (proton::readAndNext (data_)); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: BoolPropertyReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( name_, @@ -237,11 +259,11 @@ BoolPropertyReader::dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: BoolPropertyReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( std::to_string (proton::readAndNext (data_))); @@ -254,7 +276,7 @@ BoolPropertyReader::dump ( ******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: LongPropertyReader::read (pn_data_t * data_) const { return std::any (10L); } @@ -262,19 +284,19 @@ LongPropertyReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: LongPropertyReader::readString (pn_data_t * data_) const { return std::to_string (proton::readAndNext (data_)); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: LongPropertyReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( name_, @@ -283,11 +305,11 @@ LongPropertyReader::dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: LongPropertyReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( std::to_string (proton::readAndNext (data_))); @@ -300,7 +322,7 @@ LongPropertyReader::dump ( ******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: DoublePropertyReader::read (pn_data_t * data_) const { return std::any (10.0); } @@ -308,19 +330,19 @@ DoublePropertyReader::read (pn_data_t * data_) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: DoublePropertyReader::readString (pn_data_t * data_) const { return std::to_string (proton::readAndNext (data_)); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: DoublePropertyReader::dump ( - const std::string & name_, - pn_data_t * data_, - const std::unique_ptr & schema_) const + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_) const { return std::make_unique> ( name_, @@ -329,11 +351,11 @@ DoublePropertyReader::dump ( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: DoublePropertyReader::dump ( pn_data_t * data_, - const std::unique_ptr & schema_) const + const SchemaType & schema_) const { return std::make_unique> ( std::to_string (proton::readAndNext (data_))); diff --git a/experimental/cpp-serializer/src/amqp/consumer/PropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h similarity index 78% rename from experimental/cpp-serializer/src/amqp/consumer/PropertyReader.h rename to experimental/cpp-serializer/src/amqp/reader/PropertyReader.h index 70f749dafd..cffc975636 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/PropertyReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.h @@ -9,7 +9,7 @@ /******************************************************************************/ -namespace amqp { +namespace amqp::internal::reader { class PropertyReader : public Reader { private : @@ -29,15 +29,15 @@ namespace amqp { std::any read (pn_data_t *) const override = 0; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override = 0; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override = 0; const std::string & name() const override = 0; @@ -56,15 +56,15 @@ namespace amqp { std::any read (pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; const std::string & name() const override { @@ -88,15 +88,15 @@ namespace amqp { std::any read (pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; const std::string & name() const override { @@ -118,15 +118,15 @@ namespace amqp { std::any read (pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; const std::string & name() const override { @@ -148,15 +148,15 @@ namespace amqp { std::any read (pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; const std::string & name() const override { @@ -178,15 +178,15 @@ namespace amqp { std::any read (pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr & + const SchemaType & ) const override; const std::string & name() const override { diff --git a/experimental/cpp-serializer/src/amqp/consumer/Reader.cxx b/experimental/cpp-serializer/src/amqp/reader/Reader.cxx similarity index 65% rename from experimental/cpp-serializer/src/amqp/consumer/Reader.cxx rename to experimental/cpp-serializer/src/amqp/reader/Reader.cxx index cde30c9909..ea91d2ccd8 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/Reader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/Reader.cxx @@ -10,11 +10,16 @@ namespace { struct AutoMap { std::stringstream & m_stream; - AutoMap (const std::string & s, std::stringstream & stream_) : m_stream (stream_) { + AutoMap ( + const std::string & s, + std::stringstream & stream_ + ) : m_stream (stream_) { m_stream << s << " : { "; } - AutoMap (std::stringstream & stream_) : m_stream (stream_) { + explicit AutoMap (std::stringstream & stream_) + : m_stream (stream_) + { m_stream << "{ "; } @@ -26,11 +31,16 @@ namespace { struct AutoList { std::stringstream & m_stream; - AutoList (const std::string & s, std::stringstream & stream_) : m_stream (stream_) { + AutoList ( + const std::string & s, + std::stringstream & stream_ + ) : m_stream (stream_) { m_stream << s << " : [ "; } - AutoList (std::stringstream & stream_) : m_stream (stream_) { + explicit AutoList (std::stringstream & stream_) + : m_stream (stream_) + { m_stream << "[ "; } @@ -63,7 +73,7 @@ namespace { Auto am (rtn); rtn << (*(begin_))->dump(); - for (auto it(std::next(begin_)) ; it != end_; ++it) { + for (auto it (std::next(begin_)) ; it != end_; ++it) { rtn << ", " << (*it)->dump(); } } @@ -81,25 +91,29 @@ namespace { template<> std::string -amqp::TypedPair>>::dump() const { +amqp::internal::reader:: +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedPair>>::dump() const { +amqp::internal::reader:: +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedPair>>::dump() const { +amqp::internal::reader:: +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedPair>>::dump() const { +amqp::internal::reader:: +TypedPair>>::dump() const { return ::dumpPair (m_property, m_value.begin(), m_value.end()); } @@ -111,25 +125,29 @@ amqp::TypedPair>>::dump() const { template<> std::string -amqp::TypedSingle>>::dump() const { +amqp::internal::reader:: +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedSingle>>::dump() const { +amqp::internal::reader:: +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedSingle>>::dump() const { +amqp::internal::reader:: +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } template<> std::string -amqp::TypedSingle>>::dump() const { +amqp::internal::reader:: +TypedSingle>>::dump() const { return ::dumpSingle (m_value.begin(), m_value.end()); } diff --git a/experimental/cpp-serializer/src/amqp/consumer/Reader.h b/experimental/cpp-serializer/src/amqp/reader/Reader.h similarity index 57% rename from experimental/cpp-serializer/src/amqp/consumer/Reader.h rename to experimental/cpp-serializer/src/amqp/reader/Reader.h index 9cd12e432d..56244e5e17 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/Reader.h +++ b/experimental/cpp-serializer/src/amqp/reader/Reader.h @@ -8,26 +8,25 @@ #include #include -#include "schema/Schema.h" +#include "amqp/schema/Schema.h" +#include "amqp/reader/IReader.h" /******************************************************************************/ -struct pn_data_t; +namespace amqp::internal::reader { -/******************************************************************************/ - -namespace amqp { - - class Value { + class Value : public amqp::reader::IValue { public : - virtual std::string dump() const = 0; + std::string dump() const override = 0; - virtual ~Value() = default; + ~Value() override = default; }; class Single : public Value { public : std::string dump() const override = 0; + + ~Single() override = default; }; template @@ -46,7 +45,7 @@ namespace amqp { , m_value { std::move (value_) } { } - TypedSingle (const TypedSingle && value_) noexcept + explicit TypedSingle (const TypedSingle && value_) noexcept : Single() , m_value { std::move (value_.m_value) } { } @@ -63,13 +62,13 @@ namespace amqp { std::string m_property; public: - explicit Pair(const std::string & property_) - : m_property (property_) + explicit Pair (std::string property_) + : m_property (std::move (property_)) { } - virtual ~Pair() = default; + ~Pair() override = default; - Pair (amqp::Pair && pair_) noexcept + Pair (Pair && pair_) noexcept : m_property (std::move (pair_.m_property)) { } @@ -94,7 +93,7 @@ namespace amqp { , m_value (std::move (value_)) { } - TypedPair (TypedPair && pair_) + explicit TypedPair (TypedPair && pair_) noexcept : Pair (std::move (pair_.m_property)) , m_value (std::move (pair_.m_value)) { } @@ -110,72 +109,84 @@ namespace amqp { /****************************************************************************** * - * amqp::TypeSingle + * amqp::internal::reader::TypedSingle * ******************************************************************************/ template inline std::string -amqp::TypedSingle::dump() const { +amqp::internal::reader:: +TypedSingle::dump() const { return std::to_string(m_value); } template<> inline std::string -amqp::TypedSingle::dump() const { +amqp::internal::reader:: +TypedSingle::dump() const { return m_value; } template<> std::string -amqp::TypedSingle>>::dump() const; +amqp::internal::reader:: +TypedSingle>>::dump() const; template<> std::string -amqp::TypedSingle>>::dump() const; +amqp::internal::reader:: +TypedSingle>>::dump() const; template<> std::string -amqp::TypedSingle>>::dump() const; +amqp::internal::reader:: +TypedSingle>>::dump() const; template<> std::string -amqp::TypedSingle>>::dump() const; +amqp::internal::reader:: +TypedSingle>>::dump() const; /****************************************************************************** * - * amqp::TypedPair + * amqp::interanel::reader::TypedPair * ******************************************************************************/ template inline std::string -amqp::TypedPair::dump() const { +amqp::internal::reader:: +TypedPair::dump() const { return m_property + " : " + std::to_string (m_value); } template<> inline std::string -amqp::TypedPair::dump() const { +amqp::internal::reader:: +TypedPair::dump() const { return m_property + " : " + m_value; } template<> std::string -amqp::TypedPair>>::dump() const; +amqp::internal::reader:: +TypedPair>>::dump() const; template<> std::string -amqp::TypedPair>>::dump() const; +amqp::internal::reader:: +TypedPair>>::dump() const; template<> std::string -amqp::TypedPair>>::dump() const; +amqp::internal::reader:: +TypedPair>>::dump() const; template<> std::string -amqp::TypedPair>>::dump() const; +amqp::internal::reader:: +TypedPair>>::dump() const; /****************************************************************************** * @@ -184,25 +195,28 @@ amqp::TypedPair>>::dump() const; * ******************************************************************************/ -namespace amqp { +namespace amqp::internal::reader { - class Reader { + using IReader = amqp::reader::IReader; + + class Reader : public IReader { public : - virtual ~Reader() = default; - virtual const std::string & name() const = 0; - virtual const std::string & type() const = 0; + ~Reader() override = default; - virtual std::any read(pn_data_t *) const = 0; - virtual std::string readString(pn_data_t *) const = 0; + const std::string & name() const override = 0; + const std::string & type() const override = 0; - virtual std::unique_ptr dump( + std::any read (struct pn_data_t *) const override = 0; + std::string readString (struct pn_data_t *) const override = 0; + + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr &) const = 0; + const SchemaType &) const override = 0; - virtual std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr &) const = 0; + const SchemaType &) const override = 0; }; } diff --git a/experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.cxx b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx similarity index 69% rename from experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.cxx rename to experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx index 94fe3a238d..b2137453f5 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.cxx @@ -4,23 +4,28 @@ #include "proton/proton_wrapper.h" +#include "amqp/reader/IReader.h" +#include "amqp/reader/Reader.h" + /******************************************************************************/ -amqp:: +amqp::internal::reader:: RestrictedReader::RestrictedReader (std::string type_) : m_type (std::move (type_)) { } /******************************************************************************/ -const std::string amqp::RestrictedReader::m_name { // NOLINT +const std::string +amqp::internal::reader:: +RestrictedReader::m_name { // NOLINT "Restricted Reader" }; /******************************************************************************/ std::any -amqp:: +amqp::internal::reader:: RestrictedReader::read(pn_data_t *) const { return std::any(1); } @@ -28,32 +33,32 @@ RestrictedReader::read(pn_data_t *) const { /******************************************************************************/ std::string -amqp:: +amqp::internal::reader:: RestrictedReader::readString(pn_data_t * data_) const { return "hello"; } /******************************************************************************/ -std::list> -amqp:: +std::list> +amqp::internal::reader:: ListReader::dump_( pn_data_t * data_, - const std::unique_ptr & schema_ + const SchemaType & schema_ ) const { proton::is_described (data_); - std::list> read; + std::list> read; { proton::auto_enter ae (data_); - auto it = schema_->fromDescriptor(proton::readAndNext(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_)); + read.emplace_back (m_reader.lock()->dump (data_, schema_)); } } } @@ -63,38 +68,38 @@ ListReader::dump_( /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: ListReader::dump ( const std::string & name_, pn_data_t * data_, - const std::unique_ptr & schema_ + const SchemaType & schema_ ) const { proton::auto_next an (data_); - return std::make_unique>>>( + return std::make_unique>>>( name_, dump_ (data_, schema_)); } /******************************************************************************/ -std::unique_ptr -amqp:: +std::unique_ptr +amqp::internal::reader:: ListReader::dump( pn_data_t * data_, - const std::unique_ptr & schema_ + const SchemaType & schema_ ) const { proton::auto_next an (data_); - return std::make_unique>>>( + return std::make_unique>>>( dump_ (data_, schema_)); } /******************************************************************************/ const std::string & -amqp:: +amqp::internal::reader:: RestrictedReader::name() const { return m_name; } @@ -102,7 +107,7 @@ RestrictedReader::name() const { /******************************************************************************/ const std::string & -amqp:: +amqp::internal::reader:: RestrictedReader::type() const { return m_type; } @@ -114,7 +119,7 @@ RestrictedReader::type() const { ******************************************************************************/ amqp::internal::schema::Restricted::RestrictedTypes -amqp:: +amqp::internal::reader:: ListReader::restrictedType() const { return internal::schema::Restricted::RestrictedTypes::List; } diff --git a/experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.h b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h similarity index 68% rename from experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.h rename to experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h index 247eb279bb..0c1db3ae6b 100644 --- a/experimental/cpp-serializer/src/amqp/consumer/RestrictedReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h @@ -15,7 +15,7 @@ struct pn_data_t; /******************************************************************************/ -namespace amqp { +namespace amqp::internal::reader { class RestrictedReader : public Reader { private : @@ -23,17 +23,17 @@ namespace amqp { const std::string m_type; public : - RestrictedReader (std::string); + explicit RestrictedReader (std::string); ~RestrictedReader() override = default; std::any read(pn_data_t *) const override ; std::string readString(pn_data_t *) const override; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr &) const override = 0; + const SchemaType &) const override = 0; const std::string & name() const override; const std::string & type() const override; @@ -43,37 +43,37 @@ namespace amqp { /******************************************************************************/ -namespace amqp { +namespace amqp::internal::reader { class ListReader : public RestrictedReader { private : // How to read the underlying types - std::weak_ptr m_reader; + std::weak_ptr m_reader; - std::list> dump_( + std::list> dump_( pn_data_t *, - const std::unique_ptr &) const; + const SchemaType &) const; public : ListReader ( const std::string & type_, - std::weak_ptr reader_ + std::weak_ptr reader_ ) : RestrictedReader (type_) - , m_reader (reader_) + , m_reader (std::move (reader_)) { } ~ListReader() final = default; internal::schema::Restricted::RestrictedTypes restrictedType() const; - std::unique_ptr dump( + std::unique_ptr dump( const std::string &, pn_data_t *, - const std::unique_ptr &) const override; + const SchemaType &) const override; - std::unique_ptr dump( + std::unique_ptr dump( pn_data_t *, - const std::unique_ptr &) const override; + const SchemaType &) const override; }; } diff --git a/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h b/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h index ebf8ca6e0b..da9ebd11d3 100644 --- a/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h +++ b/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h @@ -5,8 +5,6 @@ #include #include -/******************************************************************************/ - #include "Descriptor.h" #include "OrderedTypeNotations.h" @@ -31,7 +29,9 @@ namespace amqp::internal::schema { namespace amqp::internal::schema { - class AMQPTypeNotation : public AMQPDescribed, public OrderedTypeNotation { + class AMQPTypeNotation + : public AMQPDescribed, public OrderedTypeNotation + { public : friend std::ostream & operator << (std::ostream &, const AMQPTypeNotation &); diff --git a/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx b/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx index acb0dc72b5..e3ef5fd604 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Envelope.cxx @@ -2,6 +2,9 @@ #include +#include "amqp/schema/Schema.h" +#include "amqp/schema/ISchema.h" + /******************************************************************************/ namespace amqp::internal::schema { @@ -33,10 +36,10 @@ Envelope::Envelope ( /******************************************************************************/ -const std::unique_ptr & +const amqp::internal::schema::ISchemaType & amqp::internal::schema:: Envelope::schema() const { - return m_schema; + return *m_schema; } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/Envelope.h b/experimental/cpp-serializer/src/amqp/schema/Envelope.h index d8a3cf3b67..ede8018f84 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Envelope.h +++ b/experimental/cpp-serializer/src/amqp/schema/Envelope.h @@ -27,7 +27,7 @@ namespace amqp::internal::schema { std::unique_ptr & schema_, std::string descriptor_); - const std::unique_ptr & schema() const; + const ISchemaType & schema() const; const std::string & descriptor() const; }; diff --git a/experimental/cpp-serializer/src/amqp/schema/Schema.cxx b/experimental/cpp-serializer/src/amqp/schema/Schema.cxx index e82e7abd31..987e272f6f 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Schema.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Schema.cxx @@ -1,5 +1,9 @@ +#include "amqp/AMQPDescribed.h" +#include "amqp/schema/ISchema.h" +#include "amqp/schema/AMQPTypeNotation.h" #include "Schema.h" +#include "types.h" #include "debug.h" @@ -36,13 +40,13 @@ operator << (std::ostream & stream_, const Schema & schema_) { amqp::internal::schema:: Schema::Schema ( - OrderedTypeNotations types_ + OrderedTypeNotations types_ ) : m_types (std::move (types_)) { for (auto i { m_types.begin() } ; i != m_types.end() ; ++i) { for (auto & j : *i) { DBG ("Schema: " << j->descriptor() << " " << j->name() << std::endl); // NOLINT - m_descriptorToType.emplace(j->descriptor(), std::ref (j)); - m_typeToDescriptor.emplace(j->name(), std::ref (j)); + m_descriptorToType.emplace (j->descriptor(), std::ref (j)); + m_typeToDescriptor.emplace (j->name(), std::ref (j)); } } } @@ -57,7 +61,7 @@ Schema::types() const { /******************************************************************************/ -amqp::internal::schema::Schema::SchemaMap::const_iterator +amqp::internal::schema::SchemaMap::const_iterator amqp::internal::schema:: Schema::fromType (const std::string & type_) const { return m_typeToDescriptor.find(type_); @@ -65,7 +69,7 @@ Schema::fromType (const std::string & type_) const { /******************************************************************************/ -amqp::internal::schema::Schema::SchemaMap::const_iterator +amqp::internal::schema::SchemaMap::const_iterator amqp::internal::schema:: Schema::fromDescriptor (const std::string & descriptor_) const { return m_descriptorToType.find (descriptor_); diff --git a/experimental/cpp-serializer/src/amqp/schema/Schema.h b/experimental/cpp-serializer/src/amqp/schema/Schema.h index c1dbb43dc4..84bb7013df 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Schema.h +++ b/experimental/cpp-serializer/src/amqp/schema/Schema.h @@ -12,49 +12,38 @@ #include "OrderedTypeNotations.h" #include "amqp/AMQPDescribed.h" +#include "amqp/schema/ISchema.h" /******************************************************************************/ namespace amqp::internal::schema { - typedef std::function &, const uPtr &)> const SetSort; + using SchemaMap = std::map>>; + using ISchemaType = amqp::schema::ISchema; -} - -/******************************************************************************/ - -namespace amqp::internal::schema { - - -} - -/******************************************************************************/ - -namespace amqp::internal::schema { - - /* - */ - class Schema : public AMQPDescribed { + class Schema + : public amqp::schema::ISchema + , public amqp::AMQPDescribed + { public : friend std::ostream & operator << (std::ostream &, const Schema &); - typedef std::map>> SchemaMap; - private : OrderedTypeNotations m_types; + SchemaMap m_descriptorToType; SchemaMap m_typeToDescriptor; public : - Schema (OrderedTypeNotations types_); + explicit Schema (OrderedTypeNotations types_); const OrderedTypeNotations & types() const; - SchemaMap::const_iterator fromType (const std::string &) const; - SchemaMap::const_iterator fromDescriptor (const std::string &) const; + SchemaMap::const_iterator fromType (const std::string &) const override; + SchemaMap::const_iterator fromDescriptor (const std::string &) const override ; - decltype(m_types.begin()) begin() const { return m_types.begin(); } - decltype(m_types.end()) end() const { return m_types.end(); } + decltype (m_types.begin()) begin() const { return m_types.begin(); } + decltype (m_types.end()) end() const { return m_types.end(); } }; } diff --git a/experimental/cpp-serializer/src/amqp/test/Pair.cxx b/experimental/cpp-serializer/src/amqp/test/Pair.cxx index 6675b84765..a0a4a13291 100644 --- a/experimental/cpp-serializer/src/amqp/test/Pair.cxx +++ b/experimental/cpp-serializer/src/amqp/test/Pair.cxx @@ -6,8 +6,13 @@ /******************************************************************************/ +using namespace amqp::reader; +using namespace amqp::internal::reader; + +/******************************************************************************/ + TEST (Pair, string) { // NOLINT - amqp::TypedPair str_test ("Left", "Hello"); + TypedPair str_test ("Left", "Hello"); EXPECT_EQ("Left : Hello", str_test.dump()); } @@ -15,7 +20,7 @@ TEST (Pair, string) { // NOLINT /******************************************************************************/ TEST (Pair, int) { // NOLINT - amqp::TypedPair int_test ("Left", 101); + TypedPair int_test ("Left", 101); EXPECT_EQ("Left : 101", int_test.dump()); } @@ -23,8 +28,8 @@ TEST (Pair, int) { // NOLINT /******************************************************************************/ TEST (Pair, UP1) { // NOLINT - std::unique_ptr> test = - std::make_unique> ("property", 10.0); + std::unique_ptr> test = + std::make_unique> ("property", 10.0); EXPECT_EQ("property : 10.000000", test->dump()); } @@ -33,20 +38,20 @@ TEST (Pair, UP1) { // NOLINT TEST (Pair, UP2) { // NOLINT struct builder { - static std::unique_ptr + static std::unique_ptr build (const std::string & prop_, int val_) { - return std::make_unique> (prop_, val_); + return std::make_unique> (prop_, val_); } }; - std::vector> vec; + std::vector> vec; vec.reserve(2); vec.emplace_back (builder::build ("first", 1)); vec.emplace_back (builder::build ("second", 2)); - std::unique_ptr test = - std::make_unique>>> ( + std::unique_ptr test = + std::make_unique>>> ( "Vector", std::move (vec)); EXPECT_EQ("Vector : { first : 1, second : 2 }", test->dump()); diff --git a/experimental/cpp-serializer/src/amqp/test/Single.cxx b/experimental/cpp-serializer/src/amqp/test/Single.cxx index f8c074d5ca..728688eeaa 100644 --- a/experimental/cpp-serializer/src/amqp/test/Single.cxx +++ b/experimental/cpp-serializer/src/amqp/test/Single.cxx @@ -4,8 +4,11 @@ #include "Reader.h" +using namespace amqp::reader; +using namespace amqp::internal::reader; + TEST (Single, string) { // NOLINT - amqp::TypedSingle str_test ("Hello"); + TypedSingle str_test ("Hello"); EXPECT_EQ("Hello", str_test.dump()); } @@ -13,13 +16,13 @@ TEST (Single, string) { // NOLINT TEST (Single, list) { // NOLINT struct builder { - static std::unique_ptr + static std::unique_ptr build (int val_) { - return std::make_unique> (val_); + return std::make_unique> (val_); } }; - std::list> list; + std::list> list; list.emplace_back (builder::build (1)); list.emplace_back (builder::build (2)); @@ -27,8 +30,8 @@ TEST (Single, list) { // NOLINT list.emplace_back (builder::build (4)); list.emplace_back (builder::build (5)); - std::unique_ptr test = - std::make_unique>>> ( + std::unique_ptr test = + std::make_unique>>> ( std::move (list)); EXPECT_EQ("[ 1, 2, 3, 4, 5 ]", test->dump()); diff --git a/experimental/cpp-serializer/src/proton/proton_wrapper.cxx b/experimental/cpp-serializer/src/proton/proton_wrapper.cxx index 4595e6d1d5..78db003209 100644 --- a/experimental/cpp-serializer/src/proton/proton_wrapper.cxx +++ b/experimental/cpp-serializer/src/proton/proton_wrapper.cxx @@ -273,7 +273,9 @@ readAndNext ( } else if (tolerateDeviance_ && pn_data_type(data_) == PN_NULL) { return ""; } - throw std::runtime_error ("Expected a String"); + std::stringstream ss; + ss << "Expected a String but found [" << data_ << "]"; + throw std::runtime_error (ss.str()); } /******************************************************************************/