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

Public Types | Public Member Functions | Protected Attributes | List of all members
clan::IODevice Class Reference
clanCore I/O Data

I/O Device interface. More...

`#include <iodevice.h>`

Inheritance diagram for clan::IODevice:

## Public Types
enum class | SeekMode { set , cur , end }
| Seeking modes. More...

## Public Member Functions
| 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.

## Protected Attributes
std::shared_ptr< IODevice_Impl > | impl

## Detailed Description

I/O Device interface.

This class can store basic datatypes and retain portability (using the specified endian mode)
The supported datatypes are: int64_t, int32_t, int16_t and int8_t
The std::string datatype is supported - Using Size(int32_t), Charactor Data (std::string characters)

## Member Enumeration Documentation

## ◆ SeekMode

enum class clan::IODevice::SeekMode
| strong

Seeking modes.

Enumerator
set | Set to a specific value from the start.
cur | Set relative to the current position.
end | Set to a specific value from the end (use negative position)

## Constructor & Destructor Documentation

## ◆ IODevice() [1/2]

clan::IODevice::IODevice | ( |  | ) |

Constructs a null instance.

Referenced by duplicate().

## ◆ IODevice() [2/2]

clan::IODevice::IODevice | ( | IODeviceProvider * | provider | ) |

Constructs a IODevice.

Parameters

  provider | = IODevice Provider

## ◆ ~IODevice()

clan::IODevice::~IODevice | ( |  | ) |

## Member Function Documentation

## ◆ duplicate()

IODevice clan::IODevice::duplicate | ( |  | ) |

Create a new IODevice referencing the same resource.

References IODevice().

## ◆ get_position()

size_t clan::IODevice::get_position | ( |  | ) | const

Returns the position in the data stream.

Returns SIZE_MAX if the position is unknown.

Returns
  The size (SIZE_MAX if position is unknown)

## ◆ get_provider() [1/2]

IODeviceProvider * clan::IODevice::get_provider | ( |  | ) |

Returns the provider for this object.

## ◆ get_provider() [2/2]

const IODeviceProvider * clan::IODevice::get_provider | ( |  | ) | const

Returns the provider for this object.

## ◆ get_size()

size_t clan::IODevice::get_size | ( |  | ) | const

Returns the size of data stream.

Returns SIZE_MAX if the size is unknown.

Returns
  The size (SIZE_MAX if size is unknown)

## ◆ is_little_endian()

bool clan::IODevice::is_little_endian | ( |  | ) | const

Returns true if the input source is in little endian mode.

Returns
  true if little endian

## ◆ is_null()

bool clan::IODevice::is_null | ( |  | ) | const
| inline

Returns true if this object is invalid.

References impl.

## ◆ peek()

size_t clan::IODevice::peek | ( | void * | data,
|  | size_t | len )

Peek data from device (data is left in the buffer).

Parameters

  data | Data to receive
  len | Maximum length of data to receive

Returns
  size of data received.

## ◆ read()

size_t clan::IODevice::read | ( | void * | data,
|  | size_t | len,
|  | bool | receive_all = true )

Alias for receive(data, len, receive_all)

Parameters

  data | Data to receive
  len | Length to receive
  receive_all | true to receive all the data. false = receive part of the data, if it would block

Returns
  size of data received

## ◆ read_float()

float clan::IODevice::read_float | ( |  | ) |

Reads a float from input source.

Warning, this is not portable

Returns
  The float read.

## ◆ read_int16()

int16_t clan::IODevice::read_int16 | ( |  | ) |

Reads a signed 16 bit integer from input source.

Returns
  The integer read.

## ◆ read_int32()

int32_t clan::IODevice::read_int32 | ( |  | ) |

Reads a signed 32 bit integer from input source.

Returns
  The integer read.

## ◆ read_int64()

int64_t clan::IODevice::read_int64 | ( |  | ) |

Reads a signed 64 bit integer from input source.

Returns
  The integer read.

## ◆ read_int8()

int8_t clan::IODevice::read_int8 | ( |  | ) |

Reads a signed 8 bit integer from input source.

Returns
  The integer read.

## ◆ read_string_a()

std::string clan::IODevice::read_string_a | ( |  | ) |

Reads a string from the input source.

The binary format expected in the input source is first an uint32 telling the length of the string, and then the string itself.

Returns
  The string read.

## ◆ read_string_nul()

std::string clan::IODevice::read_string_nul | ( |  | ) |

Reads a nul terminated string from the input source.

The binary format expected in the input source is a nul terminated string. (The NUL termintor is read, so that the file position is set after the NUL)

Returns
  The string read.

## ◆ read_string_text()

std::string clan::IODevice::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.

After reading the input source up to "read_until_chars", the file position is set to the first character that was not read. If the file contains NUL characters, then the input is read up to the NUL character, and the file position is set AFTER the NUL)

Parameters

  skip_initial_chars | Ignore any of these characters at the start of the string. NULL = Do not ignore any characters
  read_until_chars | Read from the input until any of these characters are found. NULL = Read until the end of the file
  allow_eof | Allow EOF

Returns
  The string read.

## ◆ read_uint16()

uint16_t clan::IODevice::read_uint16 | ( |  | ) |

Reads an unsigned 16 bit integer from input source.

Returns
  The integer read.

## ◆ read_uint32()

uint32_t clan::IODevice::read_uint32 | ( |  | ) |

Reads an unsigned 32 bit integer from input source.

Returns
  The integer read.

## ◆ read_uint64()

uint64_t clan::IODevice::read_uint64 | ( |  | ) |

Reads an unsigned 64 bit integer from input source.

Returns
  The integer read.

## ◆ read_uint8()

uint8_t clan::IODevice::read_uint8 | ( |  | ) |

Reads an unsigned 8 bit integer from input source.

Returns
  The integer read.

## ◆ receive()

size_t clan::IODevice::receive | ( | void * | data,
|  | size_t | len,
|  | bool | receive_all = true )

Receive data from device.

Parameters

  data | Data to receive
  len | Length to receive
  receive_all | true to receive all the data. false = receive part of the data, if it would block

Returns
  size of data received

## ◆ seek()

bool clan::IODevice::seek | ( | int | position,
|  | SeekMode | mode = SeekMode::set )

Seek in data stream.

Parameters

  position | Position to use (usage depends on the seek mode)
  mode | Seek mode

Returns
  false = Failed

References set.

## ◆ send()

size_t clan::IODevice::send | ( | const void * | data,
|  | size_t | len,
|  | bool | send_all = true )

Send data to device.

If the device databuffer is too small, it will be extended (ie grow memory block size or file size)

Parameters

  data | Data to send
  len | Length to send
  send_all | true to send all the data. false = send part of the data, if it would block

Returns
  size of data sent

## ◆ set_big_endian_mode()

void clan::IODevice::set_big_endian_mode | ( |  | ) |

Changes input data endianess to big endian mode. (Default is little endian)

## ◆ set_little_endian_mode()

void clan::IODevice::set_little_endian_mode | ( |  | ) |

Changes input data endianess to little endian mode. This is the default setting.

## ◆ set_system_mode()

void clan::IODevice::set_system_mode | ( |  | ) |

Changes input data endianess to the local systems mode.

## ◆ throw_if_null()

void clan::IODevice::throw_if_null | ( |  | ) | const

Throw an exception if this object is invalid.

## ◆ write()

size_t clan::IODevice::write | ( | const void * | data,
|  | size_t | len,
|  | bool | send_all = true )

Alias for send(data, len, send_all)

Parameters

  data | Data to send
  len | Length to send
  send_all | true to send all the data. false = send part of the data, if it would block

Returns
  size of data sent

## ◆ write_float()

void clan::IODevice::write_float | ( | float | data | ) |

Writes a float to output source.

Parameters

  data | = Float to write

Warning, this is not portable.

## ◆ write_int16()

void clan::IODevice::write_int16 | ( | int16_t | data | ) |

Writes a signed 16 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_int32()

void clan::IODevice::write_int32 | ( | int32_t | data | ) |

Writes a signed 32 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_int64()

void clan::IODevice::write_int64 | ( | int64_t | data | ) |

Writes a signed 64 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_int8()

void clan::IODevice::write_int8 | ( | int8_t | data | ) |

Writes a signed 8 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_string_a()

void clan::IODevice::write_string_a | ( | const std::string & | str | ) |

Writes a string to the output source.

Parameters

  str | String to write

The binary format written to the output source is first an uint32 telling the length of the string, and then the string itself.

## ◆ write_string_nul()

void clan::IODevice::write_string_nul | ( | const std::string & | str | ) |

Writes a nul terminated string to the output source.

Parameters

  str | String to write

The binary format written to the output source is the string content followed by the NUL character.

## ◆ write_string_text()

void clan::IODevice::write_string_text | ( | const std::string & | str | ) |

Writes a text string to the output source.

Parameters

  str | String to write

The binary format written to the output source is the string content appended with a native newline. On Windows the newline is CR+LF sequence and on other platforms it is only LF character. This function is intended for use with text files.

## ◆ write_uint16()

void clan::IODevice::write_uint16 | ( | uint16_t | data | ) |

Writes an unsigned 16 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_uint32()

void clan::IODevice::write_uint32 | ( | uint32_t | data | ) |

Writes an unsigned 32 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_uint64()

void clan::IODevice::write_uint64 | ( | uint64_t | data | ) |

Writes an unsigned 64 bit integer to output source.

Parameters

  data | Integer to write

## ◆ write_uint8()

void clan::IODevice::write_uint8 | ( | uint8_t | data | ) |

Writes an unsigned 8 bit integer to output source.

Parameters

  data | Integer to write

## Member Data Documentation

## ◆ impl

std::shared_ptr<IODevice_Impl> clan::IODevice::impl
| protected

Referenced by is_null().

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

- iodevice.h