reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DataBuffer.cxx
Go to the documentation of this file.
1#include "DataBuffer.hxx"
2#include <memory.h>
3#include "rutil/ResipAssert.h"
5
6namespace reTurn {
7
8void ArrayDeallocator(char* data)
9{
10 delete [] data;
11}
12
13DataBuffer::DataBuffer(const char* const data, const size_t size, deallocator dealloc)
14 : mBuffer(nullptr)
15 , mSize(size)
16 , mDealloc(dealloc)
17{
18 if (mSize > 0)
19 {
20 mBuffer = new char[mSize];
21 memcpy(mBuffer, data, mSize);
22 }
23 mStart = mBuffer;
24}
25
26DataBuffer::DataBuffer(const size_t size, deallocator dealloc)
27 : mBuffer(nullptr)
28 , mSize(size)
29 , mDealloc(dealloc)
30{
31 if (mSize > 0)
32 {
33 mBuffer = new char[mSize];
34 memset(mBuffer, 0, mSize);
35 }
36
37 mStart = mBuffer;
38}
39
41{
42 mDealloc(mBuffer);
43}
44
45DataBuffer* DataBuffer::own(char* const data, const size_t size, deallocator dealloc)
46{
48 buff->mBuffer = data;
49 buff->mSize = size;
50 buff->mStart = buff->mBuffer;
51 return buff;
52}
53
54const char*
56{
57 return mStart;
58}
59
60size_t
62{
63 return mSize;
64}
65
66char*
68{
69 return mStart;
70}
71
72size_t&
74{
75 return mSize;
76}
77
78char&
80{
81 resip_assert(p < mSize);
82 return mBuffer[p];
83}
84
85char
86DataBuffer::operator[](const size_t p) const
87{
88 resip_assert(p < mSize);
89 return mBuffer[p];
90}
91
92size_t
94{
95 resip_assert(newSize <= mSize);
96 mSize = newSize;
97 return mSize;
98}
99
100size_t
101DataBuffer::offset(const size_t bytes)
102{
103 resip_assert(bytes < mSize);
104 mStart = mStart+bytes;
105 mSize = mSize-bytes;
106 return mSize;
107}
108
109} // namespace
110
111
112/* ====================================================================
113
114 Copyright (c) 2007-2008, Plantronics, Inc.
115 All rights reserved.
116
117 Redistribution and use in source and binary forms, with or without
118 modification, are permitted provided that the following conditions are
119 met:
120
121 1. Redistributions of source code must retain the above copyright
122 notice, this list of conditions and the following disclaimer.
123
124 2. Redistributions in binary form must reproduce the above copyright
125 notice, this list of conditions and the following disclaimer in the
126 documentation and/or other materials provided with the distribution.
127
128 3. Neither the name of Plantronics nor the names of its contributors
129 may be used to endorse or promote products derived from this
130 software without specific prior written permission.
131
132 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
133 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
134 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
135 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
136 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
137 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
138 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
142 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143
144 ==================================================================== */
#define resip_assert(x)
This file needs to work for both C and C++ code.
static DataBuffer * own(char *data, size_t size, deallocator dealloc=ArrayDeallocator)
size_t offset(size_t bytes)
char * mutableData() noexcept
DataBuffer(const char *data, size_t size, deallocator dealloc=ArrayDeallocator)
char & operator[](size_t p)
const char * data() const noexcept
size_t & mutableSize() noexcept
size_t size() const noexcept
size_t truncate(size_t newSize)
void ArrayDeallocator(char *data)
Definition DataBuffer.cxx:8
void list()
Definition userAdmin.cxx:66