stlab.adobe.com Adobe Systems Incorporated
selection.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_SELECTION_HPP
10 #define ADOBE_SELECTION_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <vector>
15 #include <cassert>
16 
17 #include <boost/operators.hpp>
18 
19 /*************************************************************************************************/
20 
21 namespace adobe {
22 
23 /****************************************************************************************************/
28 /****************************************************************************************************/
48 class selection_t : boost::equality_comparable<selection_t>
49 {
50 public:
52  typedef std::size_t value_type;
54  typedef std::vector<value_type> store_type;
56  typedef store_type::iterator iterator;
58  typedef store_type::const_iterator const_iterator;
60  typedef store_type::size_type size_type;
62  typedef store_type::difference_type difference_type;
66  typedef const value_type& const_reference;
68  typedef value_type* pointer;
70  typedef const value_type* const_pointer;
71 
79  explicit selection_t(bool start_selected = false) :
80  start_selected_m(start_selected)
81  { }
82 
93  template <typename I> // value_type(I) == value_type
94  selection_t(I first, I last, bool start_selected = false) :
95  start_selected_m(start_selected),
96  store_m(first, last)
97  { }
98 
104  size_type size() const
105  { return store_m.size(); }
106 
108  bool empty() const
109  { return store_m.empty() && start_selected_m == false; }
110 
113  void push_back(const value_type& x)
114  {
115  assert(empty() || store_m.back() < x);
116 
117  store_m.push_back(x);
118  }
119 
121  const_iterator begin() const { return store_m.begin(); }
122 
124  const_iterator end() const { return store_m.end(); }
125 
127  const value_type& operator[](const size_type& i) const
128  { return store_m[i]; }
129 
133  void invert()
134  { start_selected_m = !start_selected_m; }
135 
139  bool start_selected() const
140  { return start_selected_m; }
141 
142  friend inline bool operator==(const selection_t& x, const selection_t& y)
143  {
144  return x.size() == y.size() &&
145  std::equal(x.begin(), x.end(), y.begin());
146  }
147 
148 private:
149 #ifndef ADOBE_NO_DOCUMENTATION
150  // This *can* be public because modifying it will not
151  // violate any invariants.
152  bool start_selected_m;
153 
154  // The requirement on the index store is that it be sorted.
155  // Thus, we need to provide mechanisms where it stays so.
156  store_type store_m;
157 #endif
158 };
159 
160 /*************************************************************************************************/
161 
162 } // namespace adobe
163 
164 /*************************************************************************************************/
165 
166 #endif
167 
168 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google