C12Adapter Opensource C++ Interface
MStreamExternalMemory Class Reference

The random access stream, arranged on the memory chunk, that this class does not own. More...

Inheritance diagram for MStreamExternalMemory:

Public Member Functions

 MStreamExternalMemory ()
 Create object without associating it with any buffer. More...
 
 MStreamExternalMemory (char *buffer, unsigned bufferSize, unsigned fileSize, unsigned flags=FlagReadWrite)
 Creates the stream on the given read/write memory buffer. More...
 
 MStreamExternalMemory (const char *buffer, unsigned bufferAndFileSize, unsigned flags=FlagReadOnly)
 Creates the stream on the given read-only memory buffer. More...
 
virtual ~MStreamExternalMemory ()
 Closes the stream and destroys the object.
 
virtual MStdString GetName () const
 Return a representative name of a stream. More...
 
unsigned GetBufferSize () const
 Return the buffer size of the stream. More...
 
void Open (char *buffer, unsigned bufferSize, unsigned fileSize, unsigned flags=FlagReadWrite)
 Opens the stream on the given read-write memory buffer. More...
 
void OpenReadOnly (const char *buffer, unsigned bufferAndFileSize, unsigned flags=FlagReadOnly)
 Opens the stream on the given read-only memory buffer. More...
 
void CloseAndClear ()
 Close the stream and clear any buffer pointers associated with the stream. More...
 
char * GetBuffer ()
 
const char * GetBuffer () const
 
- 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, arranged on the memory chunk, that this class does not own.

This is sometimes more convenient or faster than MStreamMemory as it avoids extra data copying. The class is not reflected.

Constructor & Destructor Documentation

MStreamExternalMemory::MStreamExternalMemory ( )

Create object without associating it with any buffer.

See also
Open for opening the chunk of memory for reading or writing.
OpenReadOnly for opening the chunk of memory only for reading.
MStreamExternalMemory::MStreamExternalMemory ( char *  buffer,
unsigned  bufferSize,
unsigned  fileSize,
unsigned  flags = FlagReadWrite 
)

Creates the stream on the given read/write memory buffer.

Parameters
bufferBuffer to use for reading and writing.
bufferSizeThe size of the buffer.
fileSizeInitial size of the file arranged in the buffer. The value would be zero if the buffer is to be filled with data. The file size shall not be bigger than bufferSize.
flagsFlags that shall be used by the stream, default is FlagReadWrite. It would be a logic error to not have write access in flags.
MStreamExternalMemory::MStreamExternalMemory ( const char *  buffer,
unsigned  bufferAndFileSize,
unsigned  flags = FlagReadOnly 
)

Creates the stream on the given read-only memory buffer.

Parameters
bufferBuffer to use for reading.
bufferAndFileSizeThe size of the buffer, equal to size of the file.
flagsFlags that shall be used by the stream, default is FlagReadOnly. It would be a logic error to give write access in flags, as the buffer is not supposed to be changed.

Member Function Documentation

void MStreamExternalMemory::CloseAndClear ( )

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

After the standard method Close, the buffer and size methods can be used to access the buffer, but after CloseAndClear they all get nullified.

char* MStreamExternalMemory::GetBuffer ( )
inline

Access the buffer associated with the stream.

const char* MStreamExternalMemory::GetBuffer ( ) const
inline

Access the buffer associated with the stream.

unsigned MStreamExternalMemory::GetBufferSize ( ) const
inline

Return the buffer size of the stream.

For read-only streams, this is also the size of the stream, while for read-write streams, this value can be bigger than stream size.

virtual MStdString MStreamExternalMemory::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 "<mem>"

Implements MStream.

void MStreamExternalMemory::Open ( char *  buffer,
unsigned  bufferSize,
unsigned  fileSize,
unsigned  flags = FlagReadWrite 
)

Opens the stream on the given read-write memory buffer.

Parameters
bufferBuffer to use for reading and writing.
bufferSizeThe size of the buffer.
fileSizeInitial size of the file arranged in the buffer. The value would be zero if the buffer is to be filled with data. The file size shall not be bigger than bufferSize.
flagsFlags that shall be used by the stream, default is FlagReadWrite. It would be a logic error to not have write access in flags.
void MStreamExternalMemory::OpenReadOnly ( const char *  buffer,
unsigned  bufferAndFileSize,
unsigned  flags = FlagReadOnly 
)

Opens the stream on the given read-only memory buffer.

Parameters
bufferBuffer to use for reading.
bufferAndFileSizeThe size of the buffer, equal to size of the file.
flagsFlags that shall be used by the stream, default is FlagReadOnly. It would be a logic error to give write access in flags, as the buffer is not supposed to be changed.