class mola::LazyLoadResource

Overview

Looks like a std::shared_ptr, but is stored on disk when not used.

#include <LazyLoadResource.h>

class LazyLoadResource
{
public:
    // fields

    static std::string EXTERNAL_BASE_DIR {""};

    // construction

    LazyLoadResource();

    LazyLoadResource(
        const mrpt::serialization::CSerializable::Ptr& source,
        const std::string& f
        );

    // methods

    const std::string& externalStorage() const;
    mrpt::serialization::CSerializable::Ptr value();
    const mrpt::serialization::CSerializable::Ptr& value() const;
    void load() const;
    void unload() const;
    bool isUnloaded() const;
    void reset();

    void set(
        const mrpt::serialization::CSerializable::Ptr& source,
        const std::string& f
        );

    void setAsExternal(const std::string& relativeFileName);
    void setParentEntityID(const mola::id_t id);
};

Methods

mrpt::serialization::CSerializable::Ptr value()

Access (a copy of) the underlying smart pointer to the object

const mrpt::serialization::CSerializable::Ptr& value() const

Access (a const-ref to) the underlying smart pointer to the object

void load() const

Ensure data is loaded from disk, if it was automatically swapped-off

void unload() const

Unload data and save to disk now, if not already done before

void reset()

Empty this container.

void set(
    const mrpt::serialization::CSerializable::Ptr& source,
    const std::string& f
    )

Sets the contents of this container, including the desired external file name

void setAsExternal(const std::string& relativeFileName)

Sets this container as externally-stored, given an external filename. The external content is not automatically loaded, for that, explicitly call load() if needed.