#ifndef PROCESS_MEMORY_DATAFACADE_HPP
#define PROCESS_MEMORY_DATAFACADE_HPP

// implements all data storage when shared memory is _NOT_ used

#include "storage/storage.hpp"
#include "engine/datafacade/contiguous_internalmem_datafacade_base.hpp"

namespace osrm
{
namespace engine
{
namespace datafacade
{

/**
 * This datafacade uses a process-local memory block to load
 * data into.  The structure and layout is the same as when using
 * shared memory, so this class, and the SharedMemoryDataFacade both
 * share a common base.
 * This class holds a unique_ptr to the memory block, so it
 * is auto-freed upon destruction.
 */
class ProcessMemoryDataFacade final : public ContiguousInternalMemoryDataFacadeBase
{

  private:
    std::unique_ptr<char[]> internal_memory;
    std::unique_ptr<storage::DataLayout> internal_layout;

  public:
    explicit ProcessMemoryDataFacade(const storage::StorageConfig &config)
    {
        storage::Storage storage(config);

        // Calculate the layout/size of the memory block
        internal_layout = std::make_unique<storage::DataLayout>();
        storage.PopulateLayout(*internal_layout);

        // Allocate the memory block, then load data from files into it
        internal_memory = std::make_unique<char[]>(internal_layout->GetSizeOfLayout());
        storage.PopulateData(*internal_layout, internal_memory.get());

        // Adjust all the private m_* members to point to the right places
        InitializeInternalPointers(*internal_layout.get(), internal_memory.get());
    }
};
}
}
}

#endif // PROCESS_MEMORY_DATAFACADE_HPP