Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::FileDescriptor Struct Reference

File Descriptor (use SC::File to open and use it with strings and containers). More...

#include <FileDescriptor.h>

Inheritance diagram for SC::FileDescriptor:
SC::UniqueHandle< SC::detail::FileDescriptorDefinition >

Public Types

enum  SeekMode {
  SeekStart ,
  SeekEnd ,
  SeekCurrent
}
 How the offset to FileDescriptor::seek is defined. More...
 

Public Member Functions

Result openForWriteToDevNull ()
 Opens a file descriptor handle for writing to /dev/null or equivalent on current OS. More...
 
Result setBlocking (bool blocking)
 Set blocking mode (read / write waiting for I/O). More...
 
Result setInheritable (bool inheritable)
 Set inheritable flag (visibility to child processes). More...
 
Result isInheritable (bool &hasValue) const
 Queries the inheritable state of this descriptor. More...
 
Result read (Span< char > data, Span< char > &actuallyRead, uint64_t offset)
 Reads bytes at offset into user supplied span. More...
 
Result read (Span< uint8_t > data, Span< uint8_t > &actuallyRead, uint64_t offset)
 Reads bytes at offset into user supplied span. More...
 
Result read (Span< char > data, Span< char > &actuallyRead)
 Reads bytes from current position (FileDescriptor::seek) into user supplied Span. More...
 
Result read (Span< uint8_t > data, Span< uint8_t > &actuallyRead)
 Reads bytes from current position (FileDescriptor::seek) into user supplied Span. More...
 
Result write (Span< const char > data, uint64_t offset)
 Writes bytes at offset from start of the file descriptor. More...
 
Result write (Span< const uint8_t > data, uint64_t offset)
 Writes bytes at offset from start of the file descriptor. More...
 
Result write (Span< const char > data)
 Writes bytes from current position (FileDescriptor::seek) of the file descriptor. More...
 
Result write (Span< const uint8_t > data)
 Writes bytes from current position (FileDescriptor::seek) of the file descriptor. More...
 
Result seek (SeekMode seekMode, uint64_t offset)
 Changes the current position in the file descriptor, if seekable. More...
 
Result currentPosition (size_t &position) const
 Gets current descriptor position (if seekable) More...
 
Result sizeInBytes (size_t &sizeInBytes) const
 Gets total file size in bytes (if seekable) More...
 
 UniqueHandle ()=default
 
 UniqueHandle (const UniqueHandle &v)=delete
 
 UniqueHandle (UniqueHandle &&v)
 
 UniqueHandle (const Handle &externalHandle)
 

Friends

struct File
 

Detailed Description

File Descriptor (use SC::File to open and use it with strings and containers).

Member Enumeration Documentation

◆ SeekMode

How the offset to FileDescriptor::seek is defined.

Enumerator
SeekStart 

Offset to FileDescriptor::seek is to be applied from start of descriptor.

SeekEnd 

Offset to FileDescriptor::seek is to be applied (backwards) from end of descriptor.

SeekCurrent 

Offset to FileDescriptor::seek is to be applied from current descriptor position.

Member Function Documentation

◆ currentPosition()

Result SC::FileDescriptor::currentPosition ( size_t position) const

Gets current descriptor position (if seekable)

Parameters
position(output) current position of file descriptor
Returns
Valid result if seek succeeds

◆ isInheritable()

Result SC::FileDescriptor::isInheritable ( bool &  hasValue) const

Queries the inheritable state of this descriptor.

Parameters
hasValuewill be set to true if the file descriptor has inheritable file set
Returns
Valid Result if the inheritable flag has been queried successfully

◆ openForWriteToDevNull()

Result SC::FileDescriptor::openForWriteToDevNull ( )

Opens a file descriptor handle for writing to /dev/null or equivalent on current OS.

Returns
true if file has been opened successfully

◆ read() [1/4]

Result SC::FileDescriptor::read ( Span< char >  data,
Span< char > &  actuallyRead 
)

Reads bytes from current position (FileDescriptor::seek) into user supplied Span.

Parameters
dataSpan of bytes where data should be written to
actuallyReadA sub-span of data of the actually read bytes. A zero sized span means EOF.
Returns
Valid result if read succeeded

◆ read() [2/4]

Result SC::FileDescriptor::read ( Span< char >  data,
Span< char > &  actuallyRead,
uint64_t  offset 
)

Reads bytes at offset into user supplied span.

Parameters
dataSpan of bytes where data should be written to
actuallyReadA sub-span of data of the actually read bytes. A zero sized span means EOF.
offsetOffset from begin of the file descriptor where read should be started
Returns
Valid result if read succeeded

◆ read() [3/4]

Result SC::FileDescriptor::read ( Span< uint8_t data,
Span< uint8_t > &  actuallyRead 
)

Reads bytes from current position (FileDescriptor::seek) into user supplied Span.

Parameters
dataSpan of bytes where data should be written to
actuallyReadA sub-span of data of the actually read bytes. A zero sized span means EOF.
Returns
Valid result if read succeeded

◆ read() [4/4]

Result SC::FileDescriptor::read ( Span< uint8_t data,
Span< uint8_t > &  actuallyRead,
uint64_t  offset 
)

Reads bytes at offset into user supplied span.

Parameters
dataSpan of bytes where data should be written to
actuallyReadA sub-span of data of the actually read bytes. A zero sized span means EOF.
offsetOffset from begin of the file descriptor where read should be started
Returns
Valid result if read succeeded

◆ seek()

Result SC::FileDescriptor::seek ( SeekMode  seekMode,
uint64_t  offset 
)

Changes the current position in the file descriptor, if seekable.

Parameters
seekModeHow the offset is defined (from start, end, current)
offsetAn offset to be applied according to seekMode to this descriptor
Returns
Valid result if seek succeeds

◆ setBlocking()

Result SC::FileDescriptor::setBlocking ( bool  blocking)

Set blocking mode (read / write waiting for I/O).

Can be set also during open with OpenOptions.

Parameters
blockingtrue to set file to blocking mode
Returns
true if blocking mode has been changed successfully

◆ setInheritable()

Result SC::FileDescriptor::setInheritable ( bool  inheritable)

Set inheritable flag (visibility to child processes).

Can be set also during open with OpenOptions.

Parameters
inheritabletrue to set file to blocking mode
Returns
true if blocking mode has been changed successfully

◆ sizeInBytes()

Result SC::FileDescriptor::sizeInBytes ( size_t sizeInBytes) const

Gets total file size in bytes (if seekable)

Parameters
sizeInBytes(output) total size of file
Returns
Valid result if seek succeeds

◆ write() [1/4]

Result SC::FileDescriptor::write ( Span< const char >  data)

Writes bytes from current position (FileDescriptor::seek) of the file descriptor.

Parameters
dataSpan of bytes containing the data to write
Returns
Valid result if write succeeded

◆ write() [2/4]

Result SC::FileDescriptor::write ( Span< const char >  data,
uint64_t  offset 
)

Writes bytes at offset from start of the file descriptor.

Parameters
dataSpan of bytes containing the data to write
offsetOffset from begin of file descriptor to start writing
Returns
Valid result if write succeeded

◆ write() [3/4]

Result SC::FileDescriptor::write ( Span< const uint8_t data)

Writes bytes from current position (FileDescriptor::seek) of the file descriptor.

Parameters
dataSpan of bytes containing the data to write
Returns
Valid result if write succeeded

◆ write() [4/4]

Result SC::FileDescriptor::write ( Span< const uint8_t data,
uint64_t  offset 
)

Writes bytes at offset from start of the file descriptor.

Parameters
dataSpan of bytes containing the data to write
offsetOffset from begin of file descriptor to start writing
Returns
Valid result if write succeeded

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