summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/MemBlockStream.cpp20
-rw-r--r--lib/common/MemBlockStream.h4
2 files changed, 24 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
diff --git a/lib/common/MemBlockStream.h b/lib/common/MemBlockStream.h
index 5234525b..f02e57ba 100644
--- a/lib/common/MemBlockStream.h
+++ b/lib/common/MemBlockStream.h
@@ -29,6 +29,7 @@ class MemBlockStream : public IOStream
public:
MemBlockStream();
MemBlockStream(const void *pBuffer, int Size);
+ MemBlockStream(const std::string& rMessage);
MemBlockStream(const StreamableMemBlock &rBlock);
MemBlockStream(const CollectInBufferStream &rBuffer);
MemBlockStream(const MemBlockStream &rToCopy);
@@ -46,6 +47,9 @@ public:
virtual int GetSize() const { return mBytesInBuffer; }
private:
+ // Use mTempBuffer when we need to hold a copy of the memory block,
+ // and free it ourselves when done.
+ CollectInBufferStream mTempBuffer;
const char *mpBuffer;
int mBytesInBuffer;
int mReadPosition;