1/*!
2 * \file colorstop.cpp
3 * \brief file colorstop.cpp
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#include <algorithm>
21#include <vector>
22#include <fastuidraw/util/fastuidraw_memory.hpp>
23#include <fastuidraw/colorstop.hpp>
24#include <private/util_private.hpp>
25
26namespace
27{
28 class ColorStopArrayPrivate
29 {
30 public:
31 ColorStopArrayPrivate(void):
32 m_dirty(true)
33 {}
34
35 explicit
36 ColorStopArrayPrivate(int rev):
37 m_dirty(true)
38 {
39 m_values.reserve(rev);
40 }
41
42 std::vector<fastuidraw::ColorStop> m_values;
43 bool m_dirty;
44 };
45}
46
47
48/////////////////////////////////////
49// fastuidraw::ColorStopArray methods
50fastuidraw::ColorStopArray::
51ColorStopArray(void):
52 m_d(FASTUIDRAWnew ColorStopArrayPrivate())
53{}
54
55fastuidraw::ColorStopArray::
56ColorStopArray(int reserve):
57 m_d(FASTUIDRAWnew ColorStopArrayPrivate(reserve))
58{}
59
60fastuidraw::ColorStopArray::
61~ColorStopArray()
62{
63 ColorStopArrayPrivate *d;
64 d = static_cast<ColorStopArrayPrivate*>(m_d);
65 FASTUIDRAWdelete(d);
66}
67
68void
69fastuidraw::ColorStopArray::
70add(const ColorStop &c)
71{
72 ColorStopArrayPrivate *d;
73 d = static_cast<ColorStopArrayPrivate*>(m_d);
74 d->m_dirty = true;
75 d->m_values.push_back(c);
76}
77
78void
79fastuidraw::ColorStopArray::
80clear(void)
81{
82 ColorStopArrayPrivate *d;
83 d = static_cast<ColorStopArrayPrivate*>(m_d);
84 d->m_dirty = true;
85 d->m_values.clear();
86}
87
88fastuidraw::c_array<const fastuidraw::ColorStop>
89fastuidraw::ColorStopArray::
90values(void) const
91{
92 ColorStopArrayPrivate *d;
93 d = static_cast<ColorStopArrayPrivate*>(m_d);
94 if (d->m_dirty)
95 {
96 d->m_dirty = false;
97 std::stable_sort(d->m_values.begin(), d->m_values.end());
98 }
99 return make_c_array(d->m_values);
100}
101