diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-02-11 10:29:08 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-02-11 10:29:08 +0000 |
commit | 8a058d8e37ccd6b4ab538bcf854a71a57f47273c (patch) | |
tree | 811602863390faf0c10adb99d5dad79ac9d51b08 /lib/common/MemBlockStream.cpp | |
parent | 50fc10551f25ce34d64bca9711efbca50996c329 (diff) |
Add a MemBlockStream constructor from a simple string.
Useful for sending simple string messages through Protocols or writing them
to streams. Takes a copy of the string, so you don't need to worry about object
lifetime.
Diffstat (limited to 'lib/common/MemBlockStream.cpp')
-rw-r--r-- | lib/common/MemBlockStream.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/common/MemBlockStream.cpp b/lib/common/MemBlockStream.cpp index 3a43a304..f6b7d07b 100644 --- a/lib/common/MemBlockStream.cpp +++ b/lib/common/MemBlockStream.cpp @@ -52,6 +52,26 @@ MemBlockStream::MemBlockStream(const void *pBuffer, int Size) // -------------------------------------------------------------------------- // // Function +// Name: MemBlockStream::MemBlockStream(const std::string& rMessage) +// Purpose: Convenience constructor for sending a simple string. +// Copies the string, so you can pass a temporary in. +// Created: 2014/01/20 +// +// -------------------------------------------------------------------------- +MemBlockStream::MemBlockStream(const std::string& rMessage) +: mReadPosition(0) +{ + mTempBuffer.Write(rMessage.c_str(), rMessage.size()); + mTempBuffer.SetForReading(); + mpBuffer = mTempBuffer.GetBuffer(); + mBytesInBuffer = rMessage.size(); + ASSERT(mpBuffer != 0); + ASSERT(mBytesInBuffer >= 0); +} + +// -------------------------------------------------------------------------- +// +// Function // Name: MemBlockStream::MemBlockStream(const StreamableMemBlock &) // Purpose: Constructor (doesn't copy block, careful with lifetimes) // Created: 2003/09/05 |