clan::File Class Reference - ClanLib SDK
Description: clan::File Class Reference

Public Types | Public Member Functions | Static Public Member Functions | List of all members
clan::File Class Reference
clanCore I/O Data

File I/O device. More...

`#include <file.h>`

Inheritance diagram for clan::File:

## Public Types
enum | AccessFlags { access_read = 1 , access_write = 2 , access_read_write = access_read | access_write }
| Access flags. More...
enum | Flags { flag_write_through = 1 , flag_no_buffering = 2 , flag_random_access = 4 , flag_sequential_scan = 8 }
| Optimization Flags. More...
enum | OpenMode { open_always , open_existing , open_existing_truncate , create_always , create_new }
| File opening modes. More...
enum | ShareFlags { share_read = 1 , share_write = 2 , share_delete = 4 , share_all = share_read + share_write + share_delete }
| File sharing flags. More...
Public Types inherited from clan::IODevice
enum class | SeekMode { set , cur , end }
| Seeking modes. More...

## Public Member Functions
| File ()
| Constructs a file object.
| File (const std::string &filename)
| Constructs a file object read only.
| File (const std::string &filename, OpenMode mode, unsigned int access, unsigned int share=share_all, unsigned int flags=0)
| Constructs a file object.
| ~File ()
void | close ()
| Close file.
bool | open (const std::string &filename)
| Opens a file read only.
bool | open (const std::string &filename, OpenMode mode, unsigned int access, unsigned int share=share_all, unsigned int flags=0)
| Opens a file.
Public Member Functions inherited from clan::IODevice
| IODevice ()
| Constructs a null instance.
| IODevice (IODeviceProvider *provider)
| Constructs a IODevice.
| ~IODevice ()
IODevice | duplicate ()
| Create a new IODevice referencing the same resource.
size_t | get_position () const
| Returns the position in the data stream.
IODeviceProvider * | get_provider ()
| Returns the provider for this object.
const IODeviceProvider * | get_provider () const
| Returns the provider for this object.
size_t | get_size () const
| Returns the size of data stream.
bool | is_little_endian () const
| Returns true if the input source is in little endian mode.
bool | is_null () const
| Returns true if this object is invalid.
size_t | peek (void *data, size_t len)
| Peek data from device (data is left in the buffer).
size_t | read (void *data, size_t len, bool receive_all=true)
| Alias for receive(data, len, receive_all)
float | read_float ()
| Reads a float from input source.
int16_t | read_int16 ()
| Reads a signed 16 bit integer from input source.
int32_t | read_int32 ()
| Reads a signed 32 bit integer from input source.
int64_t | read_int64 ()
| Reads a signed 64 bit integer from input source.
int8_t | read_int8 ()
| Reads a signed 8 bit integer from input source.
std::string | read_string_a ()
| Reads a string from the input source.
std::string | read_string_nul ()
| Reads a nul terminated string from the input source.
std::string | read_string_text (const char *skip_initial_chars, const char *read_until_chars, bool allow_eof=true)
| Reads a string from the input source where the source is a text file.
uint16_t | read_uint16 ()
| Reads an unsigned 16 bit integer from input source.
uint32_t | read_uint32 ()
| Reads an unsigned 32 bit integer from input source.
uint64_t | read_uint64 ()
| Reads an unsigned 64 bit integer from input source.
uint8_t | read_uint8 ()
| Reads an unsigned 8 bit integer from input source.
size_t | receive (void *data, size_t len, bool receive_all=true)
| Receive data from device.
bool | seek (int position, SeekMode mode=SeekMode::set)
| Seek in data stream.
size_t | send (const void *data, size_t len, bool send_all=true)
| Send data to device.
void | set_big_endian_mode ()
| Changes input data endianess to big endian mode. (Default is little endian)
void | set_little_endian_mode ()
| Changes input data endianess to little endian mode. This is the default setting.
void | set_system_mode ()
| Changes input data endianess to the local systems mode.
void | throw_if_null () const
| Throw an exception if this object is invalid.
size_t | write (const void *data, size_t len, bool send_all=true)
| Alias for send(data, len, send_all)
void | write_float (float data)
| Writes a float to output source.
void | write_int16 (int16_t data)
| Writes a signed 16 bit integer to output source.
void | write_int32 (int32_t data)
| Writes a signed 32 bit integer to output source.
void | write_int64 (int64_t data)
| Writes a signed 64 bit integer to output source.
void | write_int8 (int8_t data)
| Writes a signed 8 bit integer to output source.
void | write_string_a (const std::string &str)
| Writes a string to the output source.
void | write_string_nul (const std::string &str)
| Writes a nul terminated string to the output source.
void | write_string_text (const std::string &str)
| Writes a text string to the output source.
void | write_uint16 (uint16_t data)
| Writes an unsigned 16 bit integer to output source.
void | write_uint32 (uint32_t data)
| Writes an unsigned 32 bit integer to output source.
void | write_uint64 (uint64_t data)
| Writes an unsigned 64 bit integer to output source.
void | write_uint8 (uint8_t data)
| Writes an unsigned 8 bit integer to output source.

## Static Public Member Functions
static DataBuffer | read_bytes (const std::string &filename)
| Loads an file into a byte buffer.
static std::string | read_text (const std::string &filename)
| Loads an UTF-8 text file into a string.
static void | write_bytes (const std::string &filename, const DataBuffer &bytes)
| Saves a byte buffer to file.
static void | write_text (const std::string &filename, const std::string &text, bool write_bom=false)
| Saves an UTF-8 text string to file.

## Additional Inherited Members
Protected Attributes inherited from clan::IODevice
std::shared_ptr< IODevice_Impl > | impl

## Detailed Description

File I/O device.

## Member Enumeration Documentation

## ◆ AccessFlags

enum clan::File::AccessFlags

Access flags.

File access types available.

Enumerator
access_read | Generic read access.
access_write | Generic write access.
access_read_write | Generic read write access.

## ◆ Flags

enum clan::File::Flags

Optimization Flags.

Enumerator
flag_write_through |
flag_no_buffering |
flag_random_access |
flag_sequential_scan |

## ◆ OpenMode

enum clan::File::OpenMode

File opening modes.

Enumerator
open_always | Open file or create it if it does not exist.
open_existing | Open existing file. Fails if it does not exist.
open_existing_truncate | Open existing file and truncate it.
create_always | Create file, even if it already exists.
create_new | Create a new file. Fails if it already exists.

## ◆ ShareFlags

enum clan::File::ShareFlags

File sharing flags.

Enumerator
share_read | Allow others to open the file for reading.
share_write | Allow others to open the file for writing.
share_delete | Allow others to delete the file.
share_all | All other sharing flags combined.

## Constructor & Destructor Documentation

## ◆ File() [1/3]

clan::File::File | ( |  | ) |

Constructs a file object.

## ◆ File() [2/3]

clan::File::File | ( | const std::string & | filename | ) |

Constructs a file object read only.

PathHelp::normalize(filename, PathHelp::path_type_file) is called

## ◆ File() [3/3]

clan::File::File | ( | const std::string & | filename,
|  | OpenMode | mode,
|  | unsigned int | access,
|  | unsigned int | share = share_all,
|  | unsigned int | flags = 0 )

Constructs a file object.

PathHelp::normalize(filename, PathHelp::path_type_file) is called

## ◆ ~File()

clan::File::~File | ( |  | ) |

## Member Function Documentation

## ◆ close()

void clan::File::close | ( |  | ) |

Close file.

## ◆ open() [1/2]

bool clan::File::open | ( | const std::string & | filename | ) |

Opens a file read only.

PathHelp::normalize(filename, PathHelp::path_type_file) is called

## ◆ open() [2/2]

bool clan::File::open | ( | const std::string & | filename,
|  | OpenMode | mode,
|  | unsigned int | access,
|  | unsigned int | share = share_all,
|  | unsigned int | flags = 0 )

Opens a file.

PathHelp::normalize(filename, PathHelp::path_type_file) is called

## ◆ read_bytes()

static DataBuffer clan::File::read_bytes | ( | const std::string & | filename | ) |
| static

Loads an file into a byte buffer.

## ◆ read_text()

static std::string clan::File::read_text | ( | const std::string & | filename | ) |
| static

Loads an UTF-8 text file into a string.

## ◆ write_bytes()

static void clan::File::write_bytes | ( | const std::string & | filename,
|  | const DataBuffer & | bytes )
| static

Saves a byte buffer to file.

## ◆ write_text()

static void clan::File::write_text | ( | const std::string & | filename,
|  | const std::string & | text,
|  | bool | write_bom = false )
| static

Saves an UTF-8 text string to file.

The documentation for this class was generated from the following file:

- file.h