FastUIDraw
data_buffer.hpp
Go to the documentation of this file.
1 /*!
2  * \file data_buffer.hpp
3  * \brief file data_buffer.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 #ifndef FASTUIDRAW_DATA_BUFFER_HPP
20 #define FASTUIDRAW_DATA_BUFFER_HPP
21 
23 
24 namespace fastuidraw {
25 /*!\addtogroup Utility
26  * @{
27  */
28  /*!
29  * \brief
30  * Represents a buffer directly stored in memory.
31  */
33  {
34  public:
35  /*!
36  * Ctor.
37  * Copies a file into memory.
38  * \param filename name of file to open
39  */
41 
42  /*!
43  * Ctor. Allocate memory and fill the buffer
44  * with a fixed value.
45  * \param num_bytes number of bytes to give the backing store
46  * \param init initial value to give each byte
47  */
48  explicit
49  DataBufferBackingStore(unsigned int num_bytes, uint8_t init = uint8_t(0));
50 
51  /*!
52  * Ctor. Allocates the memory and initializes it with data.
53  */
54  explicit
56 
58 
59  /*!
60  * Return a pointer to the backing store of the memory.
61  */
63  data(void);
64 
65  private:
66  void *m_d;
67  };
68 
69  /*!
70  * \brief
71  * DataBuffer is an implementation of DataBufferBase where the
72  * data is directly backed by memory
73  */
74  class DataBuffer:
75  private DataBufferBackingStore,
76  public DataBufferBase
77  {
78  public:
79  /*!
80  * Ctor. Initialize the DataBuffer to be backed by uninitalized
81  * memory. Use the pointer returned by data() to set the data.
82  * \param num_bytes number of bytes to give the backing store
83  * \param init initial value to give each byte
84  */
85  explicit
86  DataBuffer(unsigned int num_bytes, uint8_t init = uint8_t(0)):
87  DataBufferBackingStore(num_bytes, init),
89  {}
90 
91  /*!
92  * Ctor. Initialize the DataBuffer to be backed by memory
93  * whose value is copied from a file.
94  */
95  explicit
96  DataBuffer(c_string filename):
97  DataBufferBackingStore(filename),
99  {}
100 
101  /*!
102  * Ctor. Initialize the DataBuffer to be backed by memory
103  * whose value is copied from a file.
104  */
105  explicit
107  DataBufferBackingStore(init_data),
108  DataBufferBase(data(), data())
109  {}
110  };
111 
112 /*! @} */
113 } //namespace fastuidraw
114 
115 #endif
DataBuffer(c_array< const uint8_t > init_data)
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
Represents a buffer directly stored in memory.
Definition: data_buffer.hpp:32
DataBuffer is an implementation of DataBufferBase where the data is directly backed by memory...
Definition: data_buffer.hpp:74
DataBuffer(c_string filename)
Definition: data_buffer.hpp:96
DataBufferBackingStore(c_string filename)
c_array< uint8_t > data(void)
DataBuffer(unsigned int num_bytes, uint8_t init=uint8_t(0))
Definition: data_buffer.hpp:86
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
Base class for passing around buffers of data; derived classes have the responsibility of maintaining...
file data_buffer_base.hpp