summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvitor.sousa <vitorsousasilva@gmail.com>2014-06-04 22:34:42 +0200
committerCedric BAIL <c.bail@partner.samsung.com>2014-06-04 22:34:47 +0200
commit0902b6a6f8ce10aefc9c19d455fd5c176e2bd53a (patch)
tree33d4493ae8d0519886bbb7c487a88fafbef8ce59
parent5e7a9b1225f792a6a7e60e96cf402440ad1adfff (diff)
eina_cxx: add documentation to the Eina C++ header files.
Summary: Added documentation to almost all classes that are intended for direct use by the library users. Marked classes/functions used by the library itself as @internal. Modified the Doxyfile.in to enable the generation of documentation to the bindings. Reviewers: felipealmeida, cedric, woohyun, smohanty, raster CC: savio, cedric Differential Revision: https://phab.enlightenment.org/D947 Signed-off-by: Cedric BAIL <c.bail@partner.samsung.com>
-rw-r--r--doc/Doxyfile.in4
-rw-r--r--src/bindings/eina_cxx/Eina.hh44
-rw-r--r--src/bindings/eina_cxx/eina_accessor.hh298
-rw-r--r--src/bindings/eina_cxx/eina_clone_allocators.hh58
-rw-r--r--src/bindings/eina_cxx/eina_error.hh155
-rw-r--r--src/bindings/eina_cxx/eina_inarray.hh1118
-rw-r--r--src/bindings/eina_cxx/eina_inlist.hh610
-rw-r--r--src/bindings/eina_cxx/eina_integer_sequence.hh46
-rw-r--r--src/bindings/eina_cxx/eina_iterator.hh144
-rw-r--r--src/bindings/eina_cxx/eina_lists_auxiliary.hh16
-rw-r--r--src/bindings/eina_cxx/eina_log.hh229
-rw-r--r--src/bindings/eina_cxx/eina_optional.hh233
-rw-r--r--src/bindings/eina_cxx/eina_ptrarray.hh670
-rw-r--r--src/bindings/eina_cxx/eina_ptrlist.hh704
-rw-r--r--src/bindings/eina_cxx/eina_range_types.hh294
-rw-r--r--src/bindings/eina_cxx/eina_ref.hh53
-rw-r--r--src/bindings/eina_cxx/eina_stringshare.hh331
-rw-r--r--src/bindings/eina_cxx/eina_thread.hh454
-rw-r--r--src/bindings/eina_cxx/eina_type_traits.hh20
-rw-r--r--src/bindings/eina_cxx/eina_value.hh252
20 files changed, 5541 insertions, 192 deletions
diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
index 0086929..a1b2c0c 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -594,6 +594,7 @@ WARN_LOGFILE =
594# with spaces. 594# with spaces.
595 595
596INPUT = @top_srcdir@/src/lib \ 596INPUT = @top_srcdir@/src/lib \
597 @top_srcdir@/src/bindings \
597 @srcdir@/main.dox \ 598 @srcdir@/main.dox \
598 @srcdir@/pkgconfig.dox \ 599 @srcdir@/pkgconfig.dox \
599 @srcdir@/eina_examples.dox \ 600 @srcdir@/eina_examples.dox \
@@ -626,7 +627,8 @@ INPUT_ENCODING = UTF-8
626 627
627FILE_PATTERNS = *.c \ 628FILE_PATTERNS = *.c \
628 *.h \ 629 *.h \
629 *.x 630 *.x \
631 *.hh
630 632
631# The RECURSIVE tag can be used to turn specify whether or not subdirectories 633# The RECURSIVE tag can be used to turn specify whether or not subdirectories
632# should be searched for input files as well. Possible values are YES and NO. 634# should be searched for input files as well. Possible values are YES and NO.
diff --git a/src/bindings/eina_cxx/Eina.hh b/src/bindings/eina_cxx/Eina.hh
index 9ba0ca3..ed25c3c 100644
--- a/src/bindings/eina_cxx/Eina.hh
+++ b/src/bindings/eina_cxx/Eina.hh
@@ -1,6 +1,11 @@
1#ifndef EINA_HH_ 1#ifndef EINA_HH_
2#define EINA_HH_ 2#define EINA_HH_
3 3
4/**
5 * @file
6 * @brief Eina C++
7 */
8
4#include <eina_iterator.hh> 9#include <eina_iterator.hh>
5#include <eina_ptrarray.hh> 10#include <eina_ptrarray.hh>
6#include <eina_ptrlist.hh> 11#include <eina_ptrlist.hh>
@@ -16,8 +21,37 @@
16#include <eina_optional.hh> 21#include <eina_optional.hh>
17#include <eina_integer_sequence.hh> 22#include <eina_integer_sequence.hh>
18 23
24/**
25 * @defgroup Eina_Cxx Eina C++
26 *
27 * @defgroup Eina_Cxx_Data_Types_Group Data Types
28 * @ingroup Eina_Cxx
29 *
30 * @defgroup Eina_Cxx_Content_Access_Group Content Access
31 * @ingroup Eina_Cxx_Data_Types_Group
32 *
33 * @defgroup Eina_Cxx_Containers_Group Containers
34 * @ingroup Eina_Cxx_Data_Types_Group
35 *
36 * @defgroup Eina_Cxx_Tools_Group Tools
37 * @ingroup Eina_Cxx
38 *
39 */
40
19namespace efl { namespace eina { 41namespace efl { namespace eina {
20 42
43/**
44 * @addtogroup Eina_Cxx
45 *
46 * @{
47 */
48
49/**
50 * @brief Initialize the Eina library.
51 *
52 * Initialize all the Eina modules upon construction and finalize them
53 * upon destruction, using the RAII programming idiom.
54 */
21struct eina_init 55struct eina_init
22{ 56{
23 eina_init() 57 eina_init()
@@ -30,6 +64,12 @@ struct eina_init
30 } 64 }
31}; 65};
32 66
67/**
68 * @brief Initialize the mutexes of the Eina library.
69 *
70 * Set up all the mutexes in all Eina modules upon construction and
71 * shut them down upon destruction, using the RAII programming idiom.
72 */
33struct eina_threads_init 73struct eina_threads_init
34{ 74{
35 eina_threads_init() 75 eina_threads_init()
@@ -42,6 +82,10 @@ struct eina_threads_init
42 } 82 }
43}; 83};
44 84
85/**
86 * @}
87 */
88
45} } 89} }
46 90
47#endif 91#endif
diff --git a/src/bindings/eina_cxx/eina_accessor.hh b/src/bindings/eina_cxx/eina_accessor.hh
index 5798c9b..22b4841 100644
--- a/src/bindings/eina_cxx/eina_accessor.hh
+++ b/src/bindings/eina_cxx/eina_accessor.hh
@@ -9,25 +9,82 @@
9#include <cstdlib> 9#include <cstdlib>
10#include <cassert> 10#include <cassert>
11 11
12/**
13 * @addtogroup Eina_Cxx_Content_Access_Group
14 *
15 * @{
16 */
17
12namespace efl { namespace eina { 18namespace efl { namespace eina {
13 19
20/**
21 * @defgroup Eina_Cxx_Accessor_Group Accessor
22 * @ingroup Eina_Cxx_Content_Access_Group
23 *
24 * @brief These classes manage accessor on containers.
25 *
26 * These classes allow to access elements of a container in a
27 * generic way, without knowing which container is used (like
28 * iterators in the C++ STL). Accessors allows random access (that is, any
29 * element in the container). For sequential access, see
30 * @ref Eina_Cxx_Iterator_Group.
31 *
32 * @{
33 */
34
35/**
36 * Wraps an native Eina_Accessor and provide random access to data structures.
37 */
14template <typename T> 38template <typename T>
15struct accessor 39struct accessor
16{ 40{
17 typedef unsigned int key_type; 41 typedef unsigned int key_type; /**< Type for accessor key. */
18 typedef T mapped_type; 42 typedef T mapped_type; /**< Type for accessor mapped elements. */
19 typedef T value_type; 43 typedef T value_type; /**< Type for accessor elements. Same as @ref mapped_type. */
20 typedef std::size_t size_type; 44 typedef std::size_t size_type; /**< Type for size information used in the accessor. */
21 45
46 /**
47 * @brief Default constructor. Creates an empty accessor.
48 */
22 accessor() : _impl(0) {} 49 accessor() : _impl(0) {}
50
51 /**
52 * @brief Create an accessor object that wraps the given Eina accessor.
53 * @param impl Native @c Eina_Accessor to be wrapped.
54 *
55 * This constructor creates an accessor object that wraps the given
56 * Eina_Accessor and provides access to the data pointed by it.
57 *
58 * @warning It is important to note that the created accessor object
59 * gains ownership of the given handle, deallocating it at destruction
60 * time.
61 */
23 explicit accessor(Eina_Accessor* impl) 62 explicit accessor(Eina_Accessor* impl)
24 : _impl(impl) 63 : _impl(impl)
25 { 64 {
26 assert(_impl != 0); 65 assert(_impl != 0);
27 } 66 }
67
68 /**
69 * @brief Copy constructor. Creates a copy of the given accessor object.
70 * @param other Other accessor object.
71 *
72 * This constructor clones the internal @c Eina_Accessor of the given
73 * accessor object, so that the newly created object can be used
74 * freely.
75 */
28 accessor(accessor<T> const& other) 76 accessor(accessor<T> const& other)
29 : _impl(eina_accessor_clone(other._impl)) 77 : _impl(eina_accessor_clone(other._impl))
30 {} 78 {}
79
80 /**
81 * @brief Assignment Operator. Replace the current content.
82 * @param other Other accessor object.
83 * @throw <tt>eina::system_error</tt> if the Eina accessor could not be cloned.
84 *
85 * This operator replaces the current native Eina accessor by a copy
86 * of the native accessor inside the given object.
87 */
31 accessor<T>& operator=(accessor<T> const& other) 88 accessor<T>& operator=(accessor<T> const& other)
32 { 89 {
33 eina_accessor_free(_impl); 90 eina_accessor_free(_impl);
@@ -36,11 +93,25 @@ struct accessor
36 throw eina::system_error(efl::eina::get_error_code(), "Error cloning accessor"); 93 throw eina::system_error(efl::eina::get_error_code(), "Error cloning accessor");
37 return *this; 94 return *this;
38 } 95 }
96
97 /**
98 * @brief Destructor. Free the internal @c Eina_Acessor.
99 */
39 ~accessor() 100 ~accessor()
40 { 101 {
41 eina_accessor_free(_impl); 102 eina_accessor_free(_impl);
42 } 103 }
43 104
105 /**
106 * @brief Retrieve the data of the accessor at a given position.
107 * @param i The position of the element.
108 * @return Constant reference to the retrieved data.
109 * @throw <tt>eina::system_error</tt> if the given element could not be retrieved.
110 *
111 * This operator retrieves a constant reference to the element at the
112 * given position. If the element could not be retrieved an
113 * <tt>eina::system_error</tt> is thrown.
114 */
44 mapped_type& operator[](size_type i) const 115 mapped_type& operator[](size_type i) const
45 { 116 {
46 assert(_impl != 0); 117 assert(_impl != 0);
@@ -53,98 +124,242 @@ struct accessor
53 return *static_cast<mapped_type*>(p); 124 return *static_cast<mapped_type*>(p);
54 } 125 }
55 126
127 /**
128 * @brief Get the handle for the wrapped @c Eina_Accessor.
129 * @return Internal handle for the native Eina accessor.
130 *
131 * This member function returns the native @c Eina_Accessor handle
132 * that is wrapped inside this object.
133 *
134 * @warning It is important to take care when using it, since the
135 * handle will be automatically release upon object destruction.
136 */
56 Eina_Accessor* native_handle() const; 137 Eina_Accessor* native_handle() const;
57 138
139 /**
140 * @brief Swap content between both objects.
141 * @param other Other accessor object.
142 *
143 * This member function swaps the internal @c Eina_Acessor with the
144 * given accessor object.
145 */
58 void swap(accessor<T>& other) 146 void swap(accessor<T>& other)
59 { 147 {
60 std::swap(_impl, other._impl); 148 std::swap(_impl, other._impl);
61 } 149 }
150 /**
151 * @brief Cast to @c boolean based on the wrapped @c Eina_Accessor.
152 * @return @c true if the wrapped handle is not @c NULL, @c false otherwise.
153 *
154 * Boolean typecast overload for easy validation of the accessor
155 * object. Returns @c false if it does not have an internal
156 * @c Eina_Accessor, i.e. if the current handle is not @c NULL.
157 */
62 explicit operator bool() const 158 explicit operator bool() const
63 { 159 {
64 return native_handle() ? &accessor<T>::native_handle : 0 ; 160 return native_handle() ? &accessor<T>::native_handle : 0 ;
65 } 161 }
66private: 162private:
163
164 /**
165 * @internal
166 * Member variable for storing the native Eina_Accessor pointer.
167 */
67 Eina_Accessor* _impl; 168 Eina_Accessor* _impl;
68}; 169};
69 170
171/**
172 * @brief Swap the contents of the two accessor objects.
173 * @param lhs First accessor object.
174 * @param rhs Second accessor object.
175 */
70template <typename U> 176template <typename U>
71void swap(accessor<U>& lhs, accessor<U>& rhs) 177void swap(accessor<U>& lhs, accessor<U>& rhs)
72{ 178{
73 lhs.swap(rhs); 179 lhs.swap(rhs);
74} 180}
75 181
182/**
183 * @}
184 */
185
186/**
187 * @defgroup Eina_Cxx_Accessor_Iterator_Group Accessor Iterator
188 * @ingroup Eina_Cxx_Content_Access_Group
189 *
190 * @{
191 */
192
193/**
194 * Random access iterator for <tt>eina::accessor</tt>.
195 */
76template <typename T> 196template <typename T>
77struct accessor_iterator 197struct accessor_iterator
78{ 198{
79 typedef T value_type; 199 typedef T value_type; /**< Type of the elements. */
80 typedef value_type* pointer; 200 typedef value_type* pointer; /**< Pointer to element type. */
81 typedef value_type& reference; 201 typedef value_type& reference; /**< Reference to element type. */
82 typedef std::ptrdiff_t difference_type; 202 typedef std::ptrdiff_t difference_type; /**< Type to represent the distance between two @ref accessor_iterators */
83 typedef std::random_access_iterator_tag iterator_category; 203 typedef std::random_access_iterator_tag iterator_category; /**< Defines the iterator as being a random access iterator. */
204
84 205
206 /**
207 * @brief Creates an @c accessor_iterator to the given <tt>eina::accessor</tt>.
208 * @param a <tt>eina::accessor</tt> object.
209 * @param pos Initial position of the iterator (Default = @c 0).
210 *
211 * This constructor creates an @c accessor_iterator for the given
212 * <tt>eina::accessor</tt> object. The position initially pointed by
213 * the iterator can be supplied via the @p pos argument, by default
214 * it is the first position (index @c 0).
215 */
85 accessor_iterator(accessor<T> const& a, unsigned int pos = 0u) 216 accessor_iterator(accessor<T> const& a, unsigned int pos = 0u)
86 : _accessor(a), _index(pos) 217 : _accessor(a), _index(pos)
87 {} 218 {}
88 219
220 /**
221 * @brief Move the iterator forward by @p i positions.
222 * @param i Number of positions to move.
223 * @return The @c accessor_iterator itself.
224 */
89 accessor_iterator<T>& operator+=(difference_type i) 225 accessor_iterator<T>& operator+=(difference_type i)
90 { 226 {
91 _index += i; 227 _index += i;
92 return *this; 228 return *this;
93 } 229 }
230
231 /**
232 * @brief Move the iterator back by @p i positions.
233 * @param i Number of positions to move.
234 * @return The @c accessor_iterator itself.
235 */
94 accessor_iterator<T>& operator-=(difference_type i) 236 accessor_iterator<T>& operator-=(difference_type i)
95 { 237 {
96 _index -= i; 238 _index -= i;
97 return *this; 239 return *this;
98 } 240 }
241
242 /**
243 * @brief Get the element @p i positions away from the current element.
244 * @param i Position relative to the current element.
245 * @return Reference to the element @p i positions away from the
246 * element currently pointed by the @c accessor_iterator.
247 */
99 value_type& operator[](difference_type i) 248 value_type& operator[](difference_type i)
100 { 249 {
101 return _accessor[_index + i]; 250 return _accessor[_index + i];
102 } 251 }
252
253 /**
254 * @brief Move the iterator to the next position.
255 * @return The @c accessor_iterator itself.
256 *
257 * This operator increments the iterator, making it point to the
258 * position right after the current one.
259 * At the end, it returns a reference to itself.
260 */
103 accessor_iterator<T>& operator++() 261 accessor_iterator<T>& operator++()
104 { 262 {
105 ++_index; 263 ++_index;
106 return *this; 264 return *this;
107 } 265 }
266
267 /**
268 * @brief Move the iterator to the previous position.
269 * @return The @c accessor_iterator itself.
270 *
271 * This operator decrements the iterator, making it point to the
272 * position right before the current one.
273 * At the end, it returns a reference to itself.
274 */
108 accessor_iterator<T>& operator--() 275 accessor_iterator<T>& operator--()
109 { 276 {
110 --_index; 277 --_index;
111 return *this; 278 return *this;
112 } 279 }
280
281 /**
282 * @brief Move the iterator to the next position.
283 * @return A copy of the @c accessor_iterator before the change.
284 *
285 * This operator increments the iterator, making it point to the
286 * position right after the current one.
287 * At the end, it returns a copy of the @c accessor_iterator before
288 * the change.
289 */
113 accessor_iterator<T>& operator++(int) 290 accessor_iterator<T>& operator++(int)
114 { 291 {
115 accessor_iterator<T> tmp(*this); 292 accessor_iterator<T> tmp(*this);
116 ++*this; 293 ++*this;
117 return tmp; 294 return tmp;
118 } 295 }
296
297 /**
298 * @brief Move the iterator to the previous position.
299 * @return A copy of the @c accessor_iterator before the change.
300 *
301 * This operator decrements the iterator, making it point to the
302 * position right before the current one.
303 * At the end, it returns a copy of the @c accessor_iterator before
304 * the change.
305 */
119 accessor_iterator<T>& operator--(int) 306 accessor_iterator<T>& operator--(int)
120 { 307 {
121 accessor_iterator<T> tmp(*this); 308 accessor_iterator<T> tmp(*this);
122 --*this; 309 --*this;
123 return tmp; 310 return tmp;
124 } 311 }
312
313 /**
314 * @brief Get a reference to the element currently pointed by the @c accessor_iterator.
315 * @return Reference to the current element.
316 */
125 value_type& operator*() const 317 value_type& operator*() const
126 { 318 {
127 return _accessor[_index]; 319 return _accessor[_index];
128 } 320 }
321
322 /**
323 * @brief Return a pointer to the current element, which member will be accessed.
324 * @return Pointer to the element currently pointed by the @c accessor_iterator.
325 */
129 pointer operator->() const 326 pointer operator->() const
130 { 327 {
131 return &**this; 328 return &**this;
132 } 329 }
330
331 /**
332 * @brief Swap content with the given @c accessor_iterator.
333 * @param other Another @c accessor_iterator of the same type.
334 */
133 void swap(accessor_iterator<T>& other) 335 void swap(accessor_iterator<T>& other)
134 { 336 {
135 std::swap(_index, other._index); 337 std::swap(_index, other._index);
136 std::swap(_accessor, other._accessor); 338 std::swap(_accessor, other._accessor);
137 } 339 }
340
138private: 341private:
139 accessor<T> _accessor; 342 accessor<T> _accessor; /**< @internal */
140 unsigned int _index; 343 unsigned int _index; /**< @internal */
141 344
345 /**
346 * @brief Check if @p lhs and @p rhs point to the same position.
347 * @param lhs @c accessor_iterator at the left side of the expression.
348 * @param rhs @c accessor_iterator at the right side of the expression.
349 * @return @c true if both @p lhs and @p rhs point to the same position.
350 */
142 template <typename U> 351 template <typename U>
143 friend bool operator==(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 352 friend bool operator==(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
144 { 353 {
145 return lhs._index == rhs._index; 354 return lhs._index == rhs._index;
146 } 355 }
147 356
357 /**
358 * @brief Get the distance between two <tt>accessor_iterator</tt>s.
359 * @param lhs @c accessor_iterator at the left side of the expression.
360 * @param rhs @c accessor_iterator at the right side of the expression.
361 * @return The number of elements between @p lhs and @p rhs.
362 */
148 template <typename U> 363 template <typename U>
149 friend typename accessor_iterator<U>::difference_type 364 friend typename accessor_iterator<U>::difference_type
150 operator-(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 365 operator-(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
@@ -152,6 +367,12 @@ private:
152 return lhs._index - rhs._index; 367 return lhs._index - rhs._index;
153 } 368 }
154 369
370 /**
371 * @brief Get an @c accessor_iterator moved @p rhs positions forward.
372 * @param lhs @c accessor_iterator object.
373 * @param rhs Number of positions relative to the current element.
374 * @return Copy of @p lhs moved @p rhs positions forward.
375 */
155 template <typename U> 376 template <typename U>
156 friend 377 friend
157 accessor_iterator<U> operator+(accessor_iterator<U> lhs 378 accessor_iterator<U> operator+(accessor_iterator<U> lhs
@@ -161,6 +382,12 @@ private:
161 return lhs; 382 return lhs;
162 } 383 }
163 384
385 /**
386 * @brief Get an @c accessor_iterator moved @p lhs positions forward.
387 * @param lhs Number of positions relative to the current element.
388 * @param rhs @c accessor_iterator object.
389 * @return Copy of @p rhs moved @p lhs positions forward.
390 */
164 template <typename U> 391 template <typename U>
165 friend 392 friend
166 accessor_iterator<U> operator+(typename accessor_iterator<U>::difference_type lhs 393 accessor_iterator<U> operator+(typename accessor_iterator<U>::difference_type lhs
@@ -169,12 +396,26 @@ private:
169 return rhs + lhs; 396 return rhs + lhs;
170 } 397 }
171 398
399 /**
400 * @brief Check if @p lhs points to a position before the position pointed by @p rhs.
401 * @param lhs @c accessor_iterator at the left side of the expression.
402 * @param rhs @c accessor_iterator at the right side of the expression.
403 * @return @c true if @p lhs points to a position before the position
404 * pointed by @p rhs, @c false otherwise.
405 */
172 template <typename U> 406 template <typename U>
173 friend bool operator<(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 407 friend bool operator<(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
174 { 408 {
175 return lhs._index < rhs._index; 409 return lhs._index < rhs._index;
176 } 410 }
177 411
412 /**
413 * @brief Check if the position pointed by @p lhs is the same or is before the one pointed by @p rhs.
414 * @param lhs @c accessor_iterator at the left side of the expression.
415 * @param rhs @c accessor_iterator at the right side of the expression.
416 * @return @c true if the position pointed by @p lhs is the same or is
417 * before the position pointed by @p rhs, @c false otherwise.
418 */
178 template <typename U> 419 template <typename U>
179 friend bool operator<=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 420 friend bool operator<=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
180 { 421 {
@@ -182,30 +423,63 @@ private:
182 } 423 }
183}; 424};
184 425
426/**
427 * @brief Check if the position pointed by @p lhs is the same or is after the one pointed by @p rhs.
428 * @param lhs @c accessor_iterator at the left side of the expression.
429 * @param rhs @c accessor_iterator at the right side of the expression.
430 * @return @c true if the position pointed by @p lhs is the same or is
431 * after the position pointed by @p rhs, @c false otherwise.
432 */
185template <typename U> 433template <typename U>
186bool operator>=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 434bool operator>=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
187{ 435{
188 return !(lhs < rhs); 436 return !(lhs < rhs);
189} 437}
190 438
439/**
440 * @brief Check if @p lhs points to a position after the position pointed by @p rhs.
441 * @param lhs @c accessor_iterator at the left side of the expression.
442 * @param rhs @c accessor_iterator at the right side of the expression.
443 * @return @c true if @p lhs points to a position after the position
444 * pointed by @p rhs, @c false otherwise.
445 */
191template <typename U> 446template <typename U>
192bool operator>(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 447bool operator>(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
193{ 448{
194 return !(lhs <= rhs); 449 return !(lhs <= rhs);
195} 450}
196 451
452/**
453 * @brief Check if @p lhs and @p rhs point to different positions.
454 * @param lhs @c accessor_iterator at the left side of the expression.
455 * @param rhs @c accessor_iterator at the right side of the expression.
456 * @return @c true if @p lhs and @p rhs point to different positions.
457 */
197template <typename U> 458template <typename U>
198bool operator!=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs) 459bool operator!=(accessor_iterator<U> const& lhs, accessor_iterator<U> const& rhs)
199{ 460{
200 return !(lhs == rhs); 461 return !(lhs == rhs);
201} 462}
202 463
464/**
465 * @brief Swap content between two <tt>accessor_iterator</tt>s.
466 * @param lhs First @c accessor_iterator.
467 * @param rhs Second @c accessor_iterator.
468 */
203template <typename U> 469template <typename U>
204void swap(accessor_iterator<U>& lhs, accessor_iterator<U>& rhs) 470void swap(accessor_iterator<U>& lhs, accessor_iterator<U>& rhs)
205{ 471{
206 lhs.swap(rhs); 472 lhs.swap(rhs);
207} 473}
208 474
475/**
476 * @}
477 */
478
209} } 479} }
210 480
481/**
482 * @}
483 */
484
211#endif 485#endif
diff --git a/src/bindings/eina_cxx/eina_clone_allocators.hh b/src/bindings/eina_cxx/eina_clone_allocators.hh
index 9174eee..2e8ae45 100644
--- a/src/bindings/eina_cxx/eina_clone_allocators.hh
+++ b/src/bindings/eina_cxx/eina_clone_allocators.hh
@@ -6,8 +6,31 @@
6#include <cstdlib> 6#include <cstdlib>
7#include <type_traits> 7#include <type_traits>
8 8
9/**
10 * @addtogroup Eina_Cxx_Containers_Group
11 *
12 * @{
13 */
14
9namespace efl { namespace eina { 15namespace efl { namespace eina {
10 16
17/**
18 * @defgroup Eina_Cxx_Clone_Allocators_Group Clone Allocators
19 * @ingroup Eina_Cxx_Containers_Group
20 *
21 * Clone allocators is a formalized way to pointer containers control
22 * the memory of the stored objects, allowing users to apply custom
23 * allocators/deallocators for the cloned objects.
24 *
25 * @{
26 */
27
28/**
29 * This allocator creates copies of objects on the heap, calling their
30 * copy constructor to make then equivalent to the given reference.
31 *
32 * The created objects are released with the default delete.
33 */
11struct heap_copy_allocator 34struct heap_copy_allocator
12{ 35{
13 template <typename T> 36 template <typename T>
@@ -27,6 +50,11 @@ struct heap_copy_allocator
27 } 50 }
28}; 51};
29 52
53/**
54 * This allocator allows users to create custom allocation schemes by
55 * overloading the <tt>new_clone(T const& v)</tt> and
56 * <tt>delete_clone(T* p)</tt> functions.
57 */
30struct heap_clone_allocator 58struct heap_clone_allocator
31{ 59{
32 template <typename T> 60 template <typename T>
@@ -41,6 +69,14 @@ struct heap_clone_allocator
41 } 69 }
42}; 70};
43 71
72/**
73 * This allocator does not allocate or deallocate anything. It simple
74 * gets non-const-qualified pointers for objects, which allow
75 * containers to hold elements without having ownership on them.
76 *
77 * It is commonly used to create a pointer container that is a view into
78 * another existing container.
79 */
44struct view_clone_allocator 80struct view_clone_allocator
45{ 81{
46 template <typename T> 82 template <typename T>
@@ -54,6 +90,11 @@ struct view_clone_allocator
54 } 90 }
55}; 91};
56 92
93/**
94 * This allocator does not define an @c allocate_clone member function,
95 * so it should be used to disable operations that require elements to
96 * be cloned.
97 */
57struct heap_no_copy_allocator 98struct heap_no_copy_allocator
58{ 99{
59 template <typename T> 100 template <typename T>
@@ -65,8 +106,15 @@ struct heap_no_copy_allocator
65 delete p; 106 delete p;
66#endif 107#endif
67 } 108 }
68}; 109};
69 110
111/**
112 * Manages allocation and deallocation of memory using the function
113 * @c malloc and @c free. This allocator does not calls constructors,
114 * the content of the newly allocated objects are assigned using
115 * @c memcpy, so it is likely only plausible with types that have
116 * <em>standard-layout</em>.
117 */
70struct malloc_clone_allocator 118struct malloc_clone_allocator
71{ 119{
72 template <typename T> 120 template <typename T>
@@ -86,6 +134,14 @@ struct malloc_clone_allocator
86 } 134 }
87}; 135};
88 136
137/**
138 * @}
139 */
140
89} } 141} }
90 142
143/**
144 * @}
145 */
146
91#endif 147#endif
diff --git a/src/bindings/eina_cxx/eina_error.hh b/src/bindings/eina_cxx/eina_error.hh
index 9962768..d2718ca 100644
--- a/src/bindings/eina_cxx/eina_error.hh
+++ b/src/bindings/eina_cxx/eina_error.hh
@@ -5,48 +5,129 @@
5 5
6#include <system_error> 6#include <system_error>
7 7
8/**
9 * @addtogroup Eina_Cxx_Tools_Group
10 *
11 * @{
12 */
13
8namespace efl { namespace eina { 14namespace efl { namespace eina {
9 15
16/**
17 * @defgroup Eina_Cxx_Error_Group Error Handling
18 * @ingroup Eina_Cxx_Tools_Group
19 *
20 * @brief Functions for handling Eina errors.
21 *
22 * Integrates the Eina errors with the standard error representation
23 * defined in the @c system_error library.
24 *
25 * @{
26 */
27
28/** <tt>std::errc</tt> for Eina errors. */
10using std::errc; 29using std::errc;
30
31/** <tt>std::system_error</tt> for Eina errors. */
11using std::system_error; 32using std::system_error;
33
34/** <tt>std::error_code</tt> for Eina errors. */
12using std::error_code; 35using std::error_code;
36
37/** <tt>std::error_condition</tt> for Eina errors. */
13using std::error_condition; 38using std::error_condition;
39
40/** <tt>std::error_category</tt> for Eina errors. */
14typedef std::error_category system_error_category; 41typedef std::error_category system_error_category;
15 42
43/**
44 * @brief Return a @c Eina_Error for an unknown error.
45 * @return @c Eina_Error indicating a unknown/external error condition.
46 *
47 * This function returns an @c Eina_Error indicating a unknown/external
48 * error condition. When first called, this function will register the
49 * said error within the other Eina errors, together with a error
50 * message.
51 */
16inline Eina_Error unknown_error() 52inline Eina_Error unknown_error()
17{ 53{
18 static Eina_Error error = eina_error_msg_static_register("Error from C++ from another value category error"); 54 static Eina_Error error = eina_error_msg_static_register("Error from C++ from another value category error");
19 return error; 55 return error;
20} 56}
21 57
58/**
59 * @brief Gets a <tt>std::generic_category</tt> instance as a <tt>eina::system_error_category</tt>.
60 * @return a <tt>std::generic_category</tt> instance as a <tt>eina::system_error_category</tt>.
61 */
22inline system_error_category const& get_generic_category() 62inline system_error_category const& get_generic_category()
23{ 63{
24 return ::std::generic_category(); 64 return ::std::generic_category();
25} 65}
66
67/**
68 * @brief Gets a <tt>std::system_category</tt> instance as a <tt>eina::system_error_category</tt>.
69 * @return <tt>std::system_category</tt> instance as a <tt>eina::system_error_category</tt>.
70 */
26inline system_error_category const& get_system_category() 71inline system_error_category const& get_system_category()
27{ 72{
28 return ::std::system_category(); 73 return ::std::system_category();
29} 74}
30 75
76/**
77 * @brief Typesafe representation of an @c Eina_Error.
78 *
79 * Used for improved compatibility with @e system_error library.
80 */
31enum error_type {}; 81enum error_type {};
32 82
83/**
84 * @brief Specialized error category for Eina errors.
85 */
33struct error_category : system_error_category 86struct error_category : system_error_category
34{ 87{
88 /**
89 * @brief Name of the error category.
90 * @return String containing the word "eina"
91 */
35 const char* name() const throw() 92 const char* name() const throw()
36 { 93 {
37 return "eina"; 94 return "eina";
38 } 95 }
39 96
97 /**
98 * @brief Check if the given error code is equivalent to the given error condition.
99 * @param code Integer representing the error code.
100 * @param condition <tt>eina::error_condition</tt> object.
101 * @return @c true if @c code is equivalent to @c condition.
102 */
40 bool equivalent(int code, eina::error_condition const& condition) const throw() 103 bool equivalent(int code, eina::error_condition const& condition) const throw()
41 { 104 {
42 return code == condition.value(); 105 return code == condition.value();
43 } 106 }
44 107
108 /**
109 * @brief Check if the given error code is equivalent to the given error condition.
110 * @param code <tt>eina::error_code</tt> object.
111 * @param condition Integer representing the error condition.
112 * @return @c true if @c code is equivalent to @c condition.
113 */
45 bool equivalent(eina::error_code const& code, int condition) const throw() 114 bool equivalent(eina::error_code const& code, int condition) const throw()
46 { 115 {
47 return code.value() == condition; 116 return code.value() == condition;
48 } 117 }
49 118
119 /**
120 * @brief Get the message related with the given error condition.
121 * @param condition Eina error condition.
122 * @return String containing the message related with the given error condition.
123 *
124 * This member function returns the error message related with the
125 * given error condition code.
126 *
127 * @note When the given condition code is not registered within the
128 * Eina errors it will return a string indicating that an error
129 * message is not available.
130 */
50 std::string message(int condition) const 131 std::string message(int condition) const
51 { 132 {
52 const char* e = ::eina_error_msg_get(condition); 133 const char* e = ::eina_error_msg_get(condition);
@@ -54,12 +135,29 @@ struct error_category : system_error_category
54 } 135 }
55}; 136};
56 137
138/**
139 * @brief Get a default <tt>eina::error_category</tt> object.
140 * @return Reference to a static instance of an <tt>eina::error_category</tt>.
141 */
57inline eina::system_error_category& eina_error_category() 142inline eina::system_error_category& eina_error_category()
58{ 143{
59 static error_category _error_category; 144 static error_category _error_category;
60 return _error_category; 145 return _error_category;
61} 146}
62 147
148/**
149 * @brief Gets the error code for the last Eina error.
150 * @return <tt>eina::error_code</tt> for the last Eina error.
151 *
152 * This function gets the error code for the last Eina error and
153 * consumes it. The category of the returned <tt>eina::error_code</tt>
154 * is @c eina_error_category.
155 *
156 * @note If no errors have been occurred or if this functions have
157 * already been called after the last error occurrence a call to this
158 * function will return a default <tt>eina::error_code</tt> to indicates
159 * that there is no unconsumed error.
160 */
63inline eina::error_code get_error_code() 161inline eina::error_code get_error_code()
64{ 162{
65 Eina_Error error = eina_error_get(); 163 Eina_Error error = eina_error_get();
@@ -72,6 +170,14 @@ inline eina::error_code get_error_code()
72 return eina::error_code(); 170 return eina::error_code();
73} 171}
74 172
173/**
174 * @brief Sets an error code in the Eina library.
175 * @param e Error code. Should be an @c eina_error_category error.
176 *
177 * This function sets an error code in the Eina library. If the category
178 * of the given error code is not @c eina_error_category it will
179 * register an unknown error instead.
180 */
75inline void set_error_code(eina::error_code const& e) 181inline void set_error_code(eina::error_code const& e)
76{ 182{
77 if(e.category() == eina_error_category()) 183 if(e.category() == eina_error_category())
@@ -80,6 +186,13 @@ inline void set_error_code(eina::error_code const& e)
80 eina_error_set(unknown_error()); 186 eina_error_set(unknown_error());
81} 187}
82 188
189/**
190 * @brief Gets the error condition for the last Eina error.
191 * @return <tt>eina::error_condition</tt> for the last Eina error.
192 *
193 * This function works exactly like @ref get_error_code but returns an
194 * <tt>eina::error_condition</tt> object instead.
195 */
83inline eina::error_condition get_error_condition() 196inline eina::error_condition get_error_condition()
84{ 197{
85 Eina_Error error = eina_error_get(); 198 Eina_Error error = eina_error_get();
@@ -92,12 +205,35 @@ inline eina::error_condition get_error_condition()
92 return eina::error_condition(); 205 return eina::error_condition();
93} 206}
94 207
208/**
209 * @brief Gets the enum value of the last Eina error.
210 * @return Value of the last Eina error as an @c error_type.
211 *
212 * This function returns the error code for the last Eina error.
213 *
214 * Differently from @ref get_error_code and @ref get_error_condition,
215 * this function does not consume the last error.
216 */
95inline error_type get_error_code_enum() 217inline error_type get_error_code_enum()
96{ 218{
97 return static_cast<error_type>( ::eina_error_get() ); 219 return static_cast<error_type>( ::eina_error_get() );
98} 220}
99 221
100 222
223/**
224 * @brief Throw an exception if there is a error set in Eina library.
225 * @throw <tt>eina::system_error</tt> containing the error identifier.
226 *
227 * This function is meant to be used after executing a operation that
228 * may set an Eina error. If an error code has been set this function
229 * will throw an exception.
230 *
231 * The thrown exception holds an <tt>eina::error_code</tt> equivalent to
232 * the one returned by @ref get_error_code.
233 *
234 * Like the @ref get_error_code function, this one consumes the last
235 * error code.
236 */
101inline void throw_on_error() 237inline void throw_on_error()
102{ 238{
103 eina::error_code ec = get_error_code(); 239 eina::error_code ec = get_error_code();
@@ -107,13 +243,28 @@ inline void throw_on_error()
107 } 243 }
108} 244}
109 245
246/**
247 * @}
248 */
249
110} } 250} }
111 251
252/**
253 * @internal
254 * Template specialization for interoperability with the @e system_error
255 * standard library.
256 * @{
257 */
112namespace std { 258namespace std {
113
114template <> struct is_error_condition_enum< ::efl::eina::error_type> : true_type {}; 259template <> struct is_error_condition_enum< ::efl::eina::error_type> : true_type {};
115template <> struct is_error_code_enum< ::efl::eina::error_type> : true_type {}; 260template <> struct is_error_code_enum< ::efl::eina::error_type> : true_type {};
116
117} 261}
262/**
263 * @}
264 */
265
266/**
267 * @}
268 */
118 269
119#endif 270#endif
diff --git a/src/bindings/eina_cxx/eina_inarray.hh b/src/bindings/eina_cxx/eina_inarray.hh
index 4b10735..ae593e4 100644
--- a/src/bindings/eina_cxx/eina_inarray.hh
+++ b/src/bindings/eina_cxx/eina_inarray.hh
@@ -9,232 +9,538 @@
9#include <cstring> 9#include <cstring>
10#include <cassert> 10#include <cassert>
11 11
12/**
13 * @addtogroup Eina_Cxx_Containers_Group
14 *
15 * @{
16 */
17
12namespace efl { namespace eina { 18namespace efl { namespace eina {
13 19
20/**
21 * @defgroup Eina_Cxx_Inline_Array_Group Inline Array
22 * @ingroup Eina_Cxx_Containers_Group
23 *
24 * Inline array is a container that stores the data itself not pointers to data,
25 * this means there is no memory fragmentation, also for small data types(such
26 * as char, short, int, etc.) it's more memory efficient.
27 *
28 * @{
29 */
30
31/**
32 * @internal
33 * Access traits for eina::inarray.
34 */
14struct _inarray_access_traits { 35struct _inarray_access_traits {
15 36
16 template <typename T> 37 template <typename T>
17 struct const_iterator 38 struct const_iterator
18 { 39 {
19 typedef T const* type; 40 typedef T const* type; /**< Type for constant iterator. */
20 }; 41 };
21 template <typename T> 42 template <typename T>
22 struct iterator 43 struct iterator
23 { 44 {
24 typedef T* type; 45 typedef T* type; /**< Type for iterator. */
25 }; 46 };
26 template <typename T> 47 template <typename T>
27 struct const_native_handle 48 struct const_native_handle
28 { 49 {
29 typedef Eina_Inarray const* type; 50 typedef Eina_Inarray const* type; /**< Type for constant native @c Eina_Inarray handle. */
30 }; 51 };
31 template <typename T> 52 template <typename T>
32 struct native_handle 53 struct native_handle
33 { 54 {
34 typedef Eina_Inarray* type; 55 typedef Eina_Inarray* type; /**< Type for native @c Eina_Inarray handle. */
35 }; 56 };
36 57
58 /**
59 * @brief Get a non-constant native @c Eina_Inarray handle from a constant one.
60 */
37 template <typename T> 61 template <typename T>
38 static Eina_Inarray* native_handle_from_const(Eina_Inarray const* array) 62 static Eina_Inarray* native_handle_from_const(Eina_Inarray const* array)
39 { 63 {
40 return const_cast<Eina_Inarray*>(array); 64 return const_cast<Eina_Inarray*>(array);
41 } 65 }
66
67/**
68 * @brief Get a reference to the last element of the given @c Eina_Inarray.
69 */
42template <typename T> 70template <typename T>
43static T& back(Eina_Inarray* raw) 71static T& back(Eina_Inarray* raw)
44{ 72{
45 assert(!_inarray_access_traits::empty<T>(raw)); 73 assert(!_inarray_access_traits::empty<T>(raw));
46 return *static_cast<T*>( ::eina_inarray_nth(raw, _inarray_access_traits::size<T>(raw)-1u)); 74 return *static_cast<T*>( ::eina_inarray_nth(raw, _inarray_access_traits::size<T>(raw)-1u));
47} 75}
76/**
77 * @brief Get a constant reference to the last element of the given @c Eina_Inarray.
78 *
79 * Version of @ref back(Eina_Inarray* raw) for const-qualified pointer
80 * to @c Eina_Inarray. Get a constant reference to the last element
81 * instead.
82 */
48template <typename T> 83template <typename T>
49static T const& back(Eina_Inarray const* raw) 84static T const& back(Eina_Inarray const* raw)
50{ 85{
51 return _inarray_access_traits::back<T>(const_cast<Eina_Inarray*>(raw)); 86 return _inarray_access_traits::back<T>(const_cast<Eina_Inarray*>(raw));
52} 87}
88
89/**
90 * @brief Get a reference to the first element of the given @c Eina_Inarray.
91 */
53template <typename T> 92template <typename T>
54static T& front(Eina_Inarray* raw) 93static T& front(Eina_Inarray* raw)
55{ 94{
56 assert(!empty<T>(raw)); 95 assert(!empty<T>(raw));
57 return *static_cast<T*>( ::eina_inarray_nth(raw, 0u)); 96 return *static_cast<T*>( ::eina_inarray_nth(raw, 0u));
58} 97}
98
99/**
100 * @brief Get a constant reference to the first element of the given @c Eina_Inarray.
101 *
102 * Version of @ref front(Eina_Inarray* raw) for const-qualified
103 * pointer to @c Eina_Inarray. Get a constant reference to the first
104 * element instead.
105 */
59template <typename T> 106template <typename T>
60static T const& front(Eina_Inarray const* raw) 107static T const& front(Eina_Inarray const* raw)
61{ 108{
62 return _inarray_access_traits::front<T>(const_cast<Eina_Inarray*>(raw)); 109 return _inarray_access_traits::front<T>(const_cast<Eina_Inarray*>(raw));
63} 110}
111
112/**
113 * @brief Get an iterator to the begin of the memory block of the given @c Eina_Inarray.
114 */
64template <typename T> 115template <typename T>
65static T* begin(Eina_Inarray* raw) 116static T* begin(Eina_Inarray* raw)
66{ 117{
67 return !raw->members ? 0 : static_cast<T*>( ::eina_inarray_nth(raw, 0u)); 118 return !raw->members ? 0 : static_cast<T*>( ::eina_inarray_nth(raw, 0u));
68} 119}
120
121/**
122 * @brief Get an iterator to the end of the memory block of the given @c Eina_Inarray.
123 */
69template <typename T> 124template <typename T>
70static T* end(Eina_Inarray* raw) 125static T* end(Eina_Inarray* raw)
71{ 126{
72 return !raw->members ? 0 127 return !raw->members ? 0
73 : static_cast<T*>( ::eina_inarray_nth(raw, _inarray_access_traits::size<T>(raw) -1)) + 1; 128 : static_cast<T*>( ::eina_inarray_nth(raw, _inarray_access_traits::size<T>(raw) -1)) + 1;
74} 129}
130
131/**
132 * @brief Get a constant iterator to the begin of the memory block of the given @c Eina_Inarray.
133 *
134 * Version of @ref begin(Eina_Inarray* raw) for const-qualified
135 * @c Eina_Inarray handles. Returns a constant iterator instead.
136 */
75template <typename T> 137template <typename T>
76static T const* begin(Eina_Inarray const* raw) 138static T const* begin(Eina_Inarray const* raw)
77{ 139{
78 return _inarray_access_traits::begin<T>(const_cast<Eina_Inarray*>(raw)); 140 return _inarray_access_traits::begin<T>(const_cast<Eina_Inarray*>(raw));
79} 141}
142
143
144/**
145 * @brief Get a constant iterator to the end of the memory block of the given @c Eina_Inarray.
146 *
147 * Version of @ref end(Eina_Inarray* raw) const-qualified
148 * @c Eina_Inarray. Returns a constant iterator instead.
149 */
80template <typename T> 150template <typename T>
81static T const* end(Eina_Inarray const* raw) 151static T const* end(Eina_Inarray const* raw)
82{ 152{
83 return _inarray_access_traits::end<T>(const_cast<Eina_Inarray*>(raw)); 153 return _inarray_access_traits::end<T>(const_cast<Eina_Inarray*>(raw));
84} 154}
155
156/**
157 * @brief Get a constant reverse iterator pointing to the reverse begin of the given Eina_Inarray.
158 *
159 * Version of @ref rbegin(Eina_Inarray* raw) for const-qualified
160 * Eina_Inarray handles. Returns a constant reverse iterator instead.
161 */
85template <typename T> 162template <typename T>
86static std::reverse_iterator<T const*> rbegin(Eina_Inarray const* raw) 163static std::reverse_iterator<T const*> rbegin(Eina_Inarray const* raw)
87{ 164{
88 return std::reverse_iterator<T const*>(_inarray_access_traits::end<T>(raw)); 165 return std::reverse_iterator<T const*>(_inarray_access_traits::end<T>(raw));
89} 166}
167
168/**
169 * @brief Get a constant reverse iterator pointing to the reverse end of the given Eina_Inarray.
170 *
171 * Version of @ref rend(Eina_Inarray* raw) to const-qualified
172 * Eina_Inarray handles. Returns a constant reverse iterator instead.
173 */
90template <typename T> 174template <typename T>
91static std::reverse_iterator<T const*> rend(Eina_Inarray const* raw) 175static std::reverse_iterator<T const*> rend(Eina_Inarray const* raw)
92{ 176{
93 return std::reverse_iterator<T const*>(_inarray_access_traits::begin<T>(raw)); 177 return std::reverse_iterator<T const*>(_inarray_access_traits::begin<T>(raw));
94} 178}
179
180/**
181 * @brief Get a reverse iterator pointing to the reverse begin of the given @c Eina_Inarray.
182 */
95template <typename T> 183template <typename T>
96static std::reverse_iterator<T*> rbegin(Eina_Inarray* raw) 184static std::reverse_iterator<T*> rbegin(Eina_Inarray* raw)
97{ 185{
98 return std::reverse_iterator<T*>(_inarray_access_traits::end<T>(raw)); 186 return std::reverse_iterator<T*>(_inarray_access_traits::end<T>(raw));
99} 187}
188
189/**
190 * @brief Get a reverse iterator pointing to the reverse end of the given @c Eina_Inarray.
191 */
100template <typename T> 192template <typename T>
101static std::reverse_iterator<T*> rend(Eina_Inarray* raw) 193static std::reverse_iterator<T*> rend(Eina_Inarray* raw)
102{ 194{
103 return std::reverse_iterator<T*>(_inarray_access_traits::begin<T>(raw)); 195 return std::reverse_iterator<T*>(_inarray_access_traits::begin<T>(raw));
104} 196}
197
198/**
199 * @brief Get a constant iterator to the begin of the memory block of the given @c Eina_Inarray.
200 *
201 * Works like @ref begin(Eina_Inarray const* raw) but is granted to
202 * return a constant iterator even for handles that are not
203 * const-qualified.
204 */
105template <typename T> 205template <typename T>
106static T const* cbegin(Eina_Inarray const* raw) 206static T const* cbegin(Eina_Inarray const* raw)
107{ 207{
108 return _inarray_access_traits::begin<T>(raw); 208 return _inarray_access_traits::begin<T>(raw);
109} 209}
210
211/**
212 * @brief Get a constant iterator to the end of the memory block of the given @c Eina_Inarray.
213 *
214 * Works like @ref end(Eina_Inarray const* raw) but is granted to
215 * return a constant iterator even for handles that are not
216 * const-qualified.
217 */
110template <typename T> 218template <typename T>
111static T const* cend(Eina_Inarray const* raw) 219static T const* cend(Eina_Inarray const* raw)
112{ 220{
113 return _inarray_access_traits::end<T>(raw); 221 return _inarray_access_traits::end<T>(raw);
114} 222}
223
224/**
225 * @brief Get a constant reverse iterator to the end of the memory block of the given @c Eina_Inarray.
226 *
227 * Works like @ref rbegin(Eina_Inarray const* raw) but is granted to
228 * return a constant reverse iterator even for handles that are not
229 * const-qualified.
230 */
115template <typename T> 231template <typename T>
116static std::reverse_iterator<T const*> crbegin(Eina_Inarray const* raw) 232static std::reverse_iterator<T const*> crbegin(Eina_Inarray const* raw)
117{ 233{
118 return _inarray_access_traits::rbegin<T const*>(raw); 234 return _inarray_access_traits::rbegin<T const*>(raw);
119} 235}
236
237/**
238 * @brief Get a constant reverse iterator to the begin of the memory block of the given @c Eina_Inarray.
239 *
240 * Works like @ref rend(Eina_Inarray const* raw) but is granted to
241 * return a constant reverse iterator even for handles that are not
242 * const-qualified.
243 */
120template <typename T> 244template <typename T>
121static std::reverse_iterator<T const*> crend(Eina_Inarray const* raw) 245static std::reverse_iterator<T const*> crend(Eina_Inarray const* raw)
122{ 246{
123 return _inarray_access_traits::rend<T const*>(raw); 247 return _inarray_access_traits::rend<T const*>(raw);
124} 248}
249
250/**
251 * @brief Check if the given Eina array is empty.
252 * @return @c true if the given array is empty, @c false otherwise.
253 *
254 * This functions returns @c true if the given @c Eina_Inarray contains
255 * no elements, otherwise it returns @c false.
256 */
125template <typename T> 257template <typename T>
126static inline bool empty(Eina_Inarray const* raw) 258static inline bool empty(Eina_Inarray const* raw)
127{ 259{
128 return _inarray_access_traits::size<T>(raw) == 0; 260 return _inarray_access_traits::size<T>(raw) == 0;
129} 261}
262
263/**
264 * @brief Get the size of the given @c Eina_Inarray.
265 * @return Number of elements in the given array.
266 *
267 * This function returns the current number of elements inside of @p raw.
268 */
130template <typename T> 269template <typename T>
131static inline std::size_t size(Eina_Inarray const* raw) 270static inline std::size_t size(Eina_Inarray const* raw)
132{ 271{
133 return ::eina_inarray_count(raw); 272 return ::eina_inarray_count(raw);
134} 273}
274
275/**
276 * @brief Get a constant reference to the element at the given position.
277 * @param raw Constant pointer to an @c Eina_Inarray.
278 * @param i Position of the element.
279 * @return Constant reference to the element.
280 *
281 * Version of @ref index() for const-qualified @c Eina_Inarray. Returns
282 * a constant reference instead.
283 */
135template <typename T> 284template <typename T>
136static T const& index(Eina_Inarray const* raw, std::size_t i) 285static T const& index(Eina_Inarray const* raw, std::size_t i)
137{ 286{
138 return *(_inarray_access_traits::begin<T>(raw) + i); 287 return *(_inarray_access_traits::begin<T>(raw) + i);
139} 288}
289
290/**
291 * @brief Get a reference to the element at the given position.
292 * @param raw Pointer to a @c Eina_Inarray.
293 * @param i Position of the element.
294 * @return Reference to the element.
295 *
296 * This member function returns a reference to the element at position
297 * @p i inside @p raw.
298 */
140template <typename T> 299template <typename T>
141static T& index(Eina_Inarray* raw, std::size_t i) 300static T& index(Eina_Inarray* raw, std::size_t i)
142{ 301{
143 return *(_inarray_access_traits::begin<T>(raw) + i); 302 return *(_inarray_access_traits::begin<T>(raw) + i);
144} 303}
145 304
305
146}; 306};
147 307
148template <typename T> 308template <typename T>
149class inarray; 309class inarray;
150 310
311/**
312 * @ingroup Eina_Cxx_Range_Group
313 *
314 * Range class for @ref inarray.
315 */
151template <typename T> 316template <typename T>
152struct range_inarray : _range_template<T, _inarray_access_traits> 317struct range_inarray : _range_template<T, _inarray_access_traits>
153{ 318{
154 typedef _range_template<T, _inarray_access_traits> _base_type; 319 typedef _range_template<T, _inarray_access_traits> _base_type; /**< Type for the base class. */
155 typedef typename std::remove_const<T>::type value_type; 320 typedef typename std::remove_const<T>::type value_type; /**< The type of each element. */
156 321
322 /**
323 * @brief Creates a range from a native Eina inline array handle.
324 */
157 range_inarray(Eina_Inarray* array) 325 range_inarray(Eina_Inarray* array)
158 : _base_type(array) 326 : _base_type(array)
159 {} 327 {}
328
329 /**
330 * @brief Creates a range from a @c inarray object.
331 */
160 range_inarray(inarray<T>& array) 332 range_inarray(inarray<T>& array)
161 : _base_type(array.native_handle()) 333 : _base_type(array.native_handle())
162 {} 334 {}
163 335
336 /**
337 * @brief Get the element at the given position in the array.
338 * @param index Position of the element.
339 * @return Reference to the element at the given position.
340 */
164 value_type& operator[](std::size_t index) const 341 value_type& operator[](std::size_t index) const
165 { 342 {
166 return _inarray_access_traits::index<T>(this->native_handle(), index); 343 return _inarray_access_traits::index<T>(this->native_handle(), index);
167 } 344 }
168}; 345};
169 346
347/**
348 * Common inarray interface for every value type.
349 */
170struct _inarray_common_base 350struct _inarray_common_base
171{ 351{
172 typedef std::size_t size_type; 352 typedef std::size_t size_type; /**< Type for size information used in the array. */
173 typedef Eina_Inarray* native_handle_type; 353 typedef Eina_Inarray* native_handle_type; /** Type for the native @c Eina_Inarray handle. */
174 typedef Eina_Inarray const* const_native_handle_type; 354 typedef Eina_Inarray const* const_native_handle_type; /** Type for constant native @c Eina_Inarray handle. */
175 355
356 /**
357 * @brief Creates a new array object from a handle to a native @c Eina_Inarray.
358 * @param array Handler to a native @c Eina_Inarray
359 *
360 * This constructor wraps a pre-allocated @c Eina_Inarray providing an
361 * OO interface to it.
362 *
363 * @warning It is important to note that the created array object
364 * gains ownership of the handle, deallocating it at destruction time.
365 */
176 explicit _inarray_common_base(Eina_Inarray* array) 366 explicit _inarray_common_base(Eina_Inarray* array)
177 : _array(array) {} 367 : _array(array) {}
368
369 /**
370 * @brief Allocates a array with the given size for each element.
371 * @param member_size Size of each element in the array.
372 *
373 * This constructor creates an inline array object with the given
374 * size (in bytes) for each element. All allocated memory will be
375 * released at destruction.
376 */
178 explicit _inarray_common_base(size_type member_size) 377 explicit _inarray_common_base(size_type member_size)
179 : _array( ::eina_inarray_new(member_size, 0) ) 378 : _array( ::eina_inarray_new(member_size, 0) )
180 { 379 {
181 } 380 }
381
382 /**
383 * @brief Release the inline array memory.
384 *
385 * This destructor release the internal native @c Eina_Inarray handle,
386 * freeing allocated memory.
387 */
182 ~_inarray_common_base() 388 ~_inarray_common_base()
183 { 389 {
184 ::eina_inarray_free(_array); 390 ::eina_inarray_free(_array);
185 } 391 }
186 392
393 /**
394 * @brief Get the current size of the array.
395 * @return Number of elements in the array.
396 *
397 * This member function returns the current number of elements inside
398 * the inline array.
399 */
187 size_type size() const 400 size_type size() const
188 { 401 {
189 return _inarray_access_traits::size<void>(_array); 402 return _inarray_access_traits::size<void>(_array);
190 } 403 }
404
405 /**
406 * @brief Check if the array is empty.
407 * @return @c true if the array is empty, @c false otherwise.
408 *
409 * This member function returns @c true if the array does not contain
410 * any elements, otherwise it returns @c false.
411 */
191 bool empty() const 412 bool empty() const
192 { 413 {
193 return _inarray_access_traits::empty<void>(_array); 414 return _inarray_access_traits::empty<void>(_array);
194 } 415 }
416
417 /**
418 * @brief Get the handle for the wrapped Eina_Inarray.
419 * @return Internal handle for the native Eina inline array.
420 *
421 * This member function returns the native @c Eina_Inarray handle that
422 * is wrapped inside this object.
423 *
424 * @warning It is important to take care when using it, since the
425 * handle will be automatically release upon object destruction.
426 */
195 native_handle_type native_handle() { return _array; } 427 native_handle_type native_handle() { return _array; }
428
429 /**
430 * @brief Get a constant handle for the wrapped Eina_Inarray.
431 * @return Constant handle for the native Eina inline array.
432 *
433 * Version of @ref native_handle() for const-qualified objects.
434 * Return a constant handle instead.
435 */
196 const_native_handle_type native_handle() const { return _array; } 436 const_native_handle_type native_handle() const { return _array; }
197 437
438 /**
439 * @internal
440 * Member variable that holds the native @c Eina_Inarray handle.
441 */
198 Eina_Inarray* _array; 442 Eina_Inarray* _array;
199private: 443private:
444 /** Disabled copy constructor. */
200 _inarray_common_base(_inarray_common_base const& other); 445 _inarray_common_base(_inarray_common_base const& other);
446 /** Disabled assignment operator. */
201 _inarray_common_base& operator=(_inarray_common_base const& other); 447 _inarray_common_base& operator=(_inarray_common_base const& other);
202}; 448};
203 449
450/**
451 * Optimized specialization of the base inline array for POD types.
452 */
204template <typename T> 453template <typename T>
205class _pod_inarray : _inarray_common_base 454class _pod_inarray : _inarray_common_base
206{ 455{
207 typedef _inarray_common_base _base_type; 456 typedef _inarray_common_base _base_type; /**< Type for the base class. */
208public: 457public:
209 typedef T value_type; 458 typedef T value_type; /**< The type of each element. */
210 typedef T& reference; 459 typedef T& reference; /**< Type for a reference to an element. */
211 typedef T const& const_reference; 460 typedef T const& const_reference; /**< Type for a constant reference to an element. */
212 typedef T* pointer; 461 typedef T* pointer; /**< Type for a pointer to an element. */
213 typedef T const* const_pointer; 462 typedef T const* const_pointer; /**< Type for a constant pointer for an element. */
463
464 /**
465 * Type for a iterator for this container.
466 * Defined as a @ref pointer for performance reasons.
467 */
214 typedef pointer iterator; 468 typedef pointer iterator;
469
470 /**
471 * Type for a constant iterator for this container.
472 * Defined as a @ref const_pointer for performance reasons.
473 */
215 typedef const_pointer const_iterator; 474 typedef const_pointer const_iterator;
216 typedef std::size_t size_type; 475 typedef std::size_t size_type; /**< Type for size information used in the array. */
217 typedef std::ptrdiff_t difference_type; 476 typedef std::ptrdiff_t difference_type; /**< Type to represent the distance between two iterators. */
218 typedef _base_type::native_handle_type native_handle_type; 477 typedef _base_type::native_handle_type native_handle_type; /** Type for the native @c Eina_Inarray handle. */
219 typedef _base_type::const_native_handle_type const_native_handle_type; 478 typedef _base_type::const_native_handle_type const_native_handle_type; /** Type for constant native @c Eina_Inarray handle. */
220 479
221 typedef std::reverse_iterator<iterator> reverse_iterator; 480 typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for reverse iterator of the array. */
222 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 481 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; /** Type for constant reverse iterator of the array. */
223 482
224 using _base_type::size; 483 using _base_type::size; /**< Type for size information used in the array. */
225 using _base_type::empty; 484
226 using _base_type::native_handle; 485 /**
486 * @brief Check if the array is empty.
487 * @return @c true if the array is empty, @c false otherwise.
488 *
489 * This member function returns @c true if the array does not contain
490 * any elements, otherwise it returns @c false.
491 */
492 using _base_type::empty;
493 using _base_type::native_handle; /** Type for the native @c Eina_Inarray handle. */
227 494
495
496 /**
497 * @brief Create a new object from a handle to a native @c Eina_Inarray.
498 * @param array Handler to a native @c Eina_Inarray.
499 *
500 * This constructor wraps a pre-allocated @c Eina_Inarray providing an
501 * OOP interface to it.
502 *
503 * @warning It is important to note that the created object gains
504 * ownership of the handle, deallocating it at destruction time.
505 */
228 _pod_inarray(Eina_Inarray* array) 506 _pod_inarray(Eina_Inarray* array)
229 : _base_type(array) {} 507 : _base_type(array) {}
508
509 /**
510 * @brief Default constructor. Create an empty array.
511 *
512 * This constructor creates an array object with no elements. Elements
513 * are declarated as having the same size of the given template
514 * typename argument.
515 */
230 _pod_inarray() : _base_type(sizeof(T)) 516 _pod_inarray() : _base_type(sizeof(T))
231 { 517 {
232 } 518 }
519
520 /**
521 * @brief Construct an array object with @p n copies of @p t.
522 * @param n Number of elements.
523 * @param t Value to be copied to each element.
524 *
525 * This constructor creates an inline array with @p n elements, each
526 * one as a copy of @p t.
527 */
233 _pod_inarray(size_type n, value_type const& t) : _base_type(sizeof(T)) 528 _pod_inarray(size_type n, value_type const& t) : _base_type(sizeof(T))
234 { 529 {
235 while(n--) 530 while(n--)
236 push_back(t); 531 push_back(t);
237 } 532 }
533
534 /**
535 * @brief Create a inline array with elements from the given range.
536 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
537 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
538 *
539 * This constructor creates a inline array with copies of the elements
540 * between @p i and @p j in the same order.
541 *
542 * @note The ending element (pointed by @p j) is not copied.
543 */
238 template <typename InputIterator> 544 template <typename InputIterator>
239 _pod_inarray(InputIterator i, InputIterator const& j 545 _pod_inarray(InputIterator i, InputIterator const& j
240 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0) 546 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
@@ -246,24 +552,58 @@ public:
246 ++i; 552 ++i;
247 } 553 }
248 } 554 }
555
556 /**
557 * @brief Copy constructor. Creates a copy of the given inline array.
558 * @param other Another inline array of the same type.
559 *
560 * This constructor creates an inline array containing a copy of each
561 * element inside @p other in the same order.
562 */
249 _pod_inarray(_pod_inarray<T>const& other) 563 _pod_inarray(_pod_inarray<T>const& other)
250 : _base_type(sizeof(T)) 564 : _base_type(sizeof(T))
251 { 565 {
252 insert(end(), other.begin(), other.end()); 566 insert(end(), other.begin(), other.end());
253 } 567 }
568
569 /**
570 * Do nothing, the native @c Eina_Inarray is already released in the
571 * base class destructor.
572 */
254 ~_pod_inarray() 573 ~_pod_inarray()
255 { 574 {
256 } 575 }
576
577 /**
578 * @brief Replace the current content with the cotent of another array.
579 * @param other Another inline array of the same type.
580 *
581 * This assignment operator replaces the content of the array by a
582 * copy of the content of @p other. The array size is adjusted
583 * accordingly and the newly copied elements keep their original order.
584 */
257 _pod_inarray<T>& operator=(_pod_inarray<T>const& other) 585 _pod_inarray<T>& operator=(_pod_inarray<T>const& other)
258 { 586 {
259 clear(); 587 clear();
260 insert(end(), other.begin(), other.end()); 588 insert(end(), other.begin(), other.end());
261 return *this; 589 return *this;
262 } 590 }
591
592 /**
593 * @brief Remove all the elements of the array.
594 */
263 void clear() 595 void clear()
264 { 596 {
265 ::eina_inarray_flush(_array); 597 ::eina_inarray_flush(_array);
266 } 598 }
599
600 /**
601 * @brief Add a copy of the given element at the end of the array.
602 * @param value Element to be added at the end of the array.
603 *
604 * This member function allocates a new element at the end of the
605 * inline array, the content of @p value is copied to the new element.
606 */
267 void push_back(T const& value) 607 void push_back(T const& value)
268 { 608 {
269 size_type s = size(); 609 size_type s = size();
@@ -271,10 +611,28 @@ public:
271 assert(size() != s); 611 assert(size() != s);
272 assert(size() == s + 1u); 612 assert(size() == s + 1u);
273 } 613 }
614
615 /**
616 * @brief Remove the last element of the array.
617 */
274 void pop_back() 618 void pop_back()
275 { 619 {
276 eina_inarray_pop(_array); 620 eina_inarray_pop(_array);
277 } 621 }
622
623 /**
624 * @brief Insert a new element at the given position.
625 * @param i Iterator pointing to the position where the new element will be inserted.
626 * @param t Value to be copied to the new element.
627 * @return Iterator pointing to the new element inserted.
628 *
629 * This member function inserts a copy of the element @p t at the
630 * position @p i. The new element comes right before the element
631 * originally pointed by @p i.
632 *
633 * At the end, a valid iterator pointing to the element just inserted
634 * is returned.
635 */
278 iterator insert(iterator i, value_type const& t) 636 iterator insert(iterator i, value_type const& t)
279 { 637 {
280 if(i != end()) 638 if(i != end())
@@ -290,6 +648,21 @@ public:
290 return end()-1; 648 return end()-1;
291 } 649 }
292 } 650 }
651
652 /**
653 * @brief Insert @p n copies of @p t at the given position.
654 * @param i Iterator pointing to the position where the new elements will be inserted.
655 * @param n Number of elements to be inserted.
656 * @param t Value to be copied to each new inserted element.
657 * @return Iterator pointing to the first inserted element.
658 *
659 * This member function inserts @p n new elements at position @p i
660 * in the array, each one as a copy of @p t. The new elements come
661 * right before the element originally pointed by @p i.
662 *
663 * At the end, a valid iterator pointing to the first element inserted
664 * is returned.
665 */
293 iterator insert(iterator i, size_t n, value_type const& t) 666 iterator insert(iterator i, size_t n, value_type const& t)
294 { 667 {
295 T* q; 668 T* q;
@@ -306,6 +679,22 @@ public:
306 std::memcpy(p, &t, sizeof(t)); 679 std::memcpy(p, &t, sizeof(t));
307 return q; 680 return q;
308 } 681 }
682
683 /**
684 * @brief Insert the elements between the given range at the given position.
685 * @param p Iterator pointing to the position where the new elements will be inserted.
686 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
687 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
688 * @return Iterator pointing to the first inserted element.
689 *
690 * This member function inserts a copy of the elements between @p i
691 * and @p j at the position @p p. The new elements come right before
692 * the element originally pointed by @p p. Note that the element
693 * pointed by @p j is not copied.
694 *
695 * At the end, a valid iterator pointing to the first element inserted
696 * is returned.
697 */
309 template <typename InputIterator> 698 template <typename InputIterator>
310 iterator insert(iterator p, InputIterator i, InputIterator j 699 iterator insert(iterator p, InputIterator i, InputIterator j
311 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0) 700 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
@@ -320,11 +709,35 @@ public:
320 } 709 }
321 return p - n; 710 return p - n;
322 } 711 }
712
713 /**
714 * @brief Remove the element at the given position.
715 * @param q Iterator pointing to the element to be removed.
716 * @return Iterator pointing to the element after the removed one.
717 *
718 * This member function removes the element pointed by the iterator
719 * @p q, reducing the array size by one. At the end, a valid iterator
720 * pointing to the element right after the removed one is returned.
721 */
323 iterator erase(iterator q) 722 iterator erase(iterator q)
324 { 723 {
325 ::eina_inarray_remove_at(_array, q - begin()); 724 ::eina_inarray_remove_at(_array, q - begin());
326 return q; 725 return q;
327 } 726 }
727
728 /**
729 * @brief Remove the elements between the given range.
730 * @param i Iterator pointing to the starting position to be removed.
731 * @param j Iterator pointing to the ending position to be removed.
732 * The element pointed by this iterator is not removed.
733 * @return Iterator pointing to the new position of the first
734 * non-removed element after the removed ones (i.e. the one
735 * originally pointed by @p j).
736 *
737 * This member function removes the elements between the iterators
738 * @p i and @p j, including the element pointed by @p i but not the
739 * element pointed by @j.
740 */
328 iterator erase(iterator i, iterator j) 741 iterator erase(iterator i, iterator j)
329 { 742 {
330 while(i != j) 743 while(i != j)
@@ -333,92 +746,293 @@ public:
333 } 746 }
334 return i; 747 return i;
335 } 748 }
749
750 /**
751 * @brief Replace the content of the array by the elements in the given range.
752 * @param i Iterator pointing to the beginning of the elements to be copied.
753 * @param j Iterator pointing to the end of the elements to be copied.
754 * Note that the element pointed by j will NOT be copied.
755 *
756 * This member function replaces the current elements by copies of the
757 * elements between the iterators @p i and @p j, including the element
758 * pointed by @p i but not the one pointed by @p j. The size of the
759 * array is adjusted accordingly and the newly copied elements remain
760 * in their original order.
761 */
336 template <typename InputIterator> 762 template <typename InputIterator>
337 void assign(InputIterator i, InputIterator j 763 void assign(InputIterator i, InputIterator j
338 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0); 764 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0);
765
766 /**
767 * @brief Replace the content of the array by @p n copies @p t.
768 * @param n Number of elements.
769 * @param t Value to be copied to each element.
770 */
339 void assign(size_type n, value_type const& t); 771 void assign(size_type n, value_type const& t);
772
773 /**
774 * @brief Get a reference to the element at the given position.
775 * @param i Position of the element.
776 * @return Reference to the element at the ith position.
777 */
340 value_type& operator[](size_type i) 778 value_type& operator[](size_type i)
341 { 779 {
342 return *(begin() + i); 780 return *(begin() + i);
343 } 781 }
782
783 /**
784 * @brief Get a constant reference to the element at the given position.
785 * @param i Position of the element.
786 * @return Constant reference to the element at the ith position.
787 *
788 * Version of @ref operator[](size_type i) for const-qualified inline
789 * array objects. Returns a constant reference instead.
790 */
344 value_type const& operator[](size_type i) const 791 value_type const& operator[](size_type i) const
345 { 792 {
346 return const_cast<inarray<T>&>(*this)[i]; 793 return const_cast<inarray<T>&>(*this)[i];
347 } 794 }
795
796 /**
797 * @brief Get a reference to the last element.
798 * @return Reference to the last element in the array.
799 */
348 value_type& back() 800 value_type& back()
349 { 801 {
350 return _inarray_access_traits::back<value_type>(_array); 802 return _inarray_access_traits::back<value_type>(_array);
351 } 803 }
804
805 /**
806 * @brief Get a constant reference to the last element.
807 * @return Constant reference to the last element in the array.
808 *
809 * Version of @ref back() for const-qualified inline array objects.
810 * Returns a constant reference instead.
811 */
352 value_type const& back() const 812 value_type const& back() const
353 { 813 {
354 return _inarray_access_traits::back<value_type>(_array); 814 return _inarray_access_traits::back<value_type>(_array);
355 } 815 }
816
817 /**
818 * @brief Get a reference to the first element.
819 * @return Reference to the first element of the array.
820 */
356 value_type& front() 821 value_type& front()
357 { 822 {
358 return _inarray_access_traits::front<value_type>(_array); 823 return _inarray_access_traits::front<value_type>(_array);
359 } 824 }
825
826 /**
827 * @brief Get a constant reference to the first element.
828 * @return Constant reference to the first element of the array.
829 *
830 * Version of @ref front() for const-qualified inline array objects.
831 * Returns a constant reference instead.
832 */
360 value_type const& front() const 833 value_type const& front() const
361 { 834 {
362 return _inarray_access_traits::front<value_type>(_array); 835 return _inarray_access_traits::front<value_type>(_array);
363 } 836 }
837
838 /**
839 * @brief Get an iterator pointing to the first element of the array.
840 * @return Iterator to the initial position of the array.
841 *
842 * This member function returns an iterator pointing to the first
843 * element of the array. If the array is empty the returned iterator
844 * is the same as the one returned by @ref end().
845 */
364 iterator begin() 846 iterator begin()
365 { 847 {
366 return _inarray_access_traits::begin<value_type>(_array); 848 return _inarray_access_traits::begin<value_type>(_array);
367 } 849 }
850
851 /**
852 * @brief Get an iterator to the position following the last element of the array.
853 * @return Iterator to the final position of the array.
854 *
855 * This member function returns an iterator to the position following
856 * the last element in the array. If the array is empty the returned
857 * iterator is the same as the one returned by @ref begin().
858 *
859 * @note Note that attempting to access this position causes undefined
860 * behavior.
861 */
368 iterator end() 862 iterator end()
369 { 863 {
370 return _inarray_access_traits::end<value_type>(_array); 864 return _inarray_access_traits::end<value_type>(_array);
371 } 865 }
866
867 /**
868 * @brief Get a constant iterator pointing to the first element of the array.
869 * @return Constant iterator to the initial position of the array.
870 *
871 * Version of @ref begin() for const-qualified inline array objects.
872 * Returns a constant iterator instead.
873 */
372 const_iterator begin() const 874 const_iterator begin() const
373 { 875 {
374 return _inarray_access_traits::begin<value_type>(_array); 876 return _inarray_access_traits::begin<value_type>(_array);
375 } 877 }
878
879 /**
880 * @brief Get a constant iterator to the position following the last element of the array.
881 * @return Constant iterator to the final position of the array.
882 *
883 * Version of @ref end() for const-qualified inline array objects.
884 * Returns a constant iterator instead.
885 */
376 const_iterator end() const 886 const_iterator end() const
377 { 887 {
378 return _inarray_access_traits::end<value_type>(_array); 888 return _inarray_access_traits::end<value_type>(_array);
379 } 889 }
890
891 /**
892 * @brief Get a constant reverse iterator pointing to the reverse begin of the array.
893 * @return Constant reverse iterator pointing to the reverse begin of the array.
894 *
895 * Version of @ref rbegin() for const-qualified inline array objects.
896 * Returns a constant reverse iterator instead.
897 */
380 const_reverse_iterator rbegin() const 898 const_reverse_iterator rbegin() const
381 { 899 {
382 return _inarray_access_traits::rbegin<value_type>(_array); 900 return _inarray_access_traits::rbegin<value_type>(_array);
383 } 901 }
902
903 /**
904 * @brief Get a constant reverse iterator pointing to the reverse end of the array.
905 * @return Constant reverse iterator pointing to the reverse end of the array.
906 *
907 * Version of @ref rend() for const-qualified inline array objects.
908 * Returns a constant reverse iterator instead.
909 */
384 const_reverse_iterator rend() const 910 const_reverse_iterator rend() const
385 { 911 {
386 return _inarray_access_traits::rend<value_type>(_array); 912 return _inarray_access_traits::rend<value_type>(_array);
387 } 913 }
914
915 /**
916 * @brief Get a reverse iterator pointing to the reverse begin of the array.
917 * @return Reverse iterator pointing to the reverse begin of the array.
918 *
919 * This member function returns a reverse iterator pointing to the
920 * last element of the array. If the array is empty the returned
921 * reverse iterator is the same as the one returned by @ref rend().
922 */
388 reverse_iterator rbegin() 923 reverse_iterator rbegin()
389 { 924 {
390 return _inarray_access_traits::rbegin<value_type>(_array); 925 return _inarray_access_traits::rbegin<value_type>(_array);
391 } 926 }
927
928 /**
929 * @brief Get a reverse iterator pointing to the reverse end of the array.
930 * @return Reverse iterator pointing to the reverse end of the array.
931 *
932 * This member function returns a reverse iterator pointing to the
933 * position before the first element of the array. If the array is
934 * empty the returned iterator is the same as the one returned by
935 * @ref rbegin().
936 *
937 * @note Note that attempting to access this position causes undefined
938 * behavior.
939 */
392 reverse_iterator rend() 940 reverse_iterator rend()
393 { 941 {
394 return _inarray_access_traits::rend<value_type>(_array); 942 return _inarray_access_traits::rend<value_type>(_array);
395 } 943 }
944
945 /**
946 * @brief Get a constant iterator pointing to the first element of the array.
947 * @return Constant iterator to the initial position of the array.
948 *
949 * This member function works like @ref begin() const but is granted
950 * to return a constant iterator even for arrays that are not
951 * const-qualified.
952 */
396 const_iterator cbegin() const 953 const_iterator cbegin() const
397 { 954 {
398 return _inarray_access_traits::cbegin<value_type>(_array); 955 return _inarray_access_traits::cbegin<value_type>(_array);
399 } 956 }
957
958 /**
959 * @brief Get a constant iterator to the position following the last element of the array.
960 * @return Constant iterator to the final position of the array.
961 *
962 * This member function works like @ref end() const but is granted to
963 * return a constant iterator even for arrays that are not
964 * const-qualified.
965 */
400 const_iterator cend() const 966 const_iterator cend() const
401 { 967 {
402 return _inarray_access_traits::cend<value_type>(_array); 968 return _inarray_access_traits::cend<value_type>(_array);
403 } 969 }
970
971 /**
972 * @brief Get a constant reverse iterator pointing to the reverse begin of the array.
973 * @return Constant reverse iterator pointing to the reverse begin of the array.
974 *
975 * This member function works like @ref rbegin() const but is granted
976 * to return a constant reverse iterator even for arrays that are not
977 * const-qualified.
978 */
404 const_reverse_iterator crbegin() const 979 const_reverse_iterator crbegin() const
405 { 980 {
406 return _inarray_access_traits::crbegin<value_type>(_array); 981 return _inarray_access_traits::crbegin<value_type>(_array);
407 } 982 }
983
984 /**
985 * @brief Get a constant reverse iterator pointing to the reverse end of the array.
986 * @return Constant reverse iterator pointing to the reverse end of the array.
987 *
988 * This member function works like @ref rend() const but is granted to
989 * return a constant reverse iterator even for arrays that are not
990 * const-qualified.
991 */
408 const_reverse_iterator crend() const 992 const_reverse_iterator crend() const
409 { 993 {
410 return _inarray_access_traits::crend<value_type>(_array); 994 return _inarray_access_traits::crend<value_type>(_array);
411 } 995 }
996
997 /**
998 * @brief Swap content between two inline arrays.
999 * @param other Other inline array of the same type.
1000 */
412 void swap(_pod_inarray<T>& other) 1001 void swap(_pod_inarray<T>& other)
413 { 1002 {
414 std::swap(_array, other._array); 1003 std::swap(_array, other._array);
415 } 1004 }
1005
1006 /**
1007 * @brief Get the maximum number of elements a inline array can hold.
1008 * @return Maximum number of elements a inline array can hold.
1009 */
416 size_type max_size() const { return -1; } 1010 size_type max_size() const { return -1; }
417 1011
1012 /**
1013 * @brief Get a handle for the wrapped Eina_Inarray.
1014 * @return Handle for the native Eina inline array.
1015 *
1016 * This member function returns the native Eina_Inarray handle that is
1017 * wrapped inside this object.
1018 *
1019 * @warning It is important to take care when using it, since the
1020 * handle will be automatically release upon object destruction.
1021 */
418 Eina_Inarray* native_handle() 1022 Eina_Inarray* native_handle()
419 { 1023 {
420 return this->_array; 1024 return this->_array;
421 } 1025 }
1026
1027 /**
1028 * @brief Get a constant handle for the wrapped Eina_Inarray.
1029 * @return Constant handle for the native Eina inline array.
1030 *
1031 * Version of @ref native_handle() for const-qualified objects.Returns
1032 * a constant handle instead.
1033 *
1034 * @see native_handle()
1035 */
422 Eina_Inarray const* native_handle() const 1036 Eina_Inarray const* native_handle() const
423 { 1037 {
424 return this->_array; 1038 return this->_array;
@@ -428,34 +1042,81 @@ public:
428template <typename T> 1042template <typename T>
429class _nonpod_inarray : _inarray_common_base 1043class _nonpod_inarray : _inarray_common_base
430{ 1044{
431 typedef _inarray_common_base _base_type; 1045 typedef _inarray_common_base _base_type; /**< Type for the base class. */
432public: 1046public:
433 typedef T value_type; 1047 typedef T value_type; /**< The type of each element. */
434 typedef T& reference; 1048 typedef T& reference; /**< Type for a reference to an element. */
435 typedef T const& const_reference; 1049 typedef T const& const_reference; /**< Type for a constant reference to an element. */
436 typedef T* pointer; 1050 typedef T* pointer; /**< Type for a pointer to an element. */
437 typedef T const* const_pointer; 1051 typedef T const* const_pointer; /**< Type for a constant pointer for an element. */
1052
1053 /**
1054 * Type for a iterator to this kind of inline array.
1055 * Defined as a @ref pointer for performance reasons.
1056 */
438 typedef pointer iterator; 1057 typedef pointer iterator;
1058
1059 /**
1060 * Type for a constant iterator for this kind of inline array.
1061 * Defined as a @ref const_pointer for performance reasons.
1062 */
439 typedef const_pointer const_iterator; 1063 typedef const_pointer const_iterator;
440 typedef std::size_t size_type; 1064 typedef std::size_t size_type; /**< Type for size information used in the array. */
441 typedef std::ptrdiff_t difference_type; 1065 typedef std::ptrdiff_t difference_type; /**< Type to represent the distance between two iterators. */
442 1066
443 typedef std::reverse_iterator<iterator> reverse_iterator; 1067 typedef std::reverse_iterator<iterator> reverse_iterator; /** Type for the native @c Eina_Inarray handle. */
444 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1068 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; /** Type for constant native @c Eina_Inarray handle. */
445 1069
446 using _base_type::size; 1070 using _base_type::size;
447 using _base_type::empty; 1071 using _base_type::empty;
448 1072
1073 /**
1074 * @brief Create a new object from a handle to a native Eina_Inarray.
1075 * @param array Handle to a native Eina_Inarray.
1076 *
1077 * This constructor wraps a pre-allocated Eina_Inarray providing an
1078 * OOP interface to it.
1079 *
1080 * @warning It is important to note that the created object gains
1081 * ownership of the handle, deallocating it at destruction time.
1082 */
449 _nonpod_inarray(Eina_Inarray* array) 1083 _nonpod_inarray(Eina_Inarray* array)
450 : _base_type(array) {} 1084 : _base_type(array) {}
1085
1086 /**
1087 * @brief Default constructor. Create an empty array.
1088 *
1089 * This constructor creates an array object with no elements. Elements
1090 * are declarated as having the same size of the given template
1091 * typename argument.
1092 */
451 _nonpod_inarray() : _base_type(sizeof(T)) 1093 _nonpod_inarray() : _base_type(sizeof(T))
452 { 1094 {
453 } 1095 }
1096
1097 /**
1098 * @brief Construct an array object with @p n copies of @p t.
1099 * @param n Number of elements.
1100 * @param t Value to be copied to each element.
1101 *
1102 * This constructor creates an inline array with @p n elements, each
1103 * one as a copy of @p t.
1104 */
454 _nonpod_inarray(size_type n, value_type const& t) : _base_type(sizeof(T)) 1105 _nonpod_inarray(size_type n, value_type const& t) : _base_type(sizeof(T))
455 { 1106 {
456 while(n--) 1107 while(n--)
457 push_back(t); 1108 push_back(t);
458 } 1109 }
1110
1111 /**
1112 * @brief Create a inline array coping the elements from the given range.
1113 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
1114 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
1115 *
1116 * This constructor creates a inline array with copies of the elements
1117 * between @p i and @p j in the same order. Note that the ending
1118 * element (pointed by @p j) is excluded.
1119 */
459 template <typename InputIterator> 1120 template <typename InputIterator>
460 _nonpod_inarray(InputIterator i, InputIterator const& j 1121 _nonpod_inarray(InputIterator i, InputIterator const& j
461 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0) 1122 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
@@ -467,23 +1128,52 @@ public:
467 ++i; 1128 ++i;
468 } 1129 }
469 } 1130 }
1131
1132 /**
1133 * @brief Copy constructor. Creates a copy of the given inline array.
1134 * @param other Another inline array of the same type.
1135 *
1136 * This constructor creates an inline array containing a copy of each
1137 * element inside @p other in the same order.
1138 */
470 _nonpod_inarray(_nonpod_inarray<T>const& other) 1139 _nonpod_inarray(_nonpod_inarray<T>const& other)
471 : _base_type(sizeof(T)) 1140 : _base_type(sizeof(T))
472 { 1141 {
473 insert(end(), other.begin(), other.end()); 1142 insert(end(), other.begin(), other.end());
474 } 1143 }
1144
1145 /**
1146 * @brief Destructor of array for non-POD elements.
1147 *
1148 * Calls the destructor of each allocated element, before the base
1149 * class destructor releases their memory.
1150 */
475 ~_nonpod_inarray() 1151 ~_nonpod_inarray()
476 { 1152 {
477 for(T* first = static_cast<T*>(_array->members) 1153 for(T* first = static_cast<T*>(_array->members)
478 , *last = first + _array->len; first != last; ++first) 1154 , *last = first + _array->len; first != last; ++first)
479 first->~T(); 1155 first->~T();
480 } 1156 }
1157
1158 /**
1159 * @brief Replace current content with the cotent of another array.
1160 * @param other Another inline array of the same type.
1161 *
1162 * This assignment operator replaces the content of the array by a
1163 * copy of the content of the given array @p other. The array size is
1164 * adjusted accordingly and the newly copied elements keep their
1165 * original order.
1166 */
481 _nonpod_inarray<T>& operator=(_nonpod_inarray<T>const& other) 1167 _nonpod_inarray<T>& operator=(_nonpod_inarray<T>const& other)
482 { 1168 {
483 clear(); 1169 clear();
484 insert(end(), other.begin(), other.end()); 1170 insert(end(), other.begin(), other.end());
485 return *this; 1171 return *this;
486 } 1172 }
1173
1174 /**
1175 * @brief Remove all the elements of the array.
1176 */
487 void clear() 1177 void clear()
488 { 1178 {
489 for(T* first = static_cast<T*>(_array->members) 1179 for(T* first = static_cast<T*>(_array->members)
@@ -491,20 +1181,61 @@ public:
491 first->~T(); 1181 first->~T();
492 ::eina_inarray_flush(_array); 1182 ::eina_inarray_flush(_array);
493 } 1183 }
1184
1185 /**
1186 * @brief Add a copy of the given element at the end of the array.
1187 * @param value Element to be added at the end of the array.
1188 *
1189 * This member function allocates a new element at the end of the
1190 * inline array, the content of @p value is copied to the new element.
1191 */
494 void push_back(T const& value) 1192 void push_back(T const& value)
495 { 1193 {
496 insert(end(), 1u, value); 1194 insert(end(), 1u, value);
497 } 1195 }
1196
1197 /**
1198 * @brief Remove the last element of the array.
1199 */
498 void pop_back() 1200 void pop_back()
499 { 1201 {
500 T* elem = static_cast<T*>(_array->members) + _array->len - 1; 1202 T* elem = static_cast<T*>(_array->members) + _array->len - 1;
501 elem->~T(); 1203 elem->~T();
502 eina_inarray_pop(_array); 1204 eina_inarray_pop(_array);
503 } 1205 }
1206
1207 /**
1208 * @brief Insert a new element at the given position.
1209 * @param i Iterator pointing to the position where the new element will be inserted.
1210 * @param t Value to be copied to the new element.
1211 * @return Iterator pointing to the new element inserted.
1212 *
1213 * This member function inserts a copy of the element @p t at the
1214 * position @p i. The new element comes right before the element
1215 * originally pointed by @p i.
1216 *
1217 * At the end, a valid iterator pointing to the element just inserted
1218 * is returned.
1219 */
504 iterator insert(iterator i, value_type const& t) 1220 iterator insert(iterator i, value_type const& t)
505 { 1221 {
506 return insert(i, 1u, t); 1222 return insert(i, 1u, t);
507 } 1223 }
1224
1225 /**
1226 * @brief Insert @p n copies of @p t at the given position.
1227 * @param i Iterator pointing to the position where the new elements will be inserted.
1228 * @param n Number of elements to be inserted.
1229 * @param t Value to be copied to each new inserted element.
1230 * @return Iterator pointing to the first inserted element.
1231 *
1232 * This member function inserts @p n new elements at position @p i
1233 * in the array, each one as a copy of @p t. The new elements come
1234 * right before the element originally pointed by @p i.
1235 *
1236 * At the end, a valid iterator pointing to the first element inserted
1237 * is returned.
1238 */
508 iterator insert(iterator i, size_t n, value_type const& t) 1239 iterator insert(iterator i, size_t n, value_type const& t)
509 { 1240 {
510 if(_array->max - _array->len >= n) 1241 if(_array->max - _array->len >= n)
@@ -546,7 +1277,7 @@ public:
546 , first = begin() 1277 , first = begin()
547 , last = first + _array->len; 1278 , last = first + _array->len;
548 i = index + begin(); 1279 i = index + begin();
549 1280
550 while(first != i) 1281 while(first != i)
551 { 1282 {
552 new (&*first++) T(*old_first); 1283 new (&*first++) T(*old_first);
@@ -565,6 +1296,19 @@ public:
565 } 1296 }
566 return i; 1297 return i;
567 } 1298 }
1299
1300 /**
1301 * @brief Insert the elements between the given range at the given position.
1302 * @param p Iterator pointing to the position where the new elements will be inserted.
1303 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
1304 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
1305 * @return Iterator pointing to the first inserted element.
1306 *
1307 * This member function inserts a copy of the elements between @p i
1308 * and @p j at the position @p p. The new elements come right before
1309 * the element originally pointed by @p p. Note that the element
1310 * pointed by @p j is not copied.
1311 */
568 template <typename InputIterator> 1312 template <typename InputIterator>
569 iterator insert(iterator p, InputIterator i, InputIterator j 1313 iterator insert(iterator p, InputIterator i, InputIterator j
570 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0) 1314 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
@@ -579,10 +1323,34 @@ public:
579 } 1323 }
580 return p - n; 1324 return p - n;
581 } 1325 }
1326
1327 /**
1328 * @brief Remove the element at the given position.
1329 * @param q Iterator pointing to the element to be removed.
1330 * @return Iterator pointing to the element after the removed one.
1331 *
1332 * This member function removes the element pointed by the iterator
1333 * @p q, reducing the array size by one. At the end, a valid iterator
1334 * pointing to the element right after the removed one is returned.
1335 */
582 iterator erase(iterator q) 1336 iterator erase(iterator q)
583 { 1337 {
584 return erase(q, q+1); 1338 return erase(q, q+1);
585 } 1339 }
1340
1341 /**
1342 * @brief Remove the elements between the given range.
1343 * @param i Iterator pointing to the starting position to be removed.
1344 * @param j Iterator pointing to the ending position to be removed.
1345 * The element pointed by this iterator is not removed.
1346 * @return Iterator pointing to the new position of the first
1347 * non-removed element after the removed ones (i.e. the one
1348 * originally pointed by j).
1349 *
1350 * This member function removes the elements between the iterators
1351 * @p i and @p j, including the element pointed by @p i but not the
1352 * element pointed by @j.
1353 */
586 iterator erase(iterator i, iterator j) 1354 iterator erase(iterator i, iterator j)
587 { 1355 {
588 iterator last = end(); 1356 iterator last = end();
@@ -595,118 +1363,373 @@ public:
595 1363
596 return i; 1364 return i;
597 } 1365 }
1366
1367 /**
1368 * @brief Replace the content of the array by the elements in the given range.
1369 * @param i Iterator pointing to the beginning of the elements to be copied.
1370 * @param j Iterator pointing to the end of the elements to be copied.
1371 * Note that the element pointed by j will NOT be copied.
1372 *
1373 * This member function replaces the current elements by copies of the
1374 * elements between the iterators @p i and @p j, including the element
1375 * pointed by @p i but not the one pointed by @p j. The size of the
1376 * array is adjusted accordingly and the newly copied elements remain
1377 * in their original order.
1378 */
598 template <typename InputIterator> 1379 template <typename InputIterator>
599 void assign(InputIterator i, InputIterator j 1380 void assign(InputIterator i, InputIterator j
600 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0); 1381 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0);
1382
1383 /**
1384 * @brief Replace the content of the array by @p n copies @p t.
1385 * @param n Number of elements.
1386 * @param t Value to be copied to each element.
1387 */
601 void assign(size_type n, value_type const& t); 1388 void assign(size_type n, value_type const& t);
1389
1390 /**
1391 * @brief Get a reference to the element at the given position.
1392 * @param i Position of the element.
1393 * @return Reference to the element at the ith position.
1394 */
602 value_type& operator[](size_type i) 1395 value_type& operator[](size_type i)
603 { 1396 {
604 return *(begin() + i); 1397 return *(begin() + i);
605 } 1398 }
1399
1400
1401 /**
1402 * @brief Get a constant reference to the element at the given position.
1403 * @param i Position of the element.
1404 * @return Constant reference to the element at the ith position.
1405 *
1406 * Version of @ref operator[](size_type i) for const-qualified inline
1407 * array objects. Return a constant reference instead.
1408 */
606 value_type const& operator[](size_type i) const 1409 value_type const& operator[](size_type i) const
607 { 1410 {
608 return const_cast<inarray<T>&>(*this)[i]; 1411 return const_cast<inarray<T>&>(*this)[i];
609 } 1412 }
1413
1414 /**
1415 * @brief Get a reference to the last element.
1416 * @return Reference to the last element in the array.
1417 */
610 value_type& back() 1418 value_type& back()
611 { 1419 {
612 return _inarray_access_traits::back<value_type>(_array); 1420 return _inarray_access_traits::back<value_type>(_array);
613 } 1421 }
1422
1423 /**
1424 * @brief Get a constant reference to the last element.
1425 * @return Constant reference to the last element in the array.
1426 *
1427 * Version of @ref back() for const-qualified inline array objects.
1428 * Return a constant reference instead.
1429 */
614 value_type const& back() const 1430 value_type const& back() const
615 { 1431 {
616 return _inarray_access_traits::back<value_type>(_array); 1432 return _inarray_access_traits::back<value_type>(_array);
617 } 1433 }
1434
1435 /**
1436 * @brief Get a reference to the first element.
1437 * @return Reference to the first element of the array.
1438 */
618 value_type& front() 1439 value_type& front()
619 { 1440 {
620 return _inarray_access_traits::front<value_type>(_array); 1441 return _inarray_access_traits::front<value_type>(_array);
621 } 1442 }
1443
1444 /**
1445 * @brief Get a constant reference to the first element.
1446 * @return Constant reference to the first element of the array.
1447 *
1448 * Version of @ref front() for const-qualified inline array objects.
1449 * Return a constant reference instead.
1450 */
622 value_type const& front() const 1451 value_type const& front() const
623 { 1452 {
624 return _inarray_access_traits::front<value_type>(_array); 1453 return _inarray_access_traits::front<value_type>(_array);
625 } 1454 }
1455
1456 /**
1457 * @brief Get an iterator pointing to the first element of the array.
1458 * @return Iterator to the initial position of the array.
1459 *
1460 * This member function returns an iterator pointing to the first
1461 * element of the array. If the array is empty the returned iterator
1462 * is the same as the one returned by @ref end().
1463 */
626 iterator begin() 1464 iterator begin()
627 { 1465 {
628 return _inarray_access_traits::begin<value_type>(_array); 1466 return _inarray_access_traits::begin<value_type>(_array);
629 } 1467 }
1468
1469 /**
1470 * @brief Get an iterator to the position following the last element of the array.
1471 * @return Iterator to the final position of the array.
1472 *
1473 * This member function returns an iterator to the position following
1474 * the last element in the array. If the array is empty the returned
1475 * iterator is the same as the one returned by @ref begin().
1476 * Note that attempting to access this position causes undefined
1477 * behavior.
1478 */
630 iterator end() 1479 iterator end()
631 { 1480 {
632 return _inarray_access_traits::end<value_type>(_array); 1481 return _inarray_access_traits::end<value_type>(_array);
633 } 1482 }
1483
1484 /**
1485 * @brief Get a constant iterator pointing to the first element of the array.
1486 * @return Constant iterator to the initial position of the array.
1487 *
1488 * Version of @ref begin() for const-qualified inline array objects.
1489 * Returns a constant iterator instead.
1490 */
634 const_iterator begin() const 1491 const_iterator begin() const
635 { 1492 {
636 return _inarray_access_traits::begin<value_type>(_array); 1493 return _inarray_access_traits::begin<value_type>(_array);
637 } 1494 }
1495
1496 /**
1497 * @brief Get a constant iterator to the position following the last element of the array.
1498 * @return Constant iterator to the final position of the array.
1499 *
1500 * Version of @ref end() for const-qualified inline array objects.
1501 * Returns a constant iterator instead.
1502 */
638 const_iterator end() const 1503 const_iterator end() const
639 { 1504 {
640 return _inarray_access_traits::end<value_type>(_array); 1505 return _inarray_access_traits::end<value_type>(_array);
641 } 1506 }
1507
1508 /**
1509 * @brief Get a constant reverse iterator pointing to the reverse begin of the array.
1510 * @return Constant reverse iterator pointing to the reverse begin of the array.
1511 *
1512 * Version of @ref rbegin() for const-qualified inline array objects.
1513 * Returns a constant reverse iterator instead.
1514 */
642 const_reverse_iterator rbegin() const 1515 const_reverse_iterator rbegin() const
643 { 1516 {
644 return _inarray_access_traits::rbegin<value_type>(_array); 1517 return _inarray_access_traits::rbegin<value_type>(_array);
645 } 1518 }
1519
1520 /**
1521 * @brief Get a constant reverse iterator pointing to the reverse end of the array.
1522 * @return Constant reverse iterator pointing to the reverse end of the array.
1523 *
1524 * Version of @ref rend() for const-qualified inline array objects.
1525 * Returns a constant reverse iterator instead.
1526 */
646 const_reverse_iterator rend() const 1527 const_reverse_iterator rend() const
647 { 1528 {
648 return _inarray_access_traits::rend<value_type>(_array); 1529 return _inarray_access_traits::rend<value_type>(_array);
649 } 1530 }
1531
1532 /**
1533 * @brief Get a reverse iterator pointing to the reverse begin of the array.
1534 * @return Reverse iterator pointing to the reverse begin of the array.
1535 *
1536 * This member function returns a reverse iterator pointing to the
1537 * last element of the array. If the array is empty the returned
1538 * reverse iterator is the same as the one returned by @ref rend().
1539 */
650 reverse_iterator rbegin() 1540 reverse_iterator rbegin()
651 { 1541 {
652 return _inarray_access_traits::rbegin<value_type>(_array); 1542 return _inarray_access_traits::rbegin<value_type>(_array);
653 } 1543 }
1544
1545 /**
1546 * @brief Get a reverse iterator pointing to the reverse end of the array.
1547 * @return Reverse iterator pointing to the reverse end of the array.
1548 *
1549 * This member function returns a reverse iterator pointing to the
1550 * position before the first element of the array. If the array is
1551 * empty the returned iterator is the same as the one returned by
1552 * @ref rbegin().
1553 *
1554 * @note Note that attempting to access this position causes undefined
1555 * behavior.
1556 */
654 reverse_iterator rend() 1557 reverse_iterator rend()
655 { 1558 {
656 return _inarray_access_traits::rend<value_type>(_array); 1559 return _inarray_access_traits::rend<value_type>(_array);
657 } 1560 }
1561
1562 /**
1563 * @brief Get a constant iterator pointing to the first element of the array.
1564 * @return Constant iterator to the initial position of the array.
1565 *
1566 * This member function works like the constant overload of @ref begin()
1567 * but is granted to return a constant iterator even for arrays that
1568 * are not const-qualified.
1569 */
658 const_iterator cbegin() const 1570 const_iterator cbegin() const
659 { 1571 {
660 return _inarray_access_traits::cbegin<value_type>(_array); 1572 return _inarray_access_traits::cbegin<value_type>(_array);
661 } 1573 }
1574
1575 /**
1576 * @brief Get a constant iterator to the position following the last element of the array.
1577 * @return Constant iterator to the final position of the array.
1578 *
1579 * This member function works like the constant overload of @ref end()
1580 * but is granted to return a constant iterator even for arrays that
1581 * are not const-qualified.
1582 */
662 const_iterator cend() const 1583 const_iterator cend() const
663 { 1584 {
664 return _inarray_access_traits::cend<value_type>(_array); 1585 return _inarray_access_traits::cend<value_type>(_array);
665 } 1586 }
1587
1588 /**
1589 * @brief Get a constant reverse iterator pointing to the reverse begin of the array.
1590 * @return Constant reverse iterator pointing to the reverse begin of the array.
1591 *
1592 * This member function works like the constant overload of @ref rbegin()
1593 * but is granted to return a constant reverse iterator even for
1594 * arrays that are not const-qualified.
1595 */
666 const_reverse_iterator crbegin() const 1596 const_reverse_iterator crbegin() const
667 { 1597 {
668 return _inarray_access_traits::crbegin<value_type>(_array); 1598 return _inarray_access_traits::crbegin<value_type>(_array);
669 } 1599 }
1600
1601 /**
1602 * @brief Get a constant reverse iterator pointing to the reverse end of the array.
1603 * @return Constant reverse iterator pointing to the reverse end of the array.
1604 *
1605 * This member function works like the constant overload of @ref rend()
1606 * but is granted to return a constant reverse iterator even for
1607 * arrays that are not const-qualified.
1608 */
670 const_reverse_iterator crend() const 1609 const_reverse_iterator crend() const
671 { 1610 {
672 return _inarray_access_traits::crend<value_type>(_array); 1611 return _inarray_access_traits::crend<value_type>(_array);
673 } 1612 }
1613
1614 /**
1615 * @brief Swap content between two inline arrays.
1616 * @param other Other inline array of the same type.
1617 */
674 void swap(_nonpod_inarray<T>& other) 1618 void swap(_nonpod_inarray<T>& other)
675 { 1619 {
676 std::swap(_array, other._array); 1620 std::swap(_array, other._array);
677 } 1621 }
1622
1623 /**
1624 * @brief Get the maximum number of elements a inline array can hold.
1625 * @return Maximum number of elements a inline array can hold.
1626 */
678 size_type max_size() const { return -1; } 1627 size_type max_size() const { return -1; }
679 1628
1629 /**
1630 * @brief Get the handle for the wrapped Eina_Inarray.
1631 * @return Internal handle for the native Eina inline array.
1632 *
1633 * This member function returns the native Eina_Inarray handle that is
1634 * wrapped inside this object. It is important to take care when using
1635 * it, since the handle will be automatically release upon object
1636 * destruction.
1637 */
680 Eina_Inarray* native_handle() 1638 Eina_Inarray* native_handle()
681 { 1639 {
682 return this->_array; 1640 return this->_array;
683 } 1641 }
1642
1643 /**
1644 * @brief Get the handle for the wrapped Eina_Inarray.
1645 * @return Internal handle for the native Eina inline array.
1646 *
1647 * This member function returns the native Eina_Inarray handle that is
1648 * wrapped inside this object. It is important to take care when using
1649 * it, since the handle will be automatically release upon object
1650 * destruction.
1651 */
684 Eina_Inarray const* native_handle() const 1652 Eina_Inarray const* native_handle() const
685 { 1653 {
686 return this->_array; 1654 return this->_array;
687 } 1655 }
688}; 1656};
689 1657
1658
1659/**
1660 * Inline array class. It provides an OOP interface to the
1661 * @c Eina_Inarray functions, and automatically take care of allocating
1662 * and deallocating resources using the RAII programming idiom.
1663 *
1664 * It also provides additional member functions to facilitate the access
1665 * to the array content, much like a STL vector.
1666 */
690template <typename T> 1667template <typename T>
691class inarray : public eina::if_<eina::is_pod<T>, _pod_inarray<T> 1668class inarray : public eina::if_<eina::is_pod<T>, _pod_inarray<T>
692 , _nonpod_inarray<T> >::type 1669 , _nonpod_inarray<T> >::type
693{ 1670{
694 typedef typename eina::if_<eina::is_pod<T>, _pod_inarray<T> 1671 typedef typename eina::if_<eina::is_pod<T>, _pod_inarray<T>
695 , _nonpod_inarray<T> >::type _base_type; 1672 , _nonpod_inarray<T> >::type _base_type; /**< Type for the base class. */
696public: 1673public:
1674
1675 /**
1676 * @brief Create a new object from a handle to a native Eina_Inarray.
1677 * @param array Handle to a native Eina_Inarray.
1678 *
1679 * This constructor wraps a pre-allocated Eina_Inarray providing an
1680 * OOP interface to it.
1681 *
1682 * @warning It is important to note that the created object gains
1683 * ownership of the handle, deallocating it at destruction time.
1684 */
697 inarray(Eina_Inarray* array) 1685 inarray(Eina_Inarray* array)
698 : _base_type(array) {} 1686 : _base_type(array) {}
1687
1688 /**
1689 * @brief Default constructor. Creates an empty array.
1690 */
699 inarray() : _base_type() {} 1691 inarray() : _base_type() {}
1692
1693 /**
1694 * @brief Construct an array object with @p n copies of @p t.
1695 * @param n Number of elements.
1696 * @param t Value to be copied to each element.
1697 *
1698 * This constructor creates an inline array with @p n elements, each
1699 * one as a copy of @p t.
1700 */
700 inarray(typename _base_type::size_type n, typename _base_type::value_type const& t) 1701 inarray(typename _base_type::size_type n, typename _base_type::value_type const& t)
701 : _base_type(n, t) {} 1702 : _base_type(n, t) {}
1703
1704 /**
1705 * @brief Create a inline array with elements from the given range.
1706 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
1707 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
1708 *
1709 * This constructor creates a inline array with copies of the elements
1710 * between @p i and @p j in the same order.
1711 *
1712 * @note The ending element (pointed by @p j) is not copied.
1713 */
702 template <typename InputIterator> 1714 template <typename InputIterator>
703 inarray(InputIterator i, InputIterator const& j 1715 inarray(InputIterator i, InputIterator const& j
704 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0) 1716 , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
705 : _base_type(i, j) 1717 : _base_type(i, j)
706 {} 1718 {}
707 1719
708}; 1720};
709 1721
1722/**
1723 * @brief Check if two inline arrays are equal.
1724 * @param lhs Inline array at the left side of the expression.
1725 * @param rhs Inline array at the right side of the expression.
1726 * @return @c true if the arrays are equals, @c false otherwise.
1727 *
1728 * This operator checks if the given inline arrays are equal. To be
1729 * considered equal both arrays need to have the same number of
1730 * elements, and each element in one array must be equal to the element
1731 * at the same position in the other array.
1732 */
710template <typename T> 1733template <typename T>
711bool operator==(inarray<T> const& lhs, inarray<T> const& rhs) 1734bool operator==(inarray<T> const& lhs, inarray<T> const& rhs)
712{ 1735{
@@ -714,19 +1737,38 @@ bool operator==(inarray<T> const& lhs, inarray<T> const& rhs)
714 std::equal(lhs.begin(), lhs.end(), rhs.begin()); 1737 std::equal(lhs.begin(), lhs.end(), rhs.begin());
715} 1738}
716 1739
1740/**
1741 * @brief Check if two inline arrays are different.
1742 * @param lhs Inline array at the left side of the expression.
1743 * @param rhs Inline array at the right side of the expression.
1744 * @return @c true if the arrays are not equal , @c false otherwise.
1745 *
1746 * This operator returns the opposite of @ref operator==(inarray<T> const& lhs, inarray<T> const& rhs).
1747 */
717template <typename T> 1748template <typename T>
718bool operator!=(inarray<T> const& lhs, inarray<T> const& rhs) 1749bool operator!=(inarray<T> const& lhs, inarray<T> const& rhs)
719{ 1750{
720 return !(lhs == rhs); 1751 return !(lhs == rhs);
721} 1752}
722 1753
1754/**
1755 * @brief Swap content between two inline arrays.
1756 * @param other Other inline array of the same type.
1757 */
723template <typename T> 1758template <typename T>
724void swap(inarray<T>& lhs, inarray<T>& rhs) 1759void swap(inarray<T>& lhs, inarray<T>& rhs)
725{ 1760{
726 lhs.swap(rhs); 1761 lhs.swap(rhs);
727} 1762}
728 1763
1764/**
1765 * @}
1766 */
729 1767
730} } 1768} }
731 1769
1770/**
1771 * @}
1772 */
1773
732#endif 1774#endif
diff --git a/src/bindings/eina_cxx/eina_inlist.hh b/src/bindings/eina_cxx/eina_inlist.hh
index 7fdf166..4d83632 100644
--- a/src/bindings/eina_cxx/eina_inlist.hh
+++ b/src/bindings/eina_cxx/eina_inlist.hh
@@ -10,8 +10,24 @@
10#include <iterator> 10#include <iterator>
11#include <algorithm> 11#include <algorithm>
12 12
13/**
14 * @addtogroup Eina_Cxx_Containers_Group
15 *
16 * @{
17 */
18
13namespace efl { namespace eina { 19namespace efl { namespace eina {
14 20
21/**
22 * @defgroup Eina_Cxx_Inline_List_Group Inline List
23 * @ingroup Eina_Cxx_Containers_Group
24 *
25 * @{
26 */
27
28/**
29 * @internal
30 */
15template <typename T> 31template <typename T>
16struct _inlist_node 32struct _inlist_node
17{ 33{
@@ -19,18 +35,27 @@ struct _inlist_node
19 T object; 35 T object;
20}; 36};
21 37
38/**
39 * @internal
40 */
22template <typename T> 41template <typename T>
23_inlist_node<T>* _get_node(Eina_Inlist* l) 42_inlist_node<T>* _get_node(Eina_Inlist* l)
24{ 43{
25 return static_cast<_inlist_node<T>*>(static_cast<void*>(l)); 44 return static_cast<_inlist_node<T>*>(static_cast<void*>(l));
26} 45}
27 46
47/**
48 * @internal
49 */
28template <typename T> 50template <typename T>
29_inlist_node<T> const* _get_node(Eina_Inlist const* l) 51_inlist_node<T> const* _get_node(Eina_Inlist const* l)
30{ 52{
31 return const_cast<Eina_Inlist*>(l); 53 return const_cast<Eina_Inlist*>(l);
32} 54}
33 55
56/**
57 * @internal
58 */
34template <typename T> 59template <typename T>
35Eina_Inlist* _get_list(_inlist_node<T>* n) 60Eina_Inlist* _get_list(_inlist_node<T>* n)
36{ 61{
@@ -40,38 +65,85 @@ Eina_Inlist* _get_list(_inlist_node<T>* n)
40 return 0; 65 return 0;
41} 66}
42 67
68/**
69 * @internal
70 */
43template <typename T> 71template <typename T>
44Eina_Inlist const* _get_list(_inlist_node<T> const* n) 72Eina_Inlist const* _get_list(_inlist_node<T> const* n)
45{ 73{
46 return _get_list(const_cast<_inlist_node<T>*>(n)); 74 return _get_list(const_cast<_inlist_node<T>*>(n));
47} 75}
48 76
77/**
78 * @internal
79 * Iterator for Inline List
80 */
49template <typename T> 81template <typename T>
50struct _inlist_iterator 82struct _inlist_iterator
51{ 83{
52 typedef typename std::remove_const<T>::type value_type; 84 typedef typename std::remove_const<T>::type value_type; /**< Type for the list elements. */
53 typedef value_type* pointer; 85 typedef value_type* pointer; /**< Type for a pointer to an element. */
54 typedef value_type& reference; 86 typedef value_type& reference; /**< Type for a reference to an element. */
55 typedef std::ptrdiff_t difference_type; 87 typedef std::ptrdiff_t difference_type; /**< Type to represent the distance between two iterators. */
56 typedef std::bidirectional_iterator_tag iterator_category; 88 typedef std::bidirectional_iterator_tag iterator_category; /**< Defines the iterator as being a bidirectional iterator. */
57 89
90 /**
91 * @brief Default constructor. Creates an uninitialized iterator.
92 */
58 _inlist_iterator() {} 93 _inlist_iterator() {}
94
95 /**
96 * @brief Creates an iterator from a inline list and a node.
97 * @param list Pointer to the inline list.
98 * @param node Pointer to the node.
99 */
59 explicit _inlist_iterator(_inlist_node<value_type>* list, _inlist_node<value_type>* node) 100 explicit _inlist_iterator(_inlist_node<value_type>* list, _inlist_node<value_type>* node)
60 : _list(list), _node(node) {} 101 : _list(list), _node(node) {}
102
103 /**
104 * @brief Copy constructor. Creates a copy of the given iterator.
105 * @param other Other iterator.
106 */
61 _inlist_iterator(_inlist_iterator<typename std::remove_const<T>::type> const& other) 107 _inlist_iterator(_inlist_iterator<typename std::remove_const<T>::type> const& other)
62 : _list(other._list), _node(other._node) {} 108 : _list(other._list), _node(other._node) {}
63 109
110 /**
111 * @brief Move the iterator to the next position in the list.
112 * @return The iterator itself.
113 *
114 * This operator increments the iterator, making it point to the
115 * position right after the current one.
116 * At the end, it returns a reference to itself.
117 */
64 _inlist_iterator<T>& operator++() 118 _inlist_iterator<T>& operator++()
65 { 119 {
66 _node = _get_node<value_type>(_node->__in_list.next); 120 _node = _get_node<value_type>(_node->__in_list.next);
67 return *this; 121 return *this;
68 } 122 }
123
124 /**
125 * @brief Move the iterator to the next position in the list.
126 * @return Copy of the iterator before the increment.
127 *
128 * This operator increments the iterator, making it point to the next
129 * position right after the current one.
130 * At the end, it returns a copy of the iterator before the increment.
131 */
69 _inlist_iterator<T> operator++(int) 132 _inlist_iterator<T> operator++(int)
70 { 133 {
71 _inlist_iterator<T> tmp(*this); 134 _inlist_iterator<T> tmp(*this);
72 ++*this; 135 ++*this;
73 return tmp; 136 return tmp;
74 } 137 }
138
139 /**
140 * @brief Move the iterator to the previous position in the list.
141 * @return The iterator itself.
142 *
143 * This operator decrements the iterator, making it point to the
144 * position right before the current one.
145 * At the end, it returns a reference to itself.
146 */
75 _inlist_iterator<T>& operator--() 147 _inlist_iterator<T>& operator--()
76 { 148 {
77 if(_node) 149 if(_node)
@@ -80,32 +152,65 @@ struct _inlist_iterator
80 _node = _get_node<value_type>(_list->__in_list.last); 152 _node = _get_node<value_type>(_list->__in_list.last);
81 return *this; 153 return *this;
82 } 154 }
155
156 /**
157 * @brief Move the iterator to the previous position in the list.
158 * @return Copy of the iterator before the decrement.
159 *
160 * This operator decrements the iterator, making it point to the
161 * position right before the current one.
162 * At the end, it returns a copy of the iterator before the decrement.
163 */
83 _inlist_iterator<T> operator--(int) 164 _inlist_iterator<T> operator--(int)
84 { 165 {
85 _inlist_iterator<T> tmp(*this); 166 _inlist_iterator<T> tmp(*this);
86 --*this; 167 --*this;
87 return tmp; 168 return tmp;
88 } 169 }
170
171 /**
172 * @brief Get a reference to the element currently pointed by the iterator.
173 * @return Reference to the current element.
174 */
89 T& operator*() const 175 T& operator*() const
90 { 176 {
91 return _node->object; 177 return _node->object;
92 } 178 }
179
180 /**
181 * @brief Return a pointer to the current element, which member will be accessed.
182 * @return Pointer to the element currently pointed by the iterator.
183 */
93 T* operator->() const 184 T* operator->() const
94 { 185 {
95 return &_node->object; 186 return &_node->object;
96 } 187 }
188
189 /**
190 * @internal
191 */
97 _inlist_node<value_type>* native_handle() 192 _inlist_node<value_type>* native_handle()
98 { 193 {
99 return _node; 194 return _node;
100 } 195 }
196
197 /**
198 * @internal
199 */
101 _inlist_node<value_type> const* native_handle() const 200 _inlist_node<value_type> const* native_handle() const
102 { 201 {
103 return _node; 202 return _node;
104 } 203 }
105private: 204private:
106 _inlist_node<value_type>* _list; 205 _inlist_node<value_type>* _list; /**< Handle to the original list. */
107 _inlist_node<value_type>* _node; 206 _inlist_node<value_type>* _node; /**< Handle to the current node. */
108 207
208 /**
209 * @brief Check if both iterators are pointing to the same node.
210 * @param lhs First iterator to be compared.
211 * @param rhs Second iterator to be compared.
212 * @return @c true if both iterators are pointing to the same node, @c false otherwise.
213 */
109 template <typename U> 214 template <typename U>
110 friend struct _inlist_iterator; 215 friend struct _inlist_iterator;
111 friend bool operator==(_inlist_iterator<T> lhs, _inlist_iterator<T> rhs) 216 friend bool operator==(_inlist_iterator<T> lhs, _inlist_iterator<T> rhs)
@@ -114,12 +219,21 @@ private:
114 } 219 }
115}; 220};
116 221
222/**
223 * @brief Check if iterators are not pointing to the same node.
224 * @param lhs First iterator to be compared.
225 * @param rhs Second iterator to be compared.
226 * @return @c true if iterators are not pointing to the same node, @c false otherwise.
227 */
117template <typename T> 228template <typename T>
118bool operator!=(_inlist_iterator<T> lhs, _inlist_iterator<T> rhs) 229bool operator!=(_inlist_iterator<T> lhs, _inlist_iterator<T> rhs)
119{ 230{
120 return !(lhs == rhs); 231 return !(lhs == rhs);
121} 232}
122 233
234/**
235 * @internal
236 */
123struct _inlist_access_traits { 237struct _inlist_access_traits {
124 template <typename T> 238 template <typename T>
125 struct const_iterator 239 struct const_iterator
@@ -242,49 +356,93 @@ struct _inlist_access_traits {
242template <typename T, typename Allocator> 356template <typename T, typename Allocator>
243class inlist; 357class inlist;
244 358
359/**
360 * @ingroup Eina_Cxx_Range_Group
361 *
362 * Range for inline list elements.
363 */
245template <typename T> 364template <typename T>
246struct range_inlist : _range_template<T, _inlist_access_traits> 365struct range_inlist : _range_template<T, _inlist_access_traits>
247{ 366{
248 typedef _range_template<T, _inlist_access_traits> _base_type; 367 typedef _range_template<T, _inlist_access_traits> _base_type; /**< Type for the base class. */
249 typedef typename _base_type::value_type value_type; 368 typedef typename _base_type::value_type value_type; /**< The type of each element. */
250 typedef typename _base_type::native_handle_type native_handle_type; 369 typedef typename _base_type::native_handle_type native_handle_type; /** Type for the native Eina inline list handle. */
251 370
371 /**
372 * @brief Creates a range from a native Eina inline list handle.
373 */
252 range_inlist(native_handle_type list) 374 range_inlist(native_handle_type list)
253 : _base_type(list) {} 375 : _base_type(list) {}
376
377 /**
378 * @brief Creates a range from a inline list object.
379 */
254 template <typename Allocator> 380 template <typename Allocator>
255 range_inlist(inlist<value_type, Allocator>& list) 381 range_inlist(inlist<value_type, Allocator>& list)
256 : _base_type(list.native_handle()) 382 : _base_type(list.native_handle())
257 {} 383 {}
258}; 384};
259 385
386/**
387 * @brief Check the given ranges are equal to each other.
388 * @param lhs Range object at the left side of the expression.
389 * @param rhs Range object at the right side of the expression.
390 * @return @c true if the ranges are equal, @c false otherwise.
391 *
392 * This operator checks if the given ranges are equal to each other. To
393 * be considered equal both ranges need to have the same size, and each
394 * element in one range must be equal to the element at the same
395 * position in the other.
396 */
260template <typename T> 397template <typename T>
261bool operator==(range_inlist<T>const& lhs, range_inlist<T>const& rhs) 398bool operator==(range_inlist<T>const& lhs, range_inlist<T>const& rhs)
262{ 399{
263 return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()); 400 return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());
264} 401}
265 402
403/**
404 * @brief Returns the opposite of @ref operator==(range_inlist<T>const& lhs, range_inlist<T>const& rhs).
405 */
266template <typename U> 406template <typename U>
267bool operator!=(range_inlist<U> const& lhs, range_inlist<U>const& rhs) 407bool operator!=(range_inlist<U> const& lhs, range_inlist<U>const& rhs)
268{ 408{
269 return !(lhs == rhs); 409 return !(lhs == rhs);
270} 410}
271 411
412/**
413 * Common implementations for inline list.
414 */
272template <typename T, typename Allocator> 415template <typename T, typename Allocator>
273struct _inlist_common_base 416struct _inlist_common_base
274{ 417{
275 typedef typename Allocator::template rebind<_inlist_node<T> >::other node_allocator_type; 418 typedef typename Allocator::template rebind<_inlist_node<T> >::other node_allocator_type; /**< Type for the allocator of the node. */
276 typedef Allocator allocator_type; 419 typedef Allocator allocator_type; /**< Type for the allocator. */
277 typedef _inlist_node<T> node_type; 420 typedef _inlist_node<T> node_type; /**< Type for the list node. */
278 421
422 /**
423 * @brief Creates a list with the given allocator.
424 * @param allocator Allocator object.
425 */
279 _inlist_common_base(Allocator allocator) 426 _inlist_common_base(Allocator allocator)
280 : _impl(allocator) {} 427 : _impl(allocator) {}
428
429 /**
430 * @brief Creates an empty inline list.
431 */
281 _inlist_common_base() 432 _inlist_common_base()
282 {} 433 {}
434
435 /**
436 * @brief Destructor. Deallocate all nodes of the list.
437 */
283 ~_inlist_common_base() 438 ~_inlist_common_base()
284 { 439 {
285 clear(); 440 clear();
286 } 441 }
287 442
443 /**
444 * @brief Deallocate all nodes of the list.
445 */
288 void clear() 446 void clear()
289 { 447 {
290 Eina_Inlist* p = _impl._list; 448 Eina_Inlist* p = _impl._list;
@@ -301,11 +459,18 @@ struct _inlist_common_base
301 } 459 }
302 _impl._list = 0; 460 _impl._list = 0;
303 } 461 }
462
463 /**
464 * @brief Get the allocator used by the list.
465 */
304 node_allocator_type& get_node_allocator() 466 node_allocator_type& get_node_allocator()
305 { 467 {
306 return _impl; 468 return _impl;
307 } 469 }
308 470
471 /**
472 * @internal
473 */
309 // For EBO 474 // For EBO
310 struct _inlist_impl : node_allocator_type 475 struct _inlist_impl : node_allocator_type
311 { 476 {
@@ -317,40 +482,77 @@ struct _inlist_common_base
317 Eina_Inlist* _list; 482 Eina_Inlist* _list;
318 }; 483 };
319 484
320 _inlist_impl _impl; 485 _inlist_impl _impl; /**< @internal */
321private: 486private:
487
488 /** Disabled copy constructor. */
322 _inlist_common_base(_inlist_common_base const& other); 489 _inlist_common_base(_inlist_common_base const& other);
490
491 /** Disabled assignment operator. */
323 _inlist_common_base& operator=(_inlist_common_base const& other); 492 _inlist_common_base& operator=(_inlist_common_base const& other);
324}; 493};
325 494
495/**
496 * C++ wrapper for the native Eina inline list.
497 *
498 * It provides an OOP interface to the @c Eina_Inlist functions, and
499 * automatically take care of allocating and deallocating resources using
500 * the RAII programming idiom.
501 *
502 * It also provides additional member functions to facilitate the access
503 * to the list content, much like a STL list.
504 */
326template <typename T, typename Allocator = std::allocator<T> > 505template <typename T, typename Allocator = std::allocator<T> >
327class inlist : protected _inlist_common_base<T, Allocator> 506class inlist : protected _inlist_common_base<T, Allocator>
328{ 507{
329 typedef _inlist_common_base<T, Allocator> _base_type; 508 typedef _inlist_common_base<T, Allocator> _base_type; /**< Type for the base class. */
330 typedef typename _base_type::node_type _node_type; 509 typedef typename _base_type::node_type _node_type; /**< Type for each node */
331public: 510public:
332 typedef typename _base_type::allocator_type allocator_type; 511 typedef typename _base_type::allocator_type allocator_type; /**< Type for the allocator. */
333 typedef typename allocator_type::value_type value_type; 512 typedef typename allocator_type::value_type value_type; /**< The type of each element. */
334 typedef typename allocator_type::reference reference; 513 typedef typename allocator_type::reference reference; /**< Type for a reference to an element. */
335 typedef typename allocator_type::const_reference const_reference; 514 typedef typename allocator_type::const_reference const_reference; /**< Type for a constant reference to an element. */
336 typedef _inlist_iterator<T const> const_iterator; 515 typedef _inlist_iterator<T const> const_iterator; /**< Type for constant iterator for this kind of container. */
337 typedef _inlist_iterator<T> iterator; 516 typedef _inlist_iterator<T> iterator; /**< Type for iterator for this kind of container. */
338 typedef typename allocator_type::pointer pointer; 517 typedef typename allocator_type::pointer pointer; /**< Type for a pointer to an element. */
339 typedef typename allocator_type::const_pointer const_pointer; 518 typedef typename allocator_type::const_pointer const_pointer; /**< Type for a constant pointer for an element. */
340 typedef std::size_t size_type; 519 typedef std::size_t size_type; /**< Type for size information. */
341 typedef std::ptrdiff_t difference_type; 520 typedef std::ptrdiff_t difference_type; /**< Type to represent the distance between two iterators. */
342 521
343 typedef std::reverse_iterator<iterator> reverse_iterator; 522 typedef std::reverse_iterator<iterator> reverse_iterator; /**< Type for reverse iterator for this kind of container. */
344 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 523 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; /**< Type for constant reverse iterator for this kind of container. */
345 524
346 using _base_type::clear; 525 using _base_type::clear;
347 526
527 /**
528 * @brief Default constructor. Creates an empty inline list.
529 */
348 inlist() {} 530 inlist() {}
531
532 /**
533 * @brief Construct an inline list object with @p n copies of @p t.
534 * @param n Number of elements.
535 * @param t Value to be copied to each element.
536 *
537 * This constructor creates an inline list with @p n elements, each
538 * one as a copy of @p t.
539 */
349 inlist(size_type n, value_type const& t) 540 inlist(size_type n, value_type const& t)
350 { 541 {
351 while(n--) 542 while(n--)
352 push_back(t); 543 push_back(t);
353 } 544 }
545
546 /**
547 * @brief Create a inline list coping the elements from the given range.
548 * @param i Iterator to the initial position. The element pointed by this iterator will be copied.
549 * @param j Iterator to the final position. The element pointed by this iterator will NOT be copied.
550 *
551 * This constructor creates a inline list with copies of the elements
552 * between @p i and @p j in the same order.
553 *
554 * @note The ending element (pointed by @p j) is not copied.
555 */
354 template <typename InputIterator> 556 template <typename InputIterator>
355 inlist(InputIterator i, InputIterator const& j 557 inlist(InputIterator i, InputIterator const& j
356 , allocator_type const& alloc = allocator_type() 558 , allocator_type const& alloc = allocator_type()
@@ -363,29 +565,74 @@ public:
363 ++i; 565 ++i;
364 } 566 }
365 } 567 }
568
569 /**
570 * @brief Copy constructor. Creates a copy of the given inline list.
571 * @param other Another inline list of the same type.
572 *
573 * This constructor creates an inline list containing a copy of each
574 * element inside @p other in the same order.
575 */
366 inlist(inlist<T, Allocator>const& other) 576 inlist(inlist<T, Allocator>const& other)
367 : _base_type() 577 : _base_type()
368 { 578 {
369 insert(end(), other.begin(), other.end()); 579 insert(end(), other.begin(), other.end());
370 } 580 }
581
582 /**
583 * @brief Replace current content with the content of another inline list.
584 * @param other Another inline list of the same type.
585 *
586 * This assignment operator replaces the content of the list by a copy
587 * of the content of @p other. The list size is adjusted accordingly
588 * and the newly copied elements keep their original order.
589 */
371 inlist<T, Allocator>& operator=(inlist<T, Allocator>const& other) 590 inlist<T, Allocator>& operator=(inlist<T, Allocator>const& other)
372 { 591 {
373 clear(); 592 clear();
374 insert(end(), other.begin(), other.end()); 593 insert(end(), other.begin(), other.end());
375 return *this; 594 return *this;
376 } 595 }
596
597 /**
598 * @brief Get the current size of the inline list.
599 * @return Number of elements in the inline list.
600 *
601 * This member function returns the current number of elements inside
602 * the inline list.
603 */
377 size_type size() const 604 size_type size() const
378 { 605 {
379 return _inlist_access_traits::size<T>(native_handle()); 606 return _inlist_access_traits::size<T>(native_handle());
380 } 607 }
608
609 /**
610 * @brief Check if the inline list is empty.