Class CStream
Defined in File CStream.h
Inheritance Relationships
Derived Types
public mrpt::io::CCompressedInputStream(Class CCompressedInputStream)public mrpt::io::CCompressedOutputStream(Class CCompressedOutputStream)public mrpt::io::CFileGZInputStream(Class CFileGZInputStream)public mrpt::io::CFileGZOutputStream(Class CFileGZOutputStream)public mrpt::io::CFileInputStream(Class CFileInputStream)public mrpt::io::CFileOutputStream(Class CFileOutputStream)public mrpt::io::CFileStream(Class CFileStream)public mrpt::io::CMemoryStream(Class CMemoryStream)public mrpt::io::CPipeBaseEndPoint(Class CPipeBaseEndPoint)
Class Documentation
-
class CStream
This base class is used to provide a unified interface to files,memory buffers,..Please see the derived classes. This class is largely inspired by Borland VCL “TStream” class.
Apart of the “VCL like” methods, operators “>>” and “<<” have been defined so that simple types (int,bool,char,float,char *,std::string,…) can be directly written and read to and from any
CStream easily. Please, it is recomendable to read CSerializable documentation also.See also
CFileStream, CMemoryStream,CSerializable
Subclassed by mrpt::io::CCompressedInputStream, mrpt::io::CCompressedOutputStream, mrpt::io::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CFileInputStream, mrpt::io::CFileOutputStream, mrpt::io::CFileStream, mrpt::io::CMemoryStream, mrpt::io::CPipeBaseEndPoint
Public Types
-
enum TSeekOrigin
Used in CStream::Seek
Values:
-
enumerator sFromBeginning
-
enumerator sFromCurrent
-
enumerator sFromEnd
-
enumerator sFromBeginning
Public Functions
-
virtual size_t Read(void *Buffer, size_t Count) = 0
Introduces a pure virtual method responsible for reading from the stream.
-
virtual size_t Write(const void *Buffer, size_t Count) = 0
Introduces a pure virtual method responsible for writing to the stream. Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
-
CStream() = default
Constructor
-
virtual ~CStream()
Destructor
-
inline virtual size_t ReadBufferImmediate(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read, without waiting for more extra bytes to arrive (just those already enqued in the stream). Note that this method will fallback to ReadBuffer() in most CStream classes but in some hardware-related classes.
- Throws:
std::exception – On any error, or if ZERO bytes are read.
-
virtual uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) = 0
Introduces a pure virtual method for moving to a specified position in the streamed resource. he Origin parameter indicates how to interpret the Offset parameter. Origin should be one of the following values:
sFromBeginning (Default) Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
sFromCurrent Offset is from the current position in the resource. Seek moves to Position + Offset.
sFromEnd Offset is from the end of the resource. Offset must be <= 0 to indicate a number of bytes before the end of the file.
- Returns:
Seek returns the new value of the Position property.
-
virtual uint64_t getTotalBytesCount() const = 0
Returns the total amount of bytes in the stream.
-
virtual uint64_t getPosition() const = 0
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
- virtual int printf (const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
See also
CStdOutStream
- template<typename CONTAINER_TYPE> inline int void printf_vector (const char *fmt, const CONTAINER_TYPE &V, char separator=',')
Prints a vector in the format [A,B,C,…] using CStream::printf, and the fmt string for each vector element
T.- Template Parameters:
CONTAINER_TYPE – can be any vector<T>, deque<T> or alike.
-
bool getline(std::string &out_str)
Reads from the stream until a
\ncharacter is found (\rcharacters are ignored).- Returns:
false on EOF or any other read error.
-
inline virtual std::string getStreamDescription() const
Returns a human-friendly description of the stream, e.g. a filename.
-
enum TSeekOrigin