NOTICK - Fix namespace allocation for C++ Serialiser

Now things are working for the most part, move the readers into their
own internal namespace. Also start creating an actual separation of the
interface and the implementation with some Interface classes at the
non internal level.
This commit is contained in:
Katelyn Baker 2019-08-19 20:10:57 +01:00
parent 101d978050
commit eb8eaba1d7
27 changed files with 527 additions and 365 deletions

View File

@ -1,32 +0,0 @@
#pragma once
/******************************************************************************/
#include <map>
#include <set>
#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<amqp::internal::schema::Schema>;
ICompositeFactory() = default;
virtual ~ICompositeFactory() = default;
virtual void process (const SchemaPtr &) = 0;
virtual const std::shared_ptr<amqp::Reader> byType (const std::string &) = 0;
virtual const std::shared_ptr<amqp::Reader> byDescriptor (const std::string &) = 0;
};
/******************************************************************************/

View File

@ -2,7 +2,7 @@
/******************************************************************************/
namespace amqp::internal {
namespace amqp {
class AMQPDescribed {
public :

View File

@ -0,0 +1,33 @@
#pragma once
/******************************************************************************/
#include "types.h"
#include "amqp/schema/ISchema.h"
#include "amqp/reader/IReader.h"
/******************************************************************************/
namespace amqp {
template <class SchemaIterator>
class ICompositeFactory {
public :
using SchemaType = schema::ISchema<SchemaIterator>;
using ReaderType = reader::IReader<SchemaIterator>;
ICompositeFactory() = default;
virtual ~ICompositeFactory() = default;
virtual void process (const SchemaType &) = 0;
virtual const std::shared_ptr<ReaderType> byType (const std::string &) = 0;
virtual const std::shared_ptr<ReaderType> byDescriptor (const std::string &) = 0;
};
}
/******************************************************************************/

View File

@ -0,0 +1,75 @@
#pragma once
/******************************************************************************/
#include <any>
#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 SchemaIterator>
class IReader {
public :
using SchemaType = amqp::schema::ISchema<SchemaIterator>;
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<IValue> dump(
const std::string &,
pn_data_t *,
const SchemaType &) const = 0;
virtual std::unique_ptr<IValue> dump(
pn_data_t *,
const SchemaType &) const = 0;
};
}
/******************************************************************************/

View File

@ -0,0 +1,16 @@
#pragma once
#include "types.h"
#include "amqp/AMQPDescribed.h"
namespace amqp::schema {
template <class Iterator>
class ISchema {
public :
virtual Iterator fromType (const std::string &) const = 0;
virtual Iterator fromDescriptor (const std::string &) const = 0;
};
}

View File

@ -6,7 +6,7 @@
#include <string>
#include <iostream>
#include "AMQPDescribed.h"
#include "amqp/AMQPDescribed.h"
/******************************************************************************
*

View File

@ -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
)

View File

@ -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<const schema::Schema &>(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<amqp::Reader>
std::shared_ptr<amqp::internal::reader::Reader>
amqp::internal::
CompositeFactory::process(
const amqp::internal::schema::AMQPTypeNotation & schema_)
{
return computeIfAbsent<amqp::Reader> (
return computeIfAbsent<reader::Reader> (
m_readersByType,
schema_.name(),
[& schema_, this] () -> std::shared_ptr<amqp::Reader> {
[& schema_, this] () -> std::shared_ptr<reader::Reader> {
switch (schema_.type()) {
case amqp::internal::schema::AMQPTypeNotation::Composite : {
return processComposite(schema_);
@ -106,12 +107,12 @@ CompositeFactory::process(
/******************************************************************************/
std::shared_ptr<amqp::Reader>
std::shared_ptr<amqp::internal::reader::Reader>
amqp::internal::
CompositeFactory::processComposite (
const amqp::internal::schema::AMQPTypeNotation & type_)
{
std::vector<std::weak_ptr<amqp::Reader>> readers;
std::vector<std::weak_ptr<reader::Reader>> readers;
const auto & fields = dynamic_cast<const amqp::internal::schema::Composite &> (
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<amqp::Reader>(
case schema::FieldType::PrimitiveProperty : {
auto reader = computeIfAbsent<reader::Reader>(
m_readersByType,
field->type(),
[&field]() -> std::shared_ptr<amqp::PropertyReader> {
return amqp::PropertyReader::make(field);
[&field]() -> std::shared_ptr<reader::PropertyReader> {
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<amqp::CompositeReader> (type_.name(), readers);
return std::make_shared<reader::CompositeReader> (type_.name(), readers);
}
/******************************************************************************/
std::shared_ptr<amqp::Reader>
std::shared_ptr<amqp::internal::reader::Reader>
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<amqp::Reader> (
auto reader = computeIfAbsent<reader::Reader> (
m_readersByType,
list.listOf(),
[& list] () -> std::shared_ptr<amqp::PropertyReader> {
return amqp::PropertyReader::make (list.listOf());
[& list] () -> std::shared_ptr<reader::PropertyReader> {
return reader::PropertyReader::make (list.listOf());
});
return std::make_shared<amqp::ListReader> (type_.name(), reader);
return std::make_shared<reader::ListReader> (type_.name(), reader);
} else {
DBG (" List of Composite - " << list.listOf() << std::endl); // NOLINT
auto reader = m_readersByType[list.listOf()];
return std::make_shared<amqp::ListReader> (list.name(), reader);
return std::make_shared<reader::ListReader> (list.name(), reader);
}
}
@ -201,7 +202,7 @@ CompositeFactory::processRestricted (
/******************************************************************************/
const std::shared_ptr<amqp::Reader>
const std::shared_ptr<amqp::internal::reader::IReader>
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<amqp::Reader>
const std::shared_ptr<amqp::internal::reader::IReader>
amqp::internal::
CompositeFactory::byDescriptor (const std::string & descriptor_) {
auto it = m_readersByDescriptor.find (descriptor_);

View File

@ -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<schema::SchemaMap::const_iterator> {
private :
using CompositePtr = uPtr<amqp::internal::schema::Composite>;
using EnvelopePtr = uPtr<amqp::internal::schema::Envelope>;
@ -26,25 +26,25 @@ namespace amqp::internal {
/**
*
*/
spStrMap_t<amqp::Reader> m_readersByType;
spStrMap_t<amqp::Reader> m_readersByDescriptor;
spStrMap_t<reader::Reader> m_readersByType;
spStrMap_t<reader::Reader> m_readersByDescriptor;
public :
CompositeFactory() = default;
void process(const SchemaPtr &) override ;
void process(const SchemaType &) override;
virtual const std::shared_ptr<amqp::Reader> byType(const std::string &) override;
const std::shared_ptr<ReaderType> byType(const std::string &) override;
virtual const std::shared_ptr<amqp::Reader> byDescriptor(const std::string &) override;
const std::shared_ptr<ReaderType> byDescriptor(const std::string &) override;
private :
std::shared_ptr<amqp::Reader> process(const amqp::internal::schema::AMQPTypeNotation &);
std::shared_ptr<reader::Reader> process(const amqp::internal::schema::AMQPTypeNotation &);
std::shared_ptr<amqp::Reader>
std::shared_ptr<reader::Reader>
processComposite(const amqp::internal::schema::AMQPTypeNotation &);
std::shared_ptr<amqp::Reader>
std::shared_ptr<reader::Reader>
processRestricted(const amqp::internal::schema::AMQPTypeNotation &);
};

View File

@ -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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
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<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
amqp::internal::
ChoiceDescriptor::build(pn_data_t * data_) const {
validateAndNext(data_);
DBG ("CHOICE " << data_ << std::endl); // NOLINT
return std::unique_ptr<amqp::internal::AMQPDescribed> (nullptr);
return std::unique_ptr<amqp::AMQPDescribed> (nullptr);
}
/******************************************************************************/
std::unique_ptr<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
amqp::internal::
ReferencedObjectDescriptor::build(pn_data_t * data_) const {
validateAndNext(data_);
DBG ("REFERENCED OBJECT " << data_ << std::endl); // NOLINT
return std::unique_ptr<amqp::internal::AMQPDescribed> (nullptr);
return std::unique_ptr<amqp::AMQPDescribed> (nullptr);
}
/******************************************************************************/
std::unique_ptr<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
amqp::internal::
TransformSchemaDescriptor::build(pn_data_t * data_) const {
validateAndNext(data_);
DBG ("TRANSFORM SCHEMA " << data_ << std::endl); // NOLINT
return std::unique_ptr<amqp::internal::AMQPDescribed> (nullptr);
return std::unique_ptr<amqp::AMQPDescribed> (nullptr);
}
/******************************************************************************/
std::unique_ptr<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
amqp::internal::
TransformElementDescriptor::build(pn_data_t * data_) const {
validateAndNext(data_);
DBG ("TRANSFORM ELEMENT " << data_ << std::endl); // NOLINT
return std::unique_ptr<amqp::internal::AMQPDescribed> (nullptr);
return std::unique_ptr<amqp::AMQPDescribed> (nullptr);
}
/******************************************************************************/
std::unique_ptr<amqp::internal::AMQPDescribed>
std::unique_ptr<amqp::AMQPDescribed>
amqp::internal::
TransformElementKeyDescriptor::build(pn_data_t * data_) const {
validateAndNext(data_);
DBG ("TRANSFORM ELEMENT KEY" << data_ << std::endl); // NOLINT
return std::unique_ptr<amqp::internal::AMQPDescribed> (nullptr);
return std::unique_ptr<amqp::AMQPDescribed> (nullptr);
}
/******************************************************************************/

View File

@ -18,7 +18,7 @@ struct pn_data_t;
/******************************************************************************/
namespace amqp:: internal {
namespace amqp::internal {
class EnvelopeDescriptor : public AMQPDescriptor {
public :

View File

@ -7,11 +7,15 @@
#include <proton/codec.h>
#include <sstream>
#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<std::weak_ptr<amqp::Reader>> & readers_
std::vector<std::weak_ptr<Reader>> & 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<std::unique_ptr<amqp::Value>>
amqp::
std::vector<std::unique_ptr<amqp::reader::IValue>>
amqp::internal::reader::
CompositeReader::_dump (
pn_data_t * data_,
const std::unique_ptr<amqp::internal::schema::Schema> & 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<std::string>(data_));
const auto & it = schema_.fromDescriptor(proton::get_symbol<std::string>(data_));
auto & fields = dynamic_cast<amqp::internal::schema::Composite &>(*(it->second.get())).fields();
assert (fields.size() == m_readers.size());
pn_data_next (data_);
std::vector<std::unique_ptr<amqp::Value>> read;
std::vector<std::unique_ptr<amqp::reader::IValue>> read;
read.reserve (fields.size());
proton::is_list (data_);
@ -116,15 +120,14 @@ CompositeReader::_dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
CompositeReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<amqp::TypedPair<std::vector<std::unique_ptr<amqp::Value>>>> (
return std::make_unique<TypedPair<std::vector<std::unique_ptr<amqp::reader::IValue>>>> (
name_,
_dump(data_, schema_));
}
@ -134,14 +137,13 @@ CompositeReader::dump (
/**
*
*/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
CompositeReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<amqp::TypedSingle<std::vector<std::unique_ptr<amqp::Value>>>> (
return std::make_unique<TypedSingle<std::vector<std::unique_ptr<amqp::reader::IValue>>>> (
_dump (data_, schema_));
}

View File

@ -7,27 +7,24 @@
#include <any>
#include <vector>
#include <iostream>
#include <amqp/schema/Schema.h>
/******************************************************************************/
namespace amqp {
namespace amqp::internal::reader {
class CompositeReader : public Reader {
private :
std::vector<std::weak_ptr<amqp::Reader>> m_readers;
std::vector<std::weak_ptr<Reader>> m_readers;
static const std::string m_name;
std::string m_type;
std::vector<std::unique_ptr<amqp::Value>> _dump (
pn_data_t * data_,
const std::unique_ptr<amqp::internal::schema::Schema> & schema_) const;
public :
CompositeReader (
std::string type_,
std::vector<std::weak_ptr<amqp::Reader>> & readers_
std::vector<std::weak_ptr<Reader>> & readers_
);
~CompositeReader() override = default;
@ -36,17 +33,22 @@ namespace amqp {
std::string readString(pn_data_t *) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const override;
const SchemaType &) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const override;
const SchemaType &) const override;
const std::string & name() const override;
const std::string & type() const override;
private :
std::vector<std::unique_ptr<amqp::reader::IValue>> _dump (
pn_data_t * data_,
const SchemaType & schema_) const;
};
}

View File

@ -13,34 +13,37 @@
namespace {
std::map<std::string, std::shared_ptr<amqp::PropertyReader>(*)() > propertyMap = {
std::map<
std::string,
std::shared_ptr<amqp::internal::reader::PropertyReader>(*)()
> propertyMap = { // NOLINT
{
"int", []() -> std::shared_ptr<amqp::PropertyReader> {
return std::make_shared<amqp::IntPropertyReader> ();
"int", []() -> std::shared_ptr<amqp::internal::reader::PropertyReader> {
return std::make_shared<amqp::internal::reader::IntPropertyReader> ();
}
},
{
"string", []() -> std::shared_ptr<amqp::PropertyReader> {
return std::make_shared<amqp::StringPropertyReader> (
amqp::StringPropertyReader());
"string", []() -> std::shared_ptr<amqp::internal::reader::PropertyReader> {
return std::make_shared<amqp::internal::reader::StringPropertyReader> (
amqp::internal::reader::StringPropertyReader());
}
},
{
"boolean", []() -> std::shared_ptr<amqp::PropertyReader> {
return std::make_shared<amqp::BoolPropertyReader> (
amqp::BoolPropertyReader());
"boolean", []() -> std::shared_ptr<amqp::internal::reader::PropertyReader> {
return std::make_shared<amqp::internal::reader::BoolPropertyReader> (
amqp::internal::reader::BoolPropertyReader());
}
},
{
"long", []() -> std::shared_ptr<amqp::PropertyReader> {
return std::make_shared<amqp::LongPropertyReader> (
amqp::LongPropertyReader());
"long", []() -> std::shared_ptr<amqp::internal::reader::PropertyReader> {
return std::make_shared<amqp::internal::reader::LongPropertyReader> (
amqp::internal::reader::LongPropertyReader());
}
},
{
"double", []() -> std::shared_ptr<amqp::PropertyReader> {
return std::make_shared<amqp::DoublePropertyReader> (
amqp::DoublePropertyReader());
"double", []() -> std::shared_ptr<amqp::internal::reader::PropertyReader> {
return std::make_shared<amqp::internal::reader::DoublePropertyReader> (
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::PropertyReader>
amqp::
std::shared_ptr<amqp::internal::reader::PropertyReader>
amqp::internal::reader::
PropertyReader::make (const FieldPtr & field_) {
return propertyMap[field_->type()]();
}
/******************************************************************************/
std::shared_ptr<amqp::PropertyReader>
amqp::
std::shared_ptr<amqp::internal::reader::PropertyReader>
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<std::string> (data_);
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
StringPropertyReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedPair<std::string>> (
name_,
@ -145,11 +167,11 @@ StringPropertyReader::dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
StringPropertyReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedSingle<std::string>> (
"\"" + proton::readAndNext<std::string> (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<int> (data_));
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
IntPropertyReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedPair<std::string>> (
name_,
@ -191,11 +213,11 @@ IntPropertyReader::dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
IntPropertyReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedSingle<std::string>> (
std::to_string (proton::readAndNext<int> (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<bool> (data_));
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
BoolPropertyReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedPair<std::string>> (
name_,
@ -237,11 +259,11 @@ BoolPropertyReader::dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
BoolPropertyReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedSingle<std::string>> (
std::to_string (proton::readAndNext<bool> (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<long> (data_));
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
LongPropertyReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedPair<std::string>> (
name_,
@ -283,11 +305,11 @@ LongPropertyReader::dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
LongPropertyReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedSingle<std::string>> (
std::to_string (proton::readAndNext<long> (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<double> (data_));
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
DoublePropertyReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const std::string & name_,
pn_data_t * data_,
const SchemaType & schema_) const
{
return std::make_unique<TypedPair<std::string>> (
name_,
@ -329,11 +351,11 @@ DoublePropertyReader::dump (
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
DoublePropertyReader::dump (
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_) const
const SchemaType & schema_) const
{
return std::make_unique<TypedSingle<std::string>> (
std::to_string (proton::readAndNext<double> (data_)));

View File

@ -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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override = 0;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &
const SchemaType &
) const override;
const std::string & name() const override {

View File

@ -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<std::vector<std::unique_ptr<amqp::Pair>>>::dump() const {
amqp::internal::reader::
TypedPair<std::vector<std::unique_ptr<amqp::internal::reader::Pair>>>::dump() const {
return ::dumpPair<AutoMap> (m_property, m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedPair<std::list<std::unique_ptr<amqp::Pair>>>::dump() const {
amqp::internal::reader::
TypedPair<std::list<std::unique_ptr<amqp::internal::reader::Pair>>>::dump() const {
return ::dumpPair<AutoMap> (m_property, m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedPair<std::vector<std::unique_ptr<amqp::Value>>>::dump() const {
amqp::internal::reader::
TypedPair<std::vector<std::unique_ptr<amqp::reader::IValue>>>::dump() const {
return ::dumpPair<AutoMap> (m_property, m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedPair<std::list<std::unique_ptr<amqp::Value>>>::dump() const {
amqp::internal::reader::
TypedPair<std::list<std::unique_ptr<amqp::reader::IValue>>>::dump() const {
return ::dumpPair<AutoList> (m_property, m_value.begin(), m_value.end());
}
@ -111,25 +125,29 @@ amqp::TypedPair<std::list<std::unique_ptr<amqp::Value>>>::dump() const {
template<>
std::string
amqp::TypedSingle<std::list<std::unique_ptr<amqp::Value>>>::dump() const {
amqp::internal::reader::
TypedSingle<std::list<std::unique_ptr<amqp::reader::IValue>>>::dump() const {
return ::dumpSingle<AutoList> (m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedSingle<std::vector<std::unique_ptr<amqp::Value>>>::dump() const {
amqp::internal::reader::
TypedSingle<std::vector<std::unique_ptr<amqp::reader::IValue>>>::dump() const {
return ::dumpSingle<AutoMap> (m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedSingle<std::list<std::unique_ptr<amqp::Single>>>::dump() const {
amqp::internal::reader::
TypedSingle<std::list<std::unique_ptr<amqp::internal::reader::Single>>>::dump() const {
return ::dumpSingle<AutoList> (m_value.begin(), m_value.end());
}
template<>
std::string
amqp::TypedSingle<std::vector<std::unique_ptr<amqp::Single>>>::dump() const {
amqp::internal::reader::
TypedSingle<std::vector<std::unique_ptr<amqp::internal::reader::Single>>>::dump() const {
return ::dumpSingle<AutoMap> (m_value.begin(), m_value.end());
}

View File

@ -8,26 +8,25 @@
#include <vector>
#include <memory>
#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<typename T>
@ -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<typename T>
inline std::string
amqp::TypedSingle<T>::dump() const {
amqp::internal::reader::
TypedSingle<T>::dump() const {
return std::to_string(m_value);
}
template<>
inline std::string
amqp::TypedSingle<std::string>::dump() const {
amqp::internal::reader::
TypedSingle<std::string>::dump() const {
return m_value;
}
template<>
std::string
amqp::TypedSingle<std::vector<std::unique_ptr<amqp::Value>>>::dump() const;
amqp::internal::reader::
TypedSingle<std::vector<std::unique_ptr<amqp::reader::IValue>>>::dump() const;
template<>
std::string
amqp::TypedSingle<std::list<std::unique_ptr<amqp::Value>>>::dump() const;
amqp::internal::reader::
TypedSingle<std::list<std::unique_ptr<amqp::reader::IValue>>>::dump() const;
template<>
std::string
amqp::TypedSingle<std::vector<std::unique_ptr<amqp::Single>>>::dump() const;
amqp::internal::reader::
TypedSingle<std::vector<std::unique_ptr<amqp::internal::reader::Single>>>::dump() const;
template<>
std::string
amqp::TypedSingle<std::list<std::unique_ptr<amqp::Single>>>::dump() const;
amqp::internal::reader::
TypedSingle<std::list<std::unique_ptr<amqp::internal::reader::Single>>>::dump() const;
/******************************************************************************
*
* amqp::TypedPair
* amqp::interanel::reader::TypedPair
*
******************************************************************************/
template<typename T>
inline std::string
amqp::TypedPair<T>::dump() const {
amqp::internal::reader::
TypedPair<T>::dump() const {
return m_property + " : " + std::to_string (m_value);
}
template<>
inline std::string
amqp::TypedPair<std::string>::dump() const {
amqp::internal::reader::
TypedPair<std::string>::dump() const {
return m_property + " : " + m_value;
}
template<>
std::string
amqp::TypedPair<std::vector<std::unique_ptr<amqp::Value>>>::dump() const;
amqp::internal::reader::
TypedPair<std::vector<std::unique_ptr<amqp::reader::IValue>>>::dump() const;
template<>
std::string
amqp::TypedPair<std::list<std::unique_ptr<amqp::Value>>>::dump() const;
amqp::internal::reader::
TypedPair<std::list<std::unique_ptr<amqp::reader::IValue>>>::dump() const;
template<>
std::string
amqp::TypedPair<std::vector<std::unique_ptr<amqp::Pair>>>::dump() const;
amqp::internal::reader::
TypedPair<std::vector<std::unique_ptr<amqp::internal::reader::Pair>>>::dump() const;
template<>
std::string
amqp::TypedPair<std::list<std::unique_ptr<amqp::Pair>>>::dump() const;
amqp::internal::reader::
TypedPair<std::list<std::unique_ptr<amqp::internal::reader::Pair>>>::dump() const;
/******************************************************************************
*
@ -184,25 +195,28 @@ amqp::TypedPair<std::list<std::unique_ptr<amqp::Pair>>>::dump() const;
*
******************************************************************************/
namespace amqp {
namespace amqp::internal::reader {
class Reader {
using IReader = amqp::reader::IReader<amqp::internal::schema::SchemaMap::const_iterator>;
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<Value> dump(
std::any read (struct pn_data_t *) const override = 0;
std::string readString (struct pn_data_t *) const override = 0;
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const = 0;
const SchemaType &) const override = 0;
virtual std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const = 0;
const SchemaType &) const override = 0;
};
}

View File

@ -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<std::unique_ptr<amqp::Value>>
amqp::
std::list<std::unique_ptr<amqp::reader::IValue>>
amqp::internal::reader::
ListReader::dump_(
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_
const SchemaType & schema_
) const {
proton::is_described (data_);
std::list<std::unique_ptr<amqp::Value>> read;
std::list<std::unique_ptr<amqp::reader::IValue>> read;
{
proton::auto_enter ae (data_);
auto it = schema_->fromDescriptor(proton::readAndNext<std::string>(data_));
auto it = schema_.fromDescriptor (proton::readAndNext<std::string>(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::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
ListReader::dump (
const std::string & name_,
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_
const SchemaType & schema_
) const {
proton::auto_next an (data_);
return std::make_unique<amqp::TypedPair<std::list<std::unique_ptr<amqp::Value>>>>(
return std::make_unique<TypedPair<std::list<std::unique_ptr<amqp::reader::IValue>>>>(
name_,
dump_ (data_, schema_));
}
/******************************************************************************/
std::unique_ptr<amqp::Value>
amqp::
std::unique_ptr<amqp::reader::IValue>
amqp::internal::reader::
ListReader::dump(
pn_data_t * data_,
const std::unique_ptr<internal::schema::Schema> & schema_
const SchemaType & schema_
) const {
proton::auto_next an (data_);
return std::make_unique<amqp::TypedSingle<std::list<std::unique_ptr<amqp::Value>>>>(
return std::make_unique<amqp::internal::reader::TypedSingle<std::list<std::unique_ptr<amqp::reader::IValue>>>>(
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;
}

View File

@ -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<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) 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<amqp::Reader> m_reader;
std::weak_ptr<Reader> m_reader;
std::list<std::unique_ptr<amqp::Value>> dump_(
std::list<std::unique_ptr<amqp::reader::IValue>> dump_(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const;
const SchemaType &) const;
public :
ListReader (
const std::string & type_,
std::weak_ptr<amqp::Reader> reader_
std::weak_ptr<Reader> reader_
) : RestrictedReader (type_)
, m_reader (reader_)
, m_reader (std::move (reader_))
{ }
~ListReader() final = default;
internal::schema::Restricted::RestrictedTypes restrictedType() const;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
const std::string &,
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const override;
const SchemaType &) const override;
std::unique_ptr<Value> dump(
std::unique_ptr<amqp::reader::IValue> dump(
pn_data_t *,
const std::unique_ptr<internal::schema::Schema> &) const override;
const SchemaType &) const override;
};
}

View File

@ -5,8 +5,6 @@
#include <memory>
#include <types.h>
/******************************************************************************/
#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 &);

View File

@ -2,6 +2,9 @@
#include <iostream>
#include "amqp/schema/Schema.h"
#include "amqp/schema/ISchema.h"
/******************************************************************************/
namespace amqp::internal::schema {
@ -33,10 +36,10 @@ Envelope::Envelope (
/******************************************************************************/
const std::unique_ptr<amqp::internal::schema::Schema> &
const amqp::internal::schema::ISchemaType &
amqp::internal::schema::
Envelope::schema() const {
return m_schema;
return *m_schema;
}
/******************************************************************************/

View File

@ -27,7 +27,7 @@ namespace amqp::internal::schema {
std::unique_ptr<Schema> & schema_,
std::string descriptor_);
const std::unique_ptr<Schema> & schema() const;
const ISchemaType & schema() const;
const std::string & descriptor() const;
};

View File

@ -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<AMQPTypeNotation> types_
OrderedTypeNotations<AMQPTypeNotation> 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_);

View File

@ -12,49 +12,38 @@
#include "OrderedTypeNotations.h"
#include "amqp/AMQPDescribed.h"
#include "amqp/schema/ISchema.h"
/******************************************************************************/
namespace amqp::internal::schema {
typedef std::function <bool(const uPtr<AMQPTypeNotation> &, const uPtr<AMQPTypeNotation> &)> const SetSort;
using SchemaMap = std::map<std::string, const std::reference_wrapper<const uPtr<AMQPTypeNotation>>>;
using ISchemaType = amqp::schema::ISchema<SchemaMap::const_iterator>;
}
/******************************************************************************/
namespace amqp::internal::schema {
}
/******************************************************************************/
namespace amqp::internal::schema {
/*
*/
class Schema : public AMQPDescribed {
class Schema
: public amqp::schema::ISchema<SchemaMap::const_iterator>
, public amqp::AMQPDescribed
{
public :
friend std::ostream & operator << (std::ostream &, const Schema &);
typedef std::map<std::string, const std::reference_wrapper<const uPtr<AMQPTypeNotation>>> SchemaMap;
private :
OrderedTypeNotations<AMQPTypeNotation> m_types;
SchemaMap m_descriptorToType;
SchemaMap m_typeToDescriptor;
public :
Schema (OrderedTypeNotations<AMQPTypeNotation> types_);
explicit Schema (OrderedTypeNotations<AMQPTypeNotation> types_);
const OrderedTypeNotations<AMQPTypeNotation> & 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(); }
};
}

View File

@ -6,8 +6,13 @@
/******************************************************************************/
using namespace amqp::reader;
using namespace amqp::internal::reader;
/******************************************************************************/
TEST (Pair, string) { // NOLINT
amqp::TypedPair<std::string> str_test ("Left", "Hello");
TypedPair<std::string> 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> int_test ("Left", 101);
TypedPair<int> 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<amqp::TypedPair<double>> test =
std::make_unique<amqp::TypedPair<double>> ("property", 10.0);
std::unique_ptr<TypedPair<double>> test =
std::make_unique<TypedPair<double>> ("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<amqp::Pair>
static std::unique_ptr<IValue>
build (const std::string & prop_, int val_) {
return std::make_unique<amqp::TypedPair<int>> (prop_, val_);
return std::make_unique<TypedPair<int>> (prop_, val_);
}
};
std::vector<std::unique_ptr<amqp::Value>> vec;
std::vector<std::unique_ptr<IValue>> vec;
vec.reserve(2);
vec.emplace_back (builder::build ("first", 1));
vec.emplace_back (builder::build ("second", 2));
std::unique_ptr<amqp::Pair> test =
std::make_unique<amqp::TypedPair<std::vector<std::unique_ptr<amqp::Value>>>> (
std::unique_ptr<Pair> test =
std::make_unique<TypedPair<std::vector<std::unique_ptr<IValue>>>> (
"Vector", std::move (vec));
EXPECT_EQ("Vector : { first : 1, second : 2 }", test->dump());

View File

@ -4,8 +4,11 @@
#include "Reader.h"
using namespace amqp::reader;
using namespace amqp::internal::reader;
TEST (Single, string) { // NOLINT
amqp::TypedSingle<std::string> str_test ("Hello");
TypedSingle<std::string> 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<amqp::Value>
static std::unique_ptr<IValue>
build (int val_) {
return std::make_unique<amqp::TypedSingle<int>> (val_);
return std::make_unique<TypedSingle<int>> (val_);
}
};
std::list<std::unique_ptr<amqp::Value>> list;
std::list<std::unique_ptr<IValue>> 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<amqp::Single> test =
std::make_unique<amqp::TypedSingle<std::list<std::unique_ptr<amqp::Value>>>> (
std::unique_ptr<Single> test =
std::make_unique<TypedSingle<std::list<std::unique_ptr<IValue>>>> (
std::move (list));
EXPECT_EQ("[ 1, 2, 3, 4, 5 ]", test->dump());

View File

@ -273,7 +273,9 @@ readAndNext<std::string> (
} 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());
}
/******************************************************************************/