databuffer.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #include <memory>
33
34 namespace clan
35 {
38
39 class DataBuffer_Impl;
40
42 class DataBuffer
43 {
46 public:
48 DataBuffer();
49 DataBuffer(unsigned int size);
50 DataBuffer(const void *data, unsigned int size);
51 DataBuffer(const DataBuffer &data, unsigned int pos, unsigned int size);
52 ~DataBuffer();
54
57 public:
59 char *get_data();
60
61 const char *get_data() const;
62
63 template<typename Type>
64 Type *get_data() { return reinterpret_cast<Type*>(get_data()); }
65
66 template<typename Type>
67 const Type *get_data() const { return reinterpret_cast<const Type*>(get_data()); }
68
70 unsigned int get_size() const;
71
73 unsigned int get_capacity() const;
74
76 char &operator[](int i);
77 const char &operator[](int i) const;
78 char &operator[](unsigned int i);
79 const char &operator[](unsigned int i) const;
80
82 bool is_null() const;
84
87 public:
88 DataBuffer &operator =(const DataBuffer &copy);
89
91 void set_size(unsigned int size);
92
94 void set_capacity(unsigned int capacity);
96
99 private:
100 std::shared_ptr<DataBuffer_Impl> impl;
102 };
103
104 }
105
clan
Definition: clanapp.h:35
clan::DataBuffer::operator=
DataBuffer & operator=(const DataBuffer &copy)
clan::DataBuffer::get_data
char * get_data()
Returns a pointer to the data.
clan::DataBuffer::set_capacity
void set_capacity(unsigned int capacity)
Preallocate enough memory.
clan::DataBuffer::DataBuffer
DataBuffer()
Constructs a data buffer of 0 size.
clan::DataBuffer::~DataBuffer
~DataBuffer()
clan::DataBuffer::get_data
const Type * get_data() const
Definition: databuffer.h:67
clan::DataBuffer::get_capacity
unsigned int get_capacity() const
Returns the capacity of the data buffer object.
clan::DataBuffer::get_data
Type * get_data()
Definition: databuffer.h:64
clan::Key::i
clan::DataBuffer::get_size
unsigned int get_size() const
Returns the size of the data.
clan::DataBuffer::is_null
bool is_null() const
Returns true if the buffer is 0 in size.
clan::DataBuffer::operator[]
char & operator[](int i)
Returns a char in the buffer.
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::DataBuffer::set_size
void set_size(unsigned int size)
Resize the buffer.