Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
buffer.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 
19 
20 #ifndef CBUFFER_H
21 #define CBUFFER_H
22 
23 
24 
25 
26 
27 class CBuffer
28 {
29 private:
30  uint8_t* _data;
31  size_t _size;
33  boost::scoped_array<uint8_t> _spAllocation;
34 
35  // disallow copy and assignment.
36  CBuffer(const CBuffer&);
37  void operator=(const CBuffer& other);
38 
39 
40 public:
41  CBuffer(); // deliberately makes the buffer null
42  void Reset(); // releases current pointer
43 
44 
45  CBuffer(size_t nSize);
46  HRESULT InitWithAllocation(size_t size);
47 
48 
49  CBuffer(uint8_t* pByteArray, size_t nByteArraySize, bool fCopy);
50 
51  HRESULT InitWithAllocAndCopy(uint8_t* pByteArray, size_t nByteArraySize);
52  HRESULT InitNoAlloc(uint8_t* pByteArray, size_t nByteArraySize);
53 
54  inline size_t GetSize() {return _size;}
55  inline size_t GetAllocatedSize() {return _allocatedSize;}
56 
57  HRESULT SetSize(size_t size);
58 
59 
60  inline uint8_t* GetData() {return _data;}
61 
62  bool IsValid();
63 };
64 
65 typedef boost::shared_ptr<CBuffer> CRefCountedBuffer;
66 
67 
68 #endif
uint8_t * GetData()
Definition: buffer.h:60
HRESULT InitWithAllocation(size_t size)
Definition: buffer.cpp:48
bool IsValid()
Definition: buffer.cpp:143
CBuffer()
Definition: buffer.cpp:24
uint8_t * _data
Definition: buffer.h:30
size_t GetSize()
Definition: buffer.h:54
HRESULT InitWithAllocAndCopy(uint8_t *pByteArray, size_t nByteArraySize)
Definition: buffer.cpp:89
size_t _size
Definition: buffer.h:31
Definition: buffer.h:27
void operator=(const CBuffer &other)
int32_t HRESULT
Definition: hresult.h:22
HRESULT InitNoAlloc(uint8_t *pByteArray, size_t nByteArraySize)
Definition: buffer.cpp:74
HRESULT SetSize(size_t size)
Definition: buffer.cpp:126
void Reset()
Definition: buffer.cpp:32
size_t GetAllocatedSize()
Definition: buffer.h:55
size_t _allocatedSize
Definition: buffer.h:32
boost::scoped_array< uint8_t > _spAllocation
Definition: buffer.h:33
boost::shared_ptr< CBuffer > CRefCountedBuffer
Definition: buffer.h:65