class file


class file final
    : public basic_file

Description

This class represents a file in the file system.

Public Member Functions

file ()
noexcept

Constructs a file object not associated with any file.

file (
    const std::filesystem::path& file_path,
    access_mode mode,
    if_not_there if_file_not_there,
    std::size_t buffer_capacity = io_buffer::default_buffer_capacity
)

Constructs a file object and opens the file at the given path with the given access mode and sets up an I/O buffer with the given capacity.

Parameters:
  • file_path:

    The path to the file to open.

  • mode:

    The access mode to open the file in. This tells whether you want to just read, just write or both read and write. This cannot be changed later unless you close the file and reopen it.

  • if_file_not_there:

    The action to take if the specified file does not exist. This can be if_not_there::create, which causes the file to be created, or if_not_there::fail, which causes this constructor to construct a closed file object.

  • buffer_capacity:

    The capacity of the I/O buffer to associate with this file object.

file (
    const file& other
)
= delete
file&
operator = (
    const file& other
)
= delete
file (
    file&& other
)
noexcept

Move-constructs a file from an existing one.

Parameters:
  • other:

    The file to move from.

file&
operator = (
    file&& other
)
noexcept

Move-assigns a file into this one.

Parameters:
  • other:

    The file to move from.

bool
is_open ()
const noexcept override

Returns true if the file is open. Otherwise, returns false.

std::int64_t
get_position ()
const noexcept override

Returns the position this file is at, that is, the position at which read and write operations will take place next.

bool
open (
    const std::filesystem::path& file_path,
    access_mode mode,
    if_not_there if_file_not_there
)
noexcept override

Opens the file at the given path with the given access mode. The last argument tells what to do if the specified file doesn't already exists, that is, whether to create the file or fail to open it. Returns true if opening the file succeeds. Otherwise, returns false.

Parameters:
  • file_path:

    The path to the file to open.

  • mode:

    The access mode to open the file in. This tells whether you want to just read, just write or both read and write. This cannot be changed later unless you close the file and reopen it.

  • if_file_not_there:

    The action to take if the specified file does not exist. This can be if_not_there::create, which causes the file to be created, or if_not_there::fail, which causes this function to simply return false without taking any action.

void
close ()
noexcept override

Flushes the I/O buffer and closes the file.

Protected Member Functions

void
set_position_raw (
    std::int64_t new_position,
    position_reference pr
)
noexcept override
std::size_t
read_raw (
    std::byte* data,
    std::size_t byte_count,
    read_request rr
)
noexcept override
std::size_t
write_raw (
    const std::byte* data,
    std::size_t byte_count
)
noexcept override


Copyright © 2022-2025 Daniel T. McGinnis

CCL was first published in 2022, and is still actively maintained.

This website was first published in 2022, and is still actively maintained.

This specific web page was first published in 2023.