databuffer.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31#include <memory>
32
33namespace clan
34{
37
38 class DataBuffer_Impl;
39
42 {
43 public:
46 DataBuffer(size_t size);
47 DataBuffer(const DataBuffer &copy);
48 DataBuffer(const void *data, size_t size);
49 DataBuffer(const DataBuffer &data, size_t pos, size_t size);
51
53 char *get_data();
54
55 const char *get_data() const;
56
57 template<typename Type>
58 Type *get_data() { return reinterpret_cast<Type*>(get_data()); }
59
60 template<typename Type>
61 const Type *get_data() const { return reinterpret_cast<const Type*>(get_data()); }
62
64 size_t get_size() const;
65
67 size_t get_capacity() const;
68
70 char &operator[](size_t i);
71 const char &operator[](size_t i) const;
72
74 bool is_null() const;
75
77
79 void set_size(size_t size);
80
82 void set_capacity(size_t capacity);
83
84 private:
85 std::shared_ptr<DataBuffer_Impl> impl;
86 };
87
89}
General purpose data buffer.
Definition databuffer.h:42
DataBuffer(size_t size)
DataBuffer()
Constructs a data buffer of 0 size.
DataBuffer & operator=(const DataBuffer &copy)
DataBuffer(const void *data, size_t size)
const char & operator[](size_t i) const
Type * get_data()
Definition databuffer.h:58
bool is_null() const
Returns true if the buffer is 0 in size.
char & operator[](size_t i)
Returns a char in the buffer.
void set_capacity(size_t capacity)
Preallocate enough memory.
size_t get_capacity() const
Returns the capacity of the data buffer object.
char * get_data()
Returns a pointer to the data.
void set_size(size_t size)
Resize the buffer.
const char * get_data() const
size_t get_size() const
Returns the size of the data.
DataBuffer(const DataBuffer &data, size_t pos, size_t size)
const Type * get_data() const
Definition databuffer.h:61
DataBuffer(const DataBuffer &copy)
Definition clanapp.h:36