Skip to content

Generic IO

abstract_reader

abstract_reader class

template <typename T = void> abstract_reader

Base class for all typed readers

Source code
template <typename T = void>
struct abstract_reader : abstract_stream<T>
{
    virtual size_t read(T* data, size_t size) = 0;

    template <univector_tag Tag>
    size_t read(univector<T, Tag>& data)
    {
        return read(data.data(), data.size());
    }
    size_t read(univector_ref<T>&& data) { return read(data.data(), data.size()); }

    univector<T> read(size_t size)
    {
        univector<T> result(size);
        this->read(result);
        return result;
    }
    bool read(conditional<is_void<T>, internal_generic::empty, T>& data) { return read(&data, 1) == 1; }
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L112

abstract_stream

abstract_stream class

template <typename T = void> abstract_stream

Base class for all typed readers and writer

Source code
template <typename T = void>
struct abstract_stream
{
    virtual ~abstract_stream() {}
    virtual imax tell() const                          = 0;
    virtual bool seek(imax offset, seek_origin origin) = 0;
    bool seek(imax offset, int origin) { return seek(offset, static_cast<seek_origin>(origin)); }
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L94

abstract_writer

abstract_writer class

template <typename T = void> abstract_writer

Base class for all typed writers

Source code
template <typename T = void>
struct abstract_writer : abstract_stream<T>
{
    virtual size_t write(const T* data, size_t size) = 0;

    template <univector_tag Tag>
    size_t write(const univector<T, Tag>& data)
    {
        return write(data.data(), data.size());
    }
    size_t write(univector_ref<const T>&& data) { return write(data.data(), data.size()); }
    bool write(const conditional<is_void<T>, internal_generic::empty, T>& data)
    {
        return write(&data, 1) == 1;
    }
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L134

binary_reader typedef

binary_reader = abstract_reader<>

Binary reader

Source code
using binary_reader = abstract_reader<>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L182

binary_writer typedef

binary_writer = abstract_writer<>

Binary writer

Source code
using binary_writer = abstract_writer<>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L185

byte_reader typedef

byte_reader = abstract_reader<u8>

Byte reader

Source code
using byte_reader = abstract_reader<u8>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L188

byte_writer typedef

byte_writer = abstract_writer<u8>

Byte writer

Source code
using byte_writer = abstract_writer<u8>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L191

f32_reader typedef

f32_reader = abstract_reader<f32>

float reader

Source code
using f32_reader = abstract_reader<f32>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L194

f32_writer typedef

f32_writer = abstract_writer<f32>

float writer

Source code
using f32_writer = abstract_writer<f32>

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L197

file_reader

file_reader class

template <typename T = void> file_reader

Typed file reader

Source code
template <typename T = void>
struct file_reader : abstract_reader<T>
{
    file_reader(file_handle&& handle) : handle(std::move(handle)) {}
    ~file_reader() override {}
    size_t read(T* data, size_t size) final { return fread(data, element_size<T>(), size, handle.file); }

    using abstract_reader<T>::read;

    imax tell() const final { return IO_TELL_64(handle.file); }
    bool seek(imax offset, seek_origin origin) final
    {
        return !IO_SEEK_64(handle.file, offset, static_cast<int>(origin));
    }
    file_handle handle;
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L218

file_writer

file_writer class

template <typename T = void> file_writer

Typed file writer

Source code
template <typename T = void>
struct file_writer : abstract_writer<T>
{
    file_writer(file_handle&& handle) : handle(std::move(handle)) {}
    ~file_writer() override {}

    using abstract_writer<T>::write;
    size_t write(const T* data, size_t size) final
    {
        return fwrite(data, element_size<T>(), size, handle.file);
    }
    imax tell() const final { return IO_TELL_64(handle.file); }
    bool seek(imax offset, seek_origin origin) final
    {
        return !IO_SEEK_64(handle.file, offset, static_cast<int>(origin));
    }
    file_handle handle;
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L236

fopen_portable function

inline FILE *fopen_portable(const filepath_char *path,
                            const filepath_char *mode)

Opens file using portable path (char on posix, wchar_t on windows)

Source code
inline FILE* fopen_portable(const filepath_char* path, const filepath_char* mode)
{
#ifdef CMT_OS_WIN
    FILE* f   = nullptr;
    errno_t e = _wfopen_s(&f, path, mode);
    (void)e;
    return f;
#else
    return fopen(path, mode);
#endif
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L61

open_file_for_appending function

template <typename T = void>
inline std::shared_ptr<file_writer<T>>
open_file_for_appending(const filepath &path)

Opens typed file for appending

Source code
template <typename T = void>
inline std::shared_ptr<file_writer<T>> open_file_for_appending(const filepath& path)
{
    return std::make_shared<file_writer<T>>(fopen_portable(path.c_str(), KFR_FILEPATH("ab")));
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L270

open_file_for_reading function

template <typename T = void>
inline std::shared_ptr<file_reader<T>>
open_file_for_reading(const filepath &path)

Opens typed file for reading

Source code
template <typename T = void>
inline std::shared_ptr<file_reader<T>> open_file_for_reading(const filepath& path)
{
    return std::make_shared<file_reader<T>>(fopen_portable(path.c_str(), KFR_FILEPATH("rb")));
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L256

open_file_for_writing function

template <typename T = void>
inline std::shared_ptr<file_writer<T>>
open_file_for_writing(const filepath &path)

Opens typed file for writing

Source code
template <typename T = void>
inline std::shared_ptr<file_writer<T>> open_file_for_writing(const filepath& path)
{
    return std::make_shared<file_writer<T>>(fopen_portable(path.c_str(), KFR_FILEPATH("wb")));
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L263

seek_origin

seek_origin enum

enum class seek_origin : int

Seek origin

Source code
enum class seek_origin : int
{
    current = SEEK_CUR, ///< From the current position
    begin   = SEEK_SET, ///< From the beginning
    end     = SEEK_END, ///< From the end
}

https://github.com/kfrlib/kfr/blob//include/kfr/io/file.hpp#L85

current enumerator

current = SEEK_CUR

From the current position

begin enumerator

begin = SEEK_SET

From the beginning

end enumerator

end = SEEK_END

From the end


Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/