/* MemBlob */
-MemBlob::MemBlob(const MemBlob::size_type reserveSize) :
- mem(nullptr), capacity(0), size(0) // will be set by memAlloc
+MemBlob::MemBlob(const size_type reserveSize)
{
debugs(MEMBLOB_DEBUGSECTION,9, "constructed, this="
<< static_cast<void*>(this) << " id=" << id
memAlloc(reserveSize);
}
-MemBlob::MemBlob(const char *buffer, const MemBlob::size_type bufSize) :
- mem(nullptr), capacity(0), size(0) // will be set by memAlloc
+MemBlob::MemBlob(const_pointer buffer, const size_type bufSize)
{
debugs(MEMBLOB_DEBUGSECTION,9, "constructed, this="
<< static_cast<void*>(this) << " id=" << id
size_t actualAlloc = minSize;
Must(!mem);
- mem = static_cast<char*>(memAllocBuf(actualAlloc, &actualAlloc));
+ mem = static_cast<value_type *>(memAllocBuf(actualAlloc, &actualAlloc));
Must(mem);
capacity = actualAlloc;
}
void
-MemBlob::append(const char *source, const size_type n)
+MemBlob::append(const_pointer source, const size_type n)
{
if (n > 0) { // appending zero bytes is allowed but only affects the stats
Must(willFit(n));
public:
typedef RefCount<MemBlob> Pointer;
- typedef uint32_t size_type;
+
+ /* emulate std::basic_string API */
+ using value_type = char;
+ using size_type = uint32_t;
+ using const_pointer = const value_type *;
/// obtain a const view of class-wide statistics
static const MemBlobStats& GetStats();
/// create a new MemBlob with at least reserveSize capacity
explicit MemBlob(const size_type reserveSize);
- /// create a MemBlob containing a copy of the buffer of a given size
- MemBlob(const char *buffer, const size_type bufferSize);
-
+ /* emulate std::basic_string API */
+ MemBlob(const_pointer, const size_type);
~MemBlob() override;
/// the number unused bytes at the end of the allocated blob
* \param source raw buffer to be copied
* \param n the number of bytes to copy from the source buffer
*/
- void append(const char *source, const size_type n);
+ void append(const_pointer source, const size_type n);
/* non-const methods below require exclusive object ownership */
- /// extends the available space to the entire allocated blob
- void clear() { size = 0; }
-
/// keep the first n bytes and forget the rest of data
/// cannot be used to increase our size; use append*() methods for that
void syncSize(const size_type n);
/// dump debugging information
std::ostream & dump(std::ostream &os) const;
+ /* emulate std::basic_string API */
+ void clear() { size = 0; }
+
public:
/* MemBlob users should avoid these and must treat them as read-only */
- char *mem; ///< raw allocated memory block
- size_type capacity; ///< size of the raw allocated memory block
- size_type size; ///< maximum allocated memory in use by callers
+ value_type *mem = nullptr; ///< raw allocated memory block
+ size_type capacity = 0; ///< size of the raw allocated memory block
+ size_type size = 0; ///< maximum allocated memory in use by callers
const InstanceId<MemBlob> id; ///< blob identifier
private: