Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
selection.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_SELECTION_HPP
9#define ADOBE_SELECTION_HPP
10
11#include <adobe/config.hpp>
12
13#include <cassert>
14#include <vector>
15
16#include <boost/operators.hpp>
17
18/**************************************************************************************************/
19
20namespace adobe {
21
22/**************************************************************************************************/
27/**************************************************************************************************/
47class selection_t : boost::equality_comparable<selection_t> {
48public:
50 typedef std::size_t value_type;
52 typedef std::vector<value_type> store_type;
54 typedef store_type::const_iterator iterator;
56 typedef store_type::const_iterator const_iterator;
58 typedef store_type::size_type size_type;
60 typedef store_type::difference_type difference_type;
68 typedef const value_type* const_pointer;
69
77 explicit selection_t(bool start_selected = false) : start_selected_m(start_selected) {}
78
89 template <typename I> // value_type(I) == value_type
90 selection_t(I first, I last, bool start_selected = false)
91 : start_selected_m(start_selected), store_m(first, last) {}
92
99 size_type size() const { return store_m.size(); }
100
102 bool empty() const { return store_m.empty() && start_selected_m == false; }
103
106 void push_back(const value_type& x) {
107 assert(store_m.empty() || store_m.back() < x);
108
109 store_m.push_back(x);
110 }
111
113 const_iterator begin() const { return store_m.begin(); }
114
116 const_iterator end() const { return store_m.end(); }
117
119 const value_type& operator[](const size_type& i) const { return store_m[i]; }
120
124 void invert() { start_selected_m = !start_selected_m; }
125
129 bool start_selected() const { return start_selected_m; }
130
131 friend inline bool operator==(const selection_t& x, const selection_t& y) {
132 return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin());
133 }
134
135private:
136#ifndef ADOBE_NO_DOCUMENTATION
137 // This *can* be public because modifying it will not
138 // violate any invariants.
139 bool start_selected_m;
140
141 // The requirement on the index store is that it be sorted.
142 // Thus, we need to provide mechanisms where it stays so.
143 store_type store_m;
144#endif
145};
146
147/**************************************************************************************************/
148
149} // namespace adobe
150
151/**************************************************************************************************/
152
153#endif
154
155/**************************************************************************************************/
std::vector< value_type > store_type
store_type for selection_t
Definition selection.hpp:52
const value_type * const_pointer
const_pointer for selection_t
Definition selection.hpp:68
const value_type & operator[](const size_type &i) const
fetches a toggle point at index i of the toggle point sequence
const_iterator begin() const
gets an iterator to the beginning of the toggle point sequence
friend bool operator==(const selection_t &x, const selection_t &y)
size_type size() const
Definition selection.hpp:99
bool empty() const
store_type::const_iterator iterator
iterator for selection_t
Definition selection.hpp:54
void push_back(const value_type &x)
store_type::size_type size_type
size_type for selection_t
Definition selection.hpp:58
selection_t(I first, I last, bool start_selected=false)
Definition selection.hpp:90
bool start_selected() const
value_type & reference
reference for selection_t
Definition selection.hpp:62
selection_t(bool start_selected=false)
Definition selection.hpp:77
store_type::difference_type difference_type
difference_type for selection_t
Definition selection.hpp:60
const_iterator end() const
gets an iterator to the end of the toggle point sequence
value_type * pointer
pointer for selection_t
Definition selection.hpp:66
std::size_t value_type
value_type for selection_t
Definition selection.hpp:50
store_type::const_iterator const_iterator
const_iterator for selection_t
Definition selection.hpp:56
const value_type & const_reference
const_reference for selection_t
Definition selection.hpp:64