databuffer.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_core.h"
33 #include <memory>
34 
35 namespace clan
36 {
39 
40 class DataBuffer_Impl;
41 
43 class CL_API_CORE DataBuffer
44 {
47 public:
49  DataBuffer();
50  DataBuffer(unsigned int size);
51  DataBuffer(const void *data, unsigned int size);
52  DataBuffer(const DataBuffer &data, unsigned int pos, unsigned int size);
53  ~DataBuffer();
55 
58 public:
60  char *get_data();
61 
62  const char *get_data() const;
63 
64  template<typename Type>
65  Type *get_data() { return reinterpret_cast<Type*>(get_data()); }
66 
67  template<typename Type>
68  const Type *get_data() const { return reinterpret_cast<const Type*>(get_data()); }
69 
71  unsigned int get_size() const;
72 
74  unsigned int get_capacity() const;
75 
77  char &operator[](int i);
78  const char &operator[](int i) const;
79  char &operator[](unsigned int i);
80  const char &operator[](unsigned int i) const;
81 
83  bool is_null() const;
85 
88 public:
89  DataBuffer &operator =(const DataBuffer &copy);
90 
92  void set_size(unsigned int size);
93 
95  void set_capacity(unsigned int capacity);
97 
100 private:
101  std::shared_ptr<DataBuffer_Impl> impl;
103 };
104 
105 }
106 
const Type * get_data() const
Definition: databuffer.h:68
Type * get_data()
Definition: databuffer.h:65
General purpose data buffer.
Definition: databuffer.h:43