Program Listing for File MemoryMappedFile.hpp

Return to documentation for file (include/networkit/io/MemoryMappedFile.hpp)

/*
 * MemoryMappedFile.hpp
 *
 *  Created on: 16.07.2018
 *      Author: Manuel Penschuck (networkit@manuel.jetzt)
 */

#ifndef NETWORKIT_IO_MEMORY_MAPPED_FILE_HPP_
#define NETWORKIT_IO_MEMORY_MAPPED_FILE_HPP_

#include <memory>
#include <string>

namespace NetworKit {
struct MemoryMappedFileState;

class MemoryMappedFile final {
public:
    using value_type = char;
    using const_iterator = const value_type *;

    MemoryMappedFile();

    explicit MemoryMappedFile(const std::string &path);

    ~MemoryMappedFile();

    MemoryMappedFile(const MemoryMappedFile &) = delete;
    MemoryMappedFile &operator=(const MemoryMappedFile &) = delete;

    MemoryMappedFile(MemoryMappedFile &&o) noexcept;

    MemoryMappedFile &operator=(MemoryMappedFile &&o) noexcept;

    void open(const std::string &file);

    void close() noexcept;

    const_iterator cbegin() const { return beginIt; }

    const_iterator cend() const { return endIt; }

    size_t size() const { return std::distance(beginIt, endIt); }

private:
    const_iterator beginIt{nullptr};
    const_iterator endIt{nullptr};

    std::unique_ptr<MemoryMappedFileState> state;
};

} // namespace NetworKit
#endif // NETWORKIT_IO_MEMORY_MAPPED_FILE_HPP_