C12Adapter Opensource C++ Interface
MStreamMemory Class Reference

The random access stream in memory that is always open. More...

Inheritance diagram for MStreamMemory:

Public Member Functions

 MStreamMemory (unsigned flags=FlagReadWrite)
 Default constructor creates the memory stream with an empty buffer. More...
 
 MStreamMemory (const char *buffer, unsigned length, unsigned flags=FlagReadWrite)
 Creates the memory stream filled by specified data. More...
 
 MStreamMemory (const MByteString &bytes, unsigned flags=FlagReadWrite)
 Creates the memory stream filled by specified data. More...
 
virtual ~MStreamMemory ()
 Closes the stream and reclaims memory.
 
virtual MStdString GetName () const
 Return a representative name of a stream. More...
 
const MByteStringGetBuffer () const
 Access the whole stream data.
 
void Open (const MByteString &bytes, unsigned flags=FlagReadWrite)
 Opens the stream and initializes it with values from the given bytes. More...
 
void OpenBuffer (const char *buffer, unsigned length, unsigned flags=FlagReadWrite)
 Opens the stream and initializes it with values from the given buffer. More...
 
void CloseAndClear ()
 Close the stream and clear the buffer associated with the stream. More...
 
- Public Member Functions inherited from MStream
virtual ~MStream ()
 Closes the stream and destroys the object. More...
 
bool IsOpen () const
 Whether the stream object is successfully open. More...
 
unsigned GetFlags () const
 Return flags associated with stream. More...
 
MByteString Read (unsigned count)
 Reads a byte string of a given length from the stream. More...
 
MByteString ReadAvailable (unsigned count)
 Reads a byte string up to a given length from the stream. More...
 
MByteString ReadAll ()
 Reads all bytes available in stream. More...
 
void ReadBytes (char *buffer, unsigned count)
 Reads a byte buffer of a given length from the stream. More...
 
unsigned ReadAvailableBytes (char *buffer, unsigned count)
 Reads a byte buffer up to a given length from the stream. More...
 
MVariant ReadLine ()
 Read one line from text file. More...
 
bool ReadOneLine (MStdString &line)
 Read one line from text file, return false at end of file. More...
 
MStdStringVector ReadAllLines ()
 Read all lines from text file. More...
 
void Skip (unsigned count)
 Skips over and discards specified number of bytes of data from this stream. More...
 
void WriteByte (Muint8 byte)
 Writes a byte to the current position in the stream and advances the position by one byte. More...
 
void WriteChar (char c)
 Writes a char to the current position in the stream and advances the position by one byte. More...
 
void Write (const MByteString &bytes)
 Writes a given byte string to the current position in the stream and advances the position. More...
 
void WriteBytes (const char *bytes, unsigned count)
 Writes a given byte buffer to the current position in the stream and advances the position. More...
 
void WriteChars (const char *chars)
 Writes a given zero terminated character string to the current position in the stream and advances the position. More...
 
void WriteLine (const MStdString &str)
 Write a line into file. More...
 
void WriteAllLines (const MStdStringVector &lines)
 Write given lines into file. More...
 
void WriteFormat (MConstChars format,...)
 Write a formatted string into a file. More...
 
void WriteFormatVA (MConstChars format, va_list args)
 Write a formatted string into a file using va_list. More...
 
void Flush ()
 Causes any buffered data to be written into stream. More...
 
void Close ()
 Flushes and closes the current stream and releases any resources. More...
 
MStdString GetKey () const
 
void SetKey (const MStdString &)
 
unsigned GetPosition () const
 
void SetPosition (unsigned)
 
unsigned GetSize () const
 
void SetSize (unsigned)
 
MVariant ReadByte ()
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Additional Inherited Members

- Public Types inherited from MStream
enum  OpenFlags {
  FlagReadOnly = 0x0001,
  FlagWriteOnly = 0x0002,
  FlagReadWrite = 0x0003,
  FlagText = 0x00010,
  FlagBuffered = 0x0020
}
 Flags that set modes of stream manipulation. More...
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MStream
 MStream ()
 Default constructor, called from children of stream.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

The random access stream in memory that is always open.

This class internally owns the buffer that it uses for reading and writing.

Constructor & Destructor Documentation

MStreamMemory::MStreamMemory ( unsigned  flags = FlagReadWrite)

Default constructor creates the memory stream with an empty buffer.

This is a handy way for creating empty memory streams that can be written.

Parameters
flagsFlags with which the stream shall be opened. It is a logic error not to give write flag while creating the stream in such a way.
MStreamMemory::MStreamMemory ( const char *  buffer,
unsigned  length,
unsigned  flags = FlagReadWrite 
)

Creates the memory stream filled by specified data.

This is a C++ only method. The given buffer is going to be copied into the stream's internal storage.

Parameters
bufferPointer to buffer with data that shall be used for the stream.
lengthLength of the buffer.
flagsFlags with which the stream shall be open.
MStreamMemory::MStreamMemory ( const MByteString bytes,
unsigned  flags = FlagReadWrite 
)

Creates the memory stream filled by specified data.

The given buffer is going to be copied into the stream's internal storage.

Parameters
bytesData that shall be used for the stream.
flagsFlags with which the stream shall be open.

Member Function Documentation

void MStreamMemory::CloseAndClear ( )

Close the stream and clear the buffer associated with the stream.

After the standard method Close, the buffer can be accessed, but after CloseAndClear it will be cleared.

If there is a necessity to clear the buffer without closing the stream one can assign zero to MStream::SetSize property.

virtual MStdString MStreamMemory::GetName ( ) const
virtual

Return a representative name of a stream.

This method overwrites the parent implementation. The name always returned by this type of stream is "<memory>"

Implements MStream.

void MStreamMemory::Open ( const MByteString bytes,
unsigned  flags = FlagReadWrite 
)

Opens the stream and initializes it with values from the given bytes.

Later on, during write operations, the stream size can grow beyond the given number of bytes. This is possible because the given buffer is copied, and can grow.

Parameters
bytesInitial bytes to use for reading and writing.
flagsFlags that shall be used by the stream, default is FlagReadWrite.
void MStreamMemory::OpenBuffer ( const char *  buffer,
unsigned  length,
unsigned  flags = FlagReadWrite 
)

Opens the stream and initializes it with values from the given buffer.

Later on, during write operations, the stream size can grow beyond the given number of bytes. This is possible because the given buffer is copied, and can grow.

Parameters
bufferBuffer to use for reading and writing.
lengthThe size of the buffer.
flagsFlags that shall be used by the stream, default is FlagReadWrite.