databuffer.h Source File - ClanLib SDK
Description: databuffer.h Source File

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
41 class DataBuffer
42 {
43 public:
45 DataBuffer();
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);
50 ~DataBuffer();
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
76 DataBuffer &operator =(const DataBuffer &copy);
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}
clan::DataBuffer
General purpose data buffer.
Definition databuffer.h:42
clan::DataBuffer::DataBuffer
DataBuffer(size_t size)
clan::DataBuffer::DataBuffer
DataBuffer()
Constructs a data buffer of 0 size.
clan::DataBuffer::operator=
DataBuffer & operator=(const DataBuffer &copy)
clan::DataBuffer::DataBuffer
DataBuffer(const void *data, size_t size)
clan::DataBuffer::operator[]
const char & operator[](size_t i) const
clan::DataBuffer::get_data
Type * get_data()
Definition databuffer.h:58
clan::DataBuffer::is_null
bool is_null() const
Returns true if the buffer is 0 in size.
clan::DataBuffer::operator[]
char & operator[](size_t i)
Returns a char in the buffer.
clan::DataBuffer::set_capacity
void set_capacity(size_t capacity)
Preallocate enough memory.
clan::DataBuffer::get_capacity
size_t get_capacity() const
Returns the capacity of the data buffer object.
clan::DataBuffer::get_data
char * get_data()
Returns a pointer to the data.
clan::DataBuffer::set_size
void set_size(size_t size)
Resize the buffer.
clan::DataBuffer::~DataBuffer
~DataBuffer()
clan::DataBuffer::get_data
const char * get_data() const
clan::DataBuffer::get_size
size_t get_size() const
Returns the size of the data.
clan::DataBuffer::DataBuffer
DataBuffer(const DataBuffer &data, size_t pos, size_t size)
clan::DataBuffer::get_data
const Type * get_data() const
Definition databuffer.h:61
clan::DataBuffer::DataBuffer
DataBuffer(const DataBuffer &copy)
clan
Definition clanapp.h:36
clan::Key::i
@ i