summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eina_cxx/eina_list.hh
blob: d5b62877cb20d414f31148fefce5d73dc8ed19d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
#ifndef EINA_LIST_HH_
#define EINA_LIST_HH_

#include <Eo.h>

#include <eina_ptrlist.hh>

namespace efl { namespace eina {

/**
 * @internal
 */
template <typename T>
struct _ptr_eo_list_iterator : _ptr_list_iterator<Eo>
{
  typedef _ptr_list_iterator<Eo> _base_type;
  typedef _ptr_eo_list_iterator<T> _self_type;
  typedef typename remove_cv<T>::type value_type;
  typedef value_type* pointer;
  typedef value_type& reference;

  _base_type& _base() { return *this; }
  _base_type const& _base() const { return *this; }
  
  _ptr_eo_list_iterator(_base_type const& base) : _base_type(base) {}
  _ptr_eo_list_iterator() {}
  explicit _ptr_eo_list_iterator(Eina_List* list, Eina_List* node)
    : _base_type(list, node)
  {
  }
  _ptr_eo_list_iterator(_ptr_eo_list_iterator<value_type> const& other)
    : _base_type(static_cast<_base_type const&>(other))
  {
  }
  _self_type& operator=(_self_type const& other)
  {
    this->_base_type::operator=(other);
    return *this;
  }

  _self_type& operator++()
  {
    ++_base();
    return *this;
  }
  _self_type operator++(int)
  {
    _self_type tmp(*this);
    ++_base();
    return tmp;
  }
  _self_type& operator--()
  {
    --_base();
    return *this;
  }
  _self_type operator--(int)
  {
    _self_type tmp(*this);
    --_base();
    return tmp;
  }
  reference operator*() const
  {
    void* data = reinterpret_cast<void*>(&this->_node->data);
    return *static_cast<pointer>(data);
  }
  pointer operator->() const
  {
    return &**this;
  }

  using _base_type::native_handle;
};

/**
 * @internal
 */
struct _eo_list_access_traits : _ptr_list_access_traits
{
  template <typename T>
  struct iterator
  {
    typedef _ptr_eo_list_iterator<T> type;
  };
  template <typename T>
  struct const_iterator : iterator<T const> {};
  template <typename T>
  static T& back(Eina_List* list)
  {
    return *static_cast<T*>(static_cast<void*>(&eina_list_last(list)->data));
  }
  template <typename T>
  static T const& back(Eina_List const* list)
  {
    return _eo_list_access_traits::back<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static T& front(Eina_List* list)
  {
    return *static_cast<T*>(static_cast<void*>(&list->data));
  }
  template <typename T>
  static T const& front(Eina_List const* list)
  {
    return _eo_list_access_traits::front<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static typename iterator<T>::type begin(Eina_List* list)
  {
    return typename iterator<T>::type(list, list);
  }
  template <typename T>
  static typename iterator<T>::type end(Eina_List* list)
  {
    return typename iterator<T>::type(list, nullptr);
  }
  template <typename T>
  static typename const_iterator<T>::type begin(Eina_List const* list)
  {
    return _eo_list_access_traits::begin<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static typename const_iterator<T>::type end(Eina_List const* list)
  {
    return _eo_list_access_traits::end<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static std::reverse_iterator<typename iterator<T>::type> rbegin(Eina_List* list)
  {
    return std::reverse_iterator<typename iterator<T>::type>(_eo_list_access_traits::end<T>(list));
  }
  template <typename T>
  static std::reverse_iterator<typename iterator<T>::type> rend(Eina_List* list)
  {
    return std::reverse_iterator<typename iterator<T>::type>(_eo_list_access_traits::begin<T>(list));
  }
  template <typename T>
  static std::reverse_iterator<typename const_iterator<T>::type> rbegin(Eina_List const* list)
  {
    return _eo_list_access_traits::rbegin<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static std::reverse_iterator<typename const_iterator<T>::type> rend(Eina_List const* list)
  {
    return _eo_list_access_traits::rend<T>(const_cast<Eina_List*>(list));
  }
  template <typename T>
  static typename const_iterator<T>::type cbegin(Eina_List const* list)
  {
    return _eo_list_access_traits::begin<T>(list);
  }
  template <typename T>
  static typename const_iterator<T>::type cend(Eina_List const* list)
  {
    return _eo_list_access_traits::end<T>(list);
  }
  template <typename T>
  static std::reverse_iterator<typename const_iterator<T>::type> crbegin(Eina_List const* list)
  {
    return _eo_list_access_traits::rbegin<T>(list);
  }
  template <typename T>
  static std::reverse_iterator<typename const_iterator<T>::type> crend(Eina_List const* list)
  {
    return _eo_list_access_traits::rend<T>(list);
  }
};
    
template <typename T, typename CloneAllocator = default_clone_allocator_placeholder, typename Enable = void>
class list : ptr_list<T, typename std::conditional
                      <std::is_same<CloneAllocator, default_clone_allocator_placeholder>::value
                       , heap_no_copy_allocator, CloneAllocator>::type>
{
  typedef ptr_list<T, typename std::conditional
                   <std::is_same<CloneAllocator, default_clone_allocator_placeholder>::value
                    , heap_no_copy_allocator, CloneAllocator>::type> _base_type;
public:
  typedef typename _base_type::value_type value_type;
  typedef typename _base_type::reference reference;
  typedef typename _base_type::const_reference const_reference;
  typedef typename _base_type::const_iterator const_iterator;
  typedef typename _base_type::iterator iterator;
  typedef typename _base_type::pointer pointer;
  typedef typename _base_type::const_pointer const_pointer;
  typedef typename _base_type::size_type size_type;
  typedef typename _base_type::difference_type difference_type;
  typedef typename _base_type::clone_allocator_type clone_allocator_type;

  typedef typename _base_type::reverse_iterator reverse_iterator;
  typedef typename _base_type::const_reverse_iterator const_reverse_iterator;

  typedef typename _base_type::native_handle_type native_handle_type;
  
  list& operator=(list&& other) = default;
  list(list&& other) = default;
  list() = default;

  using _base_type::_base_type;
  using _base_type::clear;
  using _base_type::size;
  using _base_type::empty;
  using _base_type::get_clone_allocator;
  using _base_type::push_back;
  using _base_type::push_front;
  using _base_type::pop_back;
  using _base_type::pop_front;
  using _base_type::insert;
  using _base_type::erase;
  using _base_type::assign;
  using _base_type::back;
  using _base_type::front;
  using _base_type::begin;
  using _base_type::end;
  using _base_type::rbegin;
  using _base_type::rend;
  using _base_type::cbegin;
  using _base_type::cend;
  using _base_type::crbegin;
  using _base_type::crend;
  using _base_type::ibegin;
  using _base_type::iend;
  using _base_type::cibegin;
  using _base_type::ciend;
  using _base_type::swap;
  using _base_type::max_size;
  using _base_type::native_handle;
  using _base_type::accessor;
  using _base_type::release_native_handle;
};

template <typename T, typename CloneAllocator>
class list<T, CloneAllocator, typename std::enable_if< ::efl::eo::is_eolian_object<T>::value>::type>
  : ptr_list<Eo, typename std::conditional
             <std::is_same<CloneAllocator, default_clone_allocator_placeholder>::value
              , eo_clone_allocator, CloneAllocator>::type>
{
  typedef ptr_list<Eo, typename std::conditional
                   <std::is_same<CloneAllocator, default_clone_allocator_placeholder>::value
                    , eo_clone_allocator, CloneAllocator>::type> _base_type;
  typedef list<T, CloneAllocator> _self_type;
public:
  typedef T value_type;
  typedef value_type& reference;
  typedef value_type const& const_reference;
  typedef _ptr_eo_list_iterator<value_type const> const_iterator;
  typedef _ptr_eo_list_iterator<value_type> iterator;
  typedef value_type* pointer;
  typedef value_type const* const_pointer;
  typedef std::size_t size_type;
  typedef std::ptrdiff_t difference_type;
  typedef typename _base_type::clone_allocator_type clone_allocator_type;

  typedef std::reverse_iterator<iterator> reverse_iterator;
  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

  typedef typename _base_type::native_handle_type native_handle_type;

  explicit list(typename _self_type::native_handle_type handle)
    : _base_type(handle) {}
  list(clone_allocator_type alloc) : _base_type(alloc) {}
  list() {}
  list(size_type n, const_reference t)
  {
    while(n--)
      push_back(t);
  }
  template <typename InputIterator>
  list(InputIterator i, InputIterator const& j
       , clone_allocator_type const& alloc = clone_allocator_type()
       , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
    : _base_type(alloc)
  {
    while(i != j)
      {
        push_back(*i);
        ++i;
      }
  }
  list(list<T, CloneAllocator> const& other)
    : _base_type()
  {
    insert(end(), other.begin(), other.end());
  }
  ~list()
  {
  }
  list<T, CloneAllocator>& operator=(list<T, CloneAllocator>const& other)
  {
    clear();
    insert(end(), other.begin(), other.end());
    return *this;
  }
  list& operator=(list&& other) = default;
  list(list&& other) = default;

  using _base_type::clear;
  using _base_type::size;
  using _base_type::empty;
  using _base_type::get_clone_allocator;
  using _base_type::pop_back;
  using _base_type::pop_front;
  using _base_type::release_native_handle;

  void push_back(const_reference w)
  {
    this->_base_type::push_back(* w._eo_ptr());
  }
  void push_front(const_reference w)
  {
    this->_base_type::push_front(* w._eo_ptr());
  }
  iterator insert(iterator i, const_reference v)
  {
    return this->_base_type::insert(i, * v._eo_ptr());
  }
  iterator insert(iterator i, size_t n, const_reference v)
  {
    return this->_base_type::insert(i, n, * v._eo_ptr());
  }
  template <typename InputIterator>
  iterator insert(iterator p, InputIterator i, InputIterator j
                  , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
  {
    iterator r = p;
    if(i != j)
      {
        r = insert(p, *i);
        ++i;
      }
    while(i != j)
      {
        insert(p, *i);
        ++i;
      }
    return r;
  }
  iterator erase(iterator p)
  {
    return _base_type::erase(p);
  }
  iterator erase(iterator i, iterator j)
  {
    return _base_type::erase(i, j);
  }
  template <typename InputIterator>
  void assign(InputIterator i, InputIterator j
              , typename eina::enable_if<!eina::is_integral<InputIterator>::value>::type* = 0)
  {
    clear();
    insert(end(), i, j);
  }

  void assign(size_type n, value_type const& t)
  {
    clear();
    insert(end(), n, t);
  }
  
  reference front()
  {
    return _eo_list_access_traits::front<value_type>(native_handle());
  }
  reference back()
  {
    return _eo_list_access_traits::back<value_type>(native_handle());
  }
  const_reference front() const { return const_cast<_self_type*>(this)->front(); }
  const_reference back() const { return const_cast<_self_type*>(this)->back(); }
  iterator begin()
  {
    return _eo_list_access_traits::begin<value_type>(native_handle());
  }
  iterator end()
  {
    return _eo_list_access_traits::end<value_type>(native_handle());
  }
  const_iterator begin() const
  {
    return const_cast<_self_type*>(this)->begin();
  }
  const_iterator end() const
  {
    return const_cast<_self_type*>(this)->end();
  }
  const_iterator cbegin() const
  {
    return begin();
  }
  const_iterator cend() const
  {
    return end();
  }
  reverse_iterator rbegin()
  {
    return _eo_list_access_traits::rbegin<value_type>(native_handle());
  }
  reverse_iterator rend()
  {
    return _eo_list_access_traits::rend<value_type>(native_handle());
  }
  const_reverse_iterator rbegin() const
  {
    return const_cast<_self_type*>(this)->rbegin();
  }
  const_reverse_iterator rend() const
  {
    return const_cast<_self_type*>(this)->rend();
  }
  const_reverse_iterator crbegin() const
  {
    return rbegin();
  }
  const_reverse_iterator crend() const
  {
    return rend();
  }
  eina::iterator<value_type> ibegin()
  {
    return _eo_list_access_traits::ibegin<value_type>(this->_impl._list);
  }
  eina::iterator<value_type> iend()
  {
    return _eo_list_access_traits::iend<value_type>(this->_impl._list);
  }
  eina::iterator<value_type const> ibegin() const
  {
    return _eo_list_access_traits::ibegin<value_type>(this->_impl._list);
  }
  eina::iterator<value_type const> iend() const
  {
    return _eo_list_access_traits::iend<value_type>(this->_impl._list);
  }
  eina::iterator<value_type const> cibegin() const
  {
    return _eo_list_access_traits::cibegin<value_type>(this->_impl._list);
  }
  eina::iterator<value_type const> ciend() const
  {
    return _eo_list_access_traits::ciend<value_type>(this->_impl._list);
  }
  using _base_type::swap;
  using _base_type::max_size;
  using _base_type::native_handle;

  /**
   * @brief Get a constant @ref eina::accessor for the list.
   * @return Constant <tt>eina::accessor</tt> to the list.
   *
   * Version of @ref accessor() to const-qualified inline lists. Returns
   * a const-qualified <tt>eina::accessor</tt> instead.
   */
  eina::accessor<T const> accessor() const
  {
    return eina::accessor<T const>(eina_list_accessor_new(this->_impl._list));
  }

  /**
   * @brief Get a @ref eina::accessor for the list.
   * @return <tt>eina::accessor</tt> to the list.
   */
  eina::accessor<T> accessor()
  {
    return eina::accessor<T>(eina_list_accessor_new(this->_impl._list));
  }

  friend bool operator==(list<T, CloneAllocator> const& rhs, list<T, CloneAllocator> const& lhs)
  {
    return rhs.size() == lhs.size() && std::equal(rhs.begin(), rhs.end(), lhs.begin());
  }
};

template <typename T, typename CloneAllocator>
bool operator!=(list<T, CloneAllocator> const& rhs, list<T, CloneAllocator> const& lhs)
{
  return !(rhs == lhs);
}

template <typename T, typename Enable = void>
class range_list : range_ptr_list<T>
{
  typedef range_ptr_list<T> _base_type;
public:
  typedef typename _base_type::value_type value_type;
  typedef typename _base_type::reference reference;
  typedef typename _base_type::const_reference const_reference;
  typedef typename _base_type::const_iterator const_iterator;
  typedef typename _base_type::iterator iterator;
  typedef typename _base_type::pointer pointer;
  typedef typename _base_type::const_pointer const_pointer;
  typedef typename _base_type::size_type size_type;
  typedef typename _base_type::difference_type difference_type;

  typedef typename _base_type::reverse_iterator reverse_iterator;
  typedef typename _base_type::const_reverse_iterator const_reverse_iterator;

  typedef typename _base_type::native_handle_type native_handle_type;

  using _base_type::_base_type;
  using _base_type::size;
  using _base_type::empty;
  using _base_type::back;
  using _base_type::front;
  using _base_type::begin;
  using _base_type::end;
  using _base_type::rbegin;
  using _base_type::rend;
  using _base_type::cbegin;
  using _base_type::cend;
  using _base_type::crbegin;
  using _base_type::crend;
  using _base_type::swap;
  using _base_type::native_handle;
  using _base_type::release_native_handle;
};

template <typename T>
class range_list<T, typename std::enable_if< ::efl::eo::is_eolian_object<T>::value>::type>
  : range_ptr_list<typename std::conditional<std::is_const<T>::value, Eo const, Eo>::type>
{
  typedef range_ptr_list<typename std::conditional<std::is_const<T>::value, Eo const, Eo>::type> _base_type;
  typedef range_list<T> _self_type;
public:
  typedef T value_type;
  typedef value_type& reference;
  typedef value_type const& const_reference;
  typedef _ptr_eo_list_iterator<value_type const> const_iterator;
  typedef _ptr_eo_list_iterator<value_type> iterator;
  typedef value_type* pointer;
  typedef value_type const* const_pointer;
  typedef std::size_t size_type;
  typedef std::ptrdiff_t difference_type;

  typedef std::reverse_iterator<iterator> reverse_iterator;
  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

  typedef typename _base_type::native_handle_type native_handle_type;

  explicit range_list(typename _self_type::native_handle_type handle)
    : _base_type(handle) {}
  range_list() {}
  range_list(range_list<T> const& other)
    : _base_type(other.native_handle())
  {
  }
  range_list<T>& operator=(range_list<T>const& other)
  {
    _base_type::_handle = other._handle;
    return *this;
  }
  range_list& operator=(range_list&& other) = default;
  range_list(range_list&& other) = default;
  
  using _base_type::size;
  using _base_type::empty;

  reference front()
  {
    return _eo_list_access_traits::front<value_type>(native_handle());
  }
  reference back()
  {
    return _eo_list_access_traits::back<value_type>(native_handle());
  }
  const_reference front() const { return const_cast<_self_type*>(this)->front(); }
  const_reference back() const { return const_cast<_self_type*>(this)->back(); }
  iterator begin()
  {
    return _eo_list_access_traits::begin<value_type>(native_handle());
  }
  iterator end()
  {
    return _eo_list_access_traits::end<value_type>(native_handle());
  }
  const_iterator begin() const
  {
    return const_cast<_self_type*>(this)->begin();
  }
  const_iterator end() const
  {
    return const_cast<_self_type*>(this)->end();
  }
  const_iterator cbegin() const
  {
    return begin();
  }
  const_iterator cend() const
  {
    return end();
  }
  reverse_iterator rbegin()
  {
    return _eo_list_access_traits::rbegin<value_type>(native_handle());
  }
  reverse_iterator rend()
  {
    return _eo_list_access_traits::rend<value_type>(native_handle());
  }
  const_reverse_iterator rbegin() const
  {
    return const_cast<_self_type*>(this)->rbegin();
  }
  const_reverse_iterator rend() const
  {
    return const_cast<_self_type*>(this)->rend();
  }
  const_reverse_iterator crbegin() const
  {
    return rbegin();
  }
  const_reverse_iterator crend() const
  {
    return rend();
  }
  using _base_type::swap;
  using _base_type::native_handle;
  using _base_type::release_native_handle;

  friend bool operator==(range_list<T> const& rhs, range_list<T> const& lhs)
  {
    return rhs.size() == lhs.size() && std::equal(rhs.begin(), rhs.end(), lhs.begin());
  }
};

template <typename T>
using crange_list = range_list<typename std::add_const<T>::type>;
    
} }

#endif