mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
NOTICK - Move CompositeFactory into amqp::internal namespace
This commit is contained in:
parent
2ba8676013
commit
3c3f5f5e04
@ -18,7 +18,7 @@
|
||||
#include "amqp/descriptors/AMQPDescriptorRegistory.h"
|
||||
|
||||
#include "amqp/schema/Envelope.h"
|
||||
#include "CompositeFactory.h"
|
||||
#include "amqp/CompositeFactory.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@ -51,7 +51,7 @@ data_and_stop(std::ifstream & f_, ssize_t sz) {
|
||||
<< *envelope << std::endl); // NOLINT
|
||||
}
|
||||
|
||||
CompositeFactory cf;
|
||||
amqp::internal::CompositeFactory cf;
|
||||
|
||||
cf.process (envelope->schema());
|
||||
|
||||
@ -112,4 +112,3 @@ main (int argc, char **argv) {
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
32
experimental/cpp-serializer/include/ICompositeFactory.h
Normal file
32
experimental/cpp-serializer/include/ICompositeFactory.h
Normal file
@ -0,0 +1,32 @@
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -19,36 +19,40 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
template <typename T>
|
||||
std::shared_ptr<T> &
|
||||
computeIfAbsent (
|
||||
spStrMap_t<T> & map_,
|
||||
const std::string & k_,
|
||||
std::function<std::shared_ptr<T>(void)> f_
|
||||
) {
|
||||
auto it = map_.find (k_);
|
||||
template<typename T>
|
||||
std::shared_ptr<T> &
|
||||
computeIfAbsent(
|
||||
spStrMap_t<T> &map_,
|
||||
const std::string &k_,
|
||||
std::function<std::shared_ptr<T>(void)> f_
|
||||
) {
|
||||
auto it = map_.find(k_);
|
||||
|
||||
if (it == map_.end()) {
|
||||
DBG ("ComputeIfAbsent \"" << k_ << "\" - missing" << std::endl); // NOLINT
|
||||
map_[k_] = std::move (f_());
|
||||
DBG (" \"" << k_ << "\" - RTN: " << map_[k_]->name() << " : " << map_[k_]->type() << std::endl); // NOLINT
|
||||
assert (map_[k_]);
|
||||
assert (map_[k_] != nullptr);
|
||||
assert (k_ == map_[k_]->type());
|
||||
if (it == map_.end()) {
|
||||
DBG ("ComputeIfAbsent \"" << k_ << "\" - missing" << std::endl); // NOLINT
|
||||
map_[k_] = std::move(f_());
|
||||
DBG (" \"" << k_ << "\" - RTN: " << map_[k_]->name() << " : " << map_[k_]->type()
|
||||
<< std::endl); // NOLINT
|
||||
assert (map_[k_]);
|
||||
assert (map_[k_] != nullptr);
|
||||
assert (k_ == map_[k_]->type());
|
||||
|
||||
return map_[k_];
|
||||
return map_[k_];
|
||||
} else {
|
||||
DBG ("ComputeIfAbsent \"" << k_ << "\" - found it" << std::endl); // NOLINT
|
||||
DBG (" \"" << k_ << "\" - RTN: " << map_[k_]->name() << std::endl); // NOLINT
|
||||
|
||||
assert (it->second != nullptr);
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG ("ComputeIfAbsent \"" << k_ << "\" - found it" << std::endl); // NOLINT
|
||||
DBG (" \"" << k_ << "\" - RTN: " << map_[k_]->name() << std::endl); // NOLINT
|
||||
|
||||
assert (it->second != nullptr);
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -68,9 +72,10 @@ computeIfAbsent (
|
||||
*
|
||||
*/
|
||||
void
|
||||
amqp::internal::
|
||||
CompositeFactory::process (const SchemaPtr & schema_) {
|
||||
for (auto i = schema_->begin() ; i != schema_->end() ; ++i) {
|
||||
for (const auto & j : *i) {
|
||||
for (const auto & i : *schema_) {
|
||||
for (const auto & j : i) {
|
||||
process(*j);
|
||||
m_readersByDescriptor[j->descriptor()] = m_readersByType[j->name()];
|
||||
}
|
||||
@ -80,6 +85,7 @@ CompositeFactory::process (const SchemaPtr & schema_) {
|
||||
/******************************************************************************/
|
||||
|
||||
std::shared_ptr<amqp::Reader>
|
||||
amqp::internal::
|
||||
CompositeFactory::process(
|
||||
const amqp::internal::schema::AMQPTypeNotation & schema_)
|
||||
{
|
||||
@ -101,6 +107,7 @@ CompositeFactory::process(
|
||||
/******************************************************************************/
|
||||
|
||||
std::shared_ptr<amqp::Reader>
|
||||
amqp::internal::
|
||||
CompositeFactory::processComposite (
|
||||
const amqp::internal::schema::AMQPTypeNotation & type_)
|
||||
{
|
||||
@ -155,6 +162,7 @@ CompositeFactory::processComposite (
|
||||
/******************************************************************************/
|
||||
|
||||
std::shared_ptr<amqp::Reader>
|
||||
amqp::internal::
|
||||
CompositeFactory::processRestricted (
|
||||
const amqp::internal::schema::AMQPTypeNotation & type_)
|
||||
{
|
||||
@ -194,6 +202,7 @@ CompositeFactory::processRestricted (
|
||||
/******************************************************************************/
|
||||
|
||||
const std::shared_ptr<amqp::Reader>
|
||||
amqp::internal::
|
||||
CompositeFactory::byType (const std::string & type_) {
|
||||
auto it = m_readersByType.find (type_);
|
||||
|
||||
@ -203,6 +212,7 @@ CompositeFactory::byType (const std::string & type_) {
|
||||
/******************************************************************************/
|
||||
|
||||
const std::shared_ptr<amqp::Reader>
|
||||
amqp::internal::
|
||||
CompositeFactory::byDescriptor (const std::string & descriptor_) {
|
||||
auto it = m_readersByDescriptor.find (descriptor_);
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <set>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "ICompositeFactory.h"
|
||||
#include "amqp/schema/Schema.h"
|
||||
#include "amqp/schema/Envelope.h"
|
||||
#include "amqp/schema/Composite.h"
|
||||
@ -14,9 +16,10 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
class CompositeFactory {
|
||||
namespace amqp::internal {
|
||||
|
||||
class CompositeFactory : public ICompositeFactory {
|
||||
private :
|
||||
using SchemaPtr = uPtr<amqp::internal::schema::Schema>;
|
||||
using CompositePtr = uPtr<amqp::internal::schema::Composite>;
|
||||
using EnvelopePtr = uPtr<amqp::internal::schema::Envelope>;
|
||||
|
||||
@ -29,20 +32,23 @@ class CompositeFactory {
|
||||
public :
|
||||
CompositeFactory() = default;
|
||||
|
||||
void process (const SchemaPtr &);
|
||||
void process(const SchemaPtr &) override ;
|
||||
|
||||
const std::shared_ptr<amqp::Reader> byType (const std::string &);
|
||||
const std::shared_ptr<amqp::Reader> byDescriptor (const std::string &);
|
||||
virtual const std::shared_ptr<amqp::Reader> byType(const std::string &) override;
|
||||
|
||||
virtual const std::shared_ptr<amqp::Reader> byDescriptor(const std::string &) override;
|
||||
|
||||
private :
|
||||
std::shared_ptr<amqp::Reader> process(const amqp::internal::schema::AMQPTypeNotation &);
|
||||
|
||||
std::shared_ptr<amqp::Reader>
|
||||
processComposite (const amqp::internal::schema::AMQPTypeNotation &);
|
||||
processComposite(const amqp::internal::schema::AMQPTypeNotation &);
|
||||
|
||||
std::shared_ptr<amqp::Reader>
|
||||
processRestricted (const amqp::internal::schema::AMQPTypeNotation &);
|
||||
};
|
||||
processRestricted(const amqp::internal::schema::AMQPTypeNotation &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -32,7 +32,6 @@ namespace {
|
||||
|
||||
// do we depend on the left hand side
|
||||
|
||||
|
||||
if (std::find (
|
||||
otn.begin(),
|
||||
otn.end(),
|
||||
|
Loading…
Reference in New Issue
Block a user