Boost.UI
User Interface Boost library
strings_box.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_STRINGS_BOX_HPP
9 #define BOOST_UI_STRINGS_BOX_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/widget.hpp>
18 
19 #include <vector>
20 #include <boost/range/begin.hpp>
21 #include <boost/range/end.hpp>
22 #include <boost/range/size.hpp>
23 
24 #include <algorithm> // for std::copy()
25 #include <iterator> // std::back_inserter()
26 
27 namespace boost {
28 namespace ui {
29 
30 #ifndef DOXYGEN
31 
32 namespace detail {
33 
34 template <class Iterator>
35 std::vector<uistring> begin_end_to_vector_uistring(Iterator first, Iterator last)
36 {
37  std::vector<uistring> result;
38  result.reserve(last - first);
39  std::copy(first, last, std::back_inserter(result));
40  return result;
41 }
42 
43 template <class Range>
44 std::vector<uistring> range_to_vector_uistring(const Range& r)
45 {
46  std::vector<uistring> result;
47  result.reserve(boost::size(r));
48  std::copy(boost::begin(r), boost::end(r), std::back_inserter(result));
49  return result;
50 }
51 
52 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
53 template <class T>
54 std::vector<uistring>
55 initializer_list_to_vector_uistring(std::initializer_list<T> list)
56 {
57  std::vector<uistring> result;
58  result.reserve(list.size());
59  std::copy(list.begin(), list.end(), std::back_inserter(result));
60  return result;
61 }
62 #endif
63 
64 } // namespace detail
65 
66 #endif
67 
70 
71 class BOOST_UI_DECL strings_box : public widget
72 {
73 public:
76 
79 
81  static const size_type npos = nindex;
82 
85  uistring at(size_type pos) const;
86 
88  uistring operator[](size_type pos) const;
89 
91  bool empty() const { return size() == 0; }
92 
94  size_type size() const;
95 
97  void clear();
98 
100  strings_box& assign(const std::vector<uistring>& options)
101  { clear(); return append(options); }
102 
103  strings_box& assign(size_type count, const value_type& value)
104  { return assign(std::vector<uistring>(count, value)); }
105 
106  template <class Iterator>
107  strings_box& assign(Iterator first, Iterator last)
108  { return assign(detail::begin_end_to_vector_uistring(first, last)); }
109 
110  template <class Range>
111  strings_box& assign(const Range& r)
112  { return assign(detail::range_to_vector_uistring(r)); }
113 
114 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
115  template <class T>
116  strings_box& assign(std::initializer_list<T> list)
117  { return assign(detail::initializer_list_to_vector_uistring(list)); }
118 #endif
119 
122  strings_box& append(const std::vector<uistring>& options);
123 
124  strings_box& append(size_type count, const value_type& value)
125  { return append(std::vector<uistring>(count, value)); }
126 
127  template <class Iterator>
128  strings_box& append(Iterator first, Iterator last)
129  { return append(detail::begin_end_to_vector_uistring(first, last)); }
130 
131  template <class Range>
132  strings_box& append(const Range& r)
133  { return append(detail::range_to_vector_uistring(r)); }
134 
135 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
136  template <class T>
137  strings_box& append(std::initializer_list<T> list)
138  { return append(detail::initializer_list_to_vector_uistring(list)); }
139 #endif
140 
143  void push_back(const uistring& value);
144 
146  strings_box& select(size_type pos);
147 
148 private:
149  void check_range(size_type pos) const;
150 
151  class native_impl;
152  native_impl* get_native();
153  const native_impl* get_native() const;
154 };
155 
156 } // namespace ui
157 } // namespace boost
158 
159 #endif // BOOST_UI_STRINGS_BOX_HPP
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
config.hpp
Configuration options.
widget.hpp
Widget class.
boost::ui::strings_box::append
strings_box & append(Iterator first, Iterator last)
Appends contents to the end.
Definition: strings_box.hpp:128
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::size
basic_size< coord_type > size
2D size coordinates
Definition: coord.hpp:416
boost::ui::strings_box::assign
strings_box & assign(size_type count, const value_type &value)
Replaces the contents of the container.
Definition: strings_box.hpp:103
boost::ui::strings_box::empty
bool empty() const
Checks whether the container has options.
Definition: strings_box.hpp:91
boost::ui::strings_box::size_type
index_type size_type
Integral type.
Definition: strings_box.hpp:78
boost::ui::nindex
const index_type nindex
Invalid index value.
Definition: event.hpp:50
boost::ui::strings_box::assign
strings_box & assign(std::initializer_list< T > list)
Replaces the contents of the container.
Definition: strings_box.hpp:116
boost::ui::strings_box::assign
strings_box & assign(Iterator first, Iterator last)
Replaces the contents of the container.
Definition: strings_box.hpp:107
boost::ui::strings_box::append
strings_box & append(std::initializer_list< T > list)
Appends contents to the end.
Definition: strings_box.hpp:137
boost::ui::strings_box::value_type
uistring value_type
String type.
Definition: strings_box.hpp:75
boost::ui::strings_box::append
strings_box & append(const Range &r)
Appends contents to the end.
Definition: strings_box.hpp:132
boost::ui::strings_box::assign
strings_box & assign(const std::vector< uistring > &options)
Replaces the contents of the container.
Definition: strings_box.hpp:100
boost::ui::strings_box::assign
strings_box & assign(const Range &r)
Replaces the contents of the container.
Definition: strings_box.hpp:111
boost::ui::strings_box
Abstract widget that holds array of strings.
Definition: strings_box.hpp:71
boost::ui::widget
Base class for all widgets.
Definition: widget.hpp:45
boost::ui::strings_box::append
strings_box & append(size_type count, const value_type &value)
Appends contents to the end.
Definition: strings_box.hpp:124
boost::ui::index_type
int index_type
Integral type for indexing items.
Definition: event.hpp:45