StoragePolicy - GerdHirsch/Cpp-VisitorFrameworkCyclicAcyclic GitHub Wiki

Non visitable types can be adapted by an adapter. There are many ways to manage these objects. With a StoragePolicy, the user is able to define it's own way. The VisitorFramework provides different StoragePolicies in header StoragePolicies.h.

namespace VisitorFramework{
template<class Adaptee>
struct StorageByReference{
    using StorageType = Adaptee&;
    using ReturnType = Adaptee*;
    using ConstReturnType = Adaptee const*;

    StorageByReference(StorageType adaptee):adaptee(adaptee){}

    ReturnType get(){ return &adaptee; }
    ConstReturnType get() const { return &adaptee; }
protected:
    StorageType adaptee;
};
template<class Adaptee>
struct StorageByWeakpointer{
    using StorageType = std::weak_ptr<Adaptee>;
    using ReturnType = std::shared_ptr<Adaptee>;
    using ConstReturnType = std::shared_ptr<Adaptee const>;

    StorageByWeakpointer(StorageType adaptee):adaptee(adaptee){}
    ReturnType get(){ return adaptee.lock(); }
    ConstReturnType get() const { return adaptee.lock(); }
protected:
    StorageType adaptee;
};
}

If you want to provide your own StoragePolicy, it must define appropriate types and operations for the Adapters, like the ones above.

see also: Application

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