mxnet
Public Member Functions | Static Public Member Functions | List of all members
dmlc::Stream Class Referenceabstract

interface of stream I/O for serialization More...

#include <io.h>

Inheritance diagram for dmlc::Stream:
Inheritance graph
Collaboration diagram for dmlc::Stream:
Collaboration graph

Public Member Functions

virtual size_t Read (void *ptr, size_t size)=0
 reads data from a stream More...
 
virtual void Write (const void *ptr, size_t size)=0
 writes data to a stream More...
 
virtual ~Stream (void)
 virtual destructor More...
 
template<typename T >
void Write (const T &data)
 writes a data to stream. More...
 
template<typename T >
bool Read (T *out_data)
 loads a data from stream. More...
 
template<typename T >
void WriteArray (const T *data, size_t num_elems)
 Endian aware write array of data. More...
 
template<typename T >
bool ReadArray (T *data, size_t num_elems)
 Endian aware read array of data. More...
 

Static Public Member Functions

static StreamCreate (const char *uri, const char *const flag, bool allow_null=false)
 generic factory function create an stream, the stream will close the underlying files upon deletion More...
 

Detailed Description

interface of stream I/O for serialization

Constructor & Destructor Documentation

virtual dmlc::Stream::~Stream ( void  )
inlinevirtual

virtual destructor

Member Function Documentation

static Stream* dmlc::Stream::Create ( const char *  uri,
const char *const  flag,
bool  allow_null = false 
)
static

generic factory function create an stream, the stream will close the underlying files upon deletion

Parameters
urithe uri of the input currently we support hdfs://, s3://, and file:// by default file:// will be used
flagcan be "w", "r", "a"
allow_nullwhether NULL can be returned, or directly report error
Returns
the created stream, can be NULL when allow_null == true and file do not exist
virtual size_t dmlc::Stream::Read ( void *  ptr,
size_t  size 
)
pure virtual

reads data from a stream

Parameters
ptrpointer to a memory buffer
sizeblock size
Returns
the size of data read

Implemented in dmlc::MemoryStringStream, and dmlc::MemoryFixedSizeStream.

template<typename T >
bool dmlc::Stream::Read ( T *  out_data)
inline

loads a data from stream.

dmlc::Stream support Write/Read of most STL composites and base types. If the data type is not supported, a compile time error will be issued.

This function is endian-aware, the input endian defined by DMLC_IO_USE_LITTLE_ENDIAN

Parameters
out_dataplace holder of data to be deserialized
Returns
whether the load was successful
template<typename T >
bool dmlc::Stream::ReadArray ( T *  data,
size_t  num_elems 
)
inline

Endian aware read array of data.

Parameters
dataThe data pointer
num_elemsNumber of elements
Template Parameters
Tthe data type.
Returns
whether the load was successful
virtual void dmlc::Stream::Write ( const void *  ptr,
size_t  size 
)
pure virtual

writes data to a stream

Parameters
ptrpointer to a memory buffer
sizeblock size

Implemented in dmlc::MemoryStringStream, and dmlc::MemoryFixedSizeStream.

template<typename T >
void dmlc::Stream::Write ( const T &  data)
inline

writes a data to stream.

dmlc::Stream support Write/Read of most STL composites and base types. If the data type is not supported, a compile time error will be issued.

This function is endian-aware, the output endian defined by DMLC_IO_USE_LITTLE_ENDIAN

Parameters
datadata to be written
Template Parameters
Tthe data type to be written
template<typename T >
void dmlc::Stream::WriteArray ( const T *  data,
size_t  num_elems 
)
inline

Endian aware write array of data.

Parameters
dataThe data pointer
num_elemsNumber of elements
Template Parameters
Tthe data type.

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