FastUIDraw
painter_packed_value.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_packed_value.hpp
3  * \brief file painter_packed_value.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 
20 #ifndef FASTUIDRAW_PAINTER_PACKED_VALUE_HPP
21 #define FASTUIDRAW_PAINTER_PACKED_VALUE_HPP
22 
23 
24 #include <fastuidraw/util/util.hpp>
26 #include <fastuidraw/image.hpp>
27 
28 namespace fastuidraw
29 {
30  class PainterPackedValuePool;
31 
32  template<typename T>
34 
35 /*!\addtogroup PainterShaderData
36  * @{
37  */
38 
39  /*!
40  * \brief
41  * (Private) base class used for PainterPackedValue
42  */
44  {
45  private:
46  friend class PainterPackedValuePool;
47  template<typename> friend class PainterPackedValue;
48 
52 
53  explicit
55 
57  operator=(const PainterPackedValueBase&);
58 
59  void
61 
63  packed_data(void) const;
64 
66  bind_images(void) const;
67 
68  void *m_d;
69  };
70 
71  /*!
72  * \brief
73  * A PainterPackedValue represents a handle to an object that stores
74  * packed state data and tracks if that underlying data is already is
75  * already copied to PainterDraw::m_store.
76  *
77  * If already on a store, then rather than copying the data again, the data
78  * is reused. The object behind the handle is NOT thread safe. In addition
79  * the underlying reference count is not either. Hence any access (even dtor,
80  * copy ctor and equality operator) on a fixed object cannot be done from
81  * multiple threads simutaneously. A fixed PainterPackedValue can be used
82  * by different Painter objects, subject to that the access is done from
83  * same thread.
84  */
85  template<typename T>
87  {
88  private:
89  typedef void (PainterPackedValue::*unspecified_bool_type)(void);
90 
91  public:
92  /*!
93  * Ctor, initializes handle to nullptr, i.e.
94  * no underlying value object.
95  */
97  {}
98 
99  /*!
100  * Swap operation
101  * \param obj object with which to swap
102  */
103  void
105  {
106  PainterPackedValueBase::swap(obj);
107  }
108 
109  /*!
110  * Resets the object to not refer to anything.
111  * Provided as a conveniance, equivalent to
112  * \code
113  * PainterPackedValue tmp;
114  * swap(tmp);
115  * \endcode
116  */
117  void
118  reset(void)
119  {
120  PainterPackedValue tmp;
121  swap(tmp);
122  }
123 
124  /*!
125  * Returns the data of the PainterPackedValue
126  */
128  packed_data(void) const
129  {
130  return PainterPackedValueBase::packed_data();
131  }
132 
133  /*!
134  * Returns the images needed for binding,
135  * only makes sense when T = \ref PainterBrushShaderData
136  */
138  bind_images(void) const
139  {
140  return PainterPackedValueBase::bind_images();
141  }
142 
143  /*!
144  * Used to allow using object as a boolean without
145  * accidentally converting to a boolean (since it
146  * returns a pointer to a function).
147  */
148  operator
149  unspecified_bool_type(void) const
150  {
151  return this->m_d ? &PainterPackedValue::reset : 0;
152  }
153 
154  /*!
155  * Comparison operator to underlying object
156  * storing value.
157  * \param rhs handle to which to compare
158  */
159  bool
160  operator==(const PainterPackedValue &rhs) const
161  {
162  return this->m_d == rhs.m_d;
163  }
164 
165  /*!
166  * Comparison operator to underlying object
167  * storing value.
168  * \param rhs handle to which to compare
169  */
170  bool
171  operator!=(const PainterPackedValue &rhs) const
172  {
173  return this->m_d != rhs.m_d;
174  }
175 
176  /*!
177  * Comparison operator to underlying object
178  * storing value.
179  * \param rhs handle to which to compare
180  */
181  bool
182  operator<(const PainterPackedValue &rhs) const
183  {
184  return this->m_d < rhs.m_d;
185  }
186 
187  /*!
188  * Pointer to opaque data of PainterPackedValueBase, used
189  * internally by fastuidraw. Do not touch!
190  */
191  void*
192  opaque_data(void) const
193  {
194  return this->m_d;
195  }
196 
197  private:
198  friend class PainterPackedValuePool;
199 
200  explicit
201  PainterPackedValue(void *d):
203  {}
204  };
205 
206 /*! @} */
207 }
208 
209 #endif
A PainterPackedValue represents a handle to an object that stores packed state data and tracks if tha...
A PainterPackedValuePool can be used to create PainterPackedValue objects.
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
void swap(PainterPackedValue &obj)
file c_array.hpp
c_array< const reference_counted_ptr< const Image > > bind_images(void) const
bool operator==(const PainterPackedValue &rhs) const
void swap(reference_counted_ptr< T > &lhs, reference_counted_ptr< T > &rhs)
file util.hpp
(Private) base class used for PainterPackedValue
A c_array is a wrapper over a C pointer with a size parameter to facilitate bounds checking and provi...
Definition: c_array.hpp:43
c_array< uvec4 > packed_data(void) const
bool operator!=(const PainterPackedValue &rhs) const
file image.hpp