Adapter Cyclic Implementation - GerdHirsch/Cpp-VisitorFrameworkCyclicAcyclic GitHub Wiki

The Repository generates the application specific Adapters with the parameters, the repository is created: using VisitableAdapter = .

template<class LoggingPolicy, class BaseKind_, class ...Visitables>
struct Repository{
    using VisitorBase = ...
...
    template<class Adaptee, class StoragePolicy>
    using VisitableAdapter =
	    Cyclic::VisitableAdapter<Adaptee, StoragePolicy, LoggingPolicy, VisitorBase>;

    // Convenience Interfaces
    template<class Adaptee>
    using AdapterByWeakpointer =
        VisitableAdapter<Adaptee, StorageByWeakpointer<Adaptee>>;
    template<class Adaptee>
    using AdapterByReference =
	    VisitableAdapter<Adaptee, StorageByReference<Adaptee>>;

...

LoggingPolicy and VisitorBase is used as arguments from Repository. The convenience interfaces define in addition, a StoragePolicy.

namespace Cyclic{
template
<
	class Adaptee,
	class StoragePolicy,
	class LoggingPolicy,
	class VisitorBase
>
struct VisitableAdapter :
    VisitableImpl<
	    Adaptee,
	    VisitorBase,
	    LoggingPolicy,
	    VisitableAdapter<Adaptee, StoragePolicy, LoggingPolicy, VisitorBase>>,
    StoragePolicy
{
    using StorageType = typename StoragePolicy::StorageType;
    using ReturnType = typename StoragePolicy::ReturnType;
    using ConstReturnType = typename StoragePolicy::ConstReturnType;

    VisitableAdapter(StorageType element): StoragePolicy(element){}

    ReturnType getVisitable() { return this->get(); }
    ConstReturnType getVisitable() const { return this->get(); }

    std::string toString() const {
	    std::string message("CyclicAdapter::");
	    message += this->getVisitable()->toString();
	    return message;
    }
};
} //namespace

The VisitableAdapter inherits from VisitableImpl<..> and from the StoragePolicy. It uses the StoragePolicy to store the Adaptee. It provides a getVisitable() method, which is used from VisitableImpl<..>::accept(..).

⚠️ **GitHub.com Fallback** ⚠️