selection.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_SELECTION_HPP 00010 #define ADOBE_SELECTION_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <vector> 00015 #include <cassert> 00016 00017 #include <boost/operators.hpp> 00018 00019 /*************************************************************************************************/ 00020 00021 namespace adobe { 00022 00023 /****************************************************************************************************/ 00028 /****************************************************************************************************/ 00048 class selection_t : boost::equality_comparable<selection_t> 00049 { 00050 public: 00052 typedef std::size_t value_type; 00054 typedef std::vector<value_type> store_type; 00056 typedef store_type::iterator iterator; 00058 typedef store_type::const_iterator const_iterator; 00060 typedef store_type::size_type size_type; 00062 typedef store_type::difference_type difference_type; 00064 typedef value_type& reference; 00066 typedef const value_type& const_reference; 00068 typedef value_type* pointer; 00070 typedef const value_type* const_pointer; 00071 00079 explicit selection_t(bool start_selected = false) : 00080 start_selected_m(start_selected) 00081 { } 00082 00093 template <typename I> // value_type(I) == value_type 00094 selection_t(I first, I last, bool start_selected = false) : 00095 start_selected_m(start_selected), 00096 store_m(first, last) 00097 { } 00098 00104 size_type size() const 00105 { return store_m.size(); } 00106 00108 bool empty() const 00109 { return store_m.empty() && start_selected_m == false; } 00110 00113 void push_back(const value_type& x) 00114 { 00115 assert(empty() || store_m.back() < x); 00116 00117 store_m.push_back(x); 00118 } 00119 00121 const_iterator begin() const { return store_m.begin(); } 00122 00124 const_iterator end() const { return store_m.end(); } 00125 00127 const value_type& operator[](const size_type& i) const 00128 { return store_m[i]; } 00129 00133 void invert() 00134 { start_selected_m = !start_selected_m; } 00135 00139 bool start_selected() const 00140 { return start_selected_m; } 00141 00142 friend inline bool operator==(const selection_t& x, const selection_t& y) 00143 { 00144 return x.size() == y.size() && 00145 std::equal(x.begin(), x.end(), y.begin()); 00146 } 00147 00148 private: 00149 #ifndef ADOBE_NO_DOCUMENTATION 00150 // This *can* be public because modifying it will not 00151 // violate any invariants. 00152 bool start_selected_m; 00153 00154 // The requirement on the index store is that it be sorted. 00155 // Thus, we need to provide mechanisms where it stays so. 00156 store_type store_m; 00157 #endif 00158 }; 00159 00160 /*************************************************************************************************/ 00161 00162 } // namespace adobe 00163 00164 /*************************************************************************************************/ 00165 00166 #endif 00167 00168 /*************************************************************************************************/ |