27 # ifndef TPL_DYNDLIST_H 28 # define TPL_DYNDLIST_H 30 # include <ahFunctional.H> 32 # include <ah-args-ctor.H> 33 # include <ahIterator.H> 34 # include <ah-iterator.H> 35 # include <tpl_dnode.H> 37 using namespace Aleph;
50 template <
typename T =
int>
58 public StlAlephIterator<DynDlist<T>>
74 const size_t &
size() const noexcept {
return num_elem; }
129 return __insert(
new Dnode<T> (item));
140 return __insert(
new Dnode<T> (std::forward<T>(item)));
151 return __append(
new Dnode<T> (item));
162 return __append(
new Dnode<T> (std::forward<T>(item)));
170 num_elem += list.num_elem;
179 num_elem += list.num_elem;
222 return this->
get_next()->get_data();
228 return this->
get_prev()->get_data();
235 throw std::underflow_error(
"DynDlist is empty");
243 throw std::underflow_error(
"DynDlist is empty");
283 throw std::underflow_error(
"DynDlist is empty");
295 throw std::underflow_error(
"DynDlist is empty");
303 T &
put(T && item) {
return append(std::forward<T>(item)); }
320 T &
push(T && item) {
return insert(std::forward<T>(item)); }
341 void remove(T & data) noexcept
359 std::swap(num_elem, l.num_elem);
376 Dlink::split_list(l, r);
377 l.num_elem = r.num_elem = num_elem/2;
379 if (num_elem % 2 == 1)
399 throw std::domain_error(
"lists are not empty");
466 pos = list_ptr->num_elem - 1;
472 put_itor_at_the_end(*
this);
477 :
Base(list), list_ptr(&const_cast<DynDlist&>(list)), pos(0)
482 Iterator() noexcept : list_ptr(
nullptr) { }
487 list_ptr = it.list_ptr;
500 T & get_curr_ne()
const noexcept
517 throw std::overflow_error (
"DynDlist Iterator has not current");
520 ++list_ptr->num_elem;
536 throw std::overflow_error (
"DynDlist Iterator has not current");
540 ++list_ptr->num_elem;
555 throw std::overflow_error (
"DynDlist Iterator has not current");
558 ++list_ptr->num_elem;
574 throw std::overflow_error (
"DynDlist Iterator has not current");
578 ++list_ptr->num_elem;
599 throw std::overflow_error (
"DynDlist Iterator has not current");
602 list_ptr->num_elem += list.num_elem;
626 throw std::overflow_error (
"DynDlist Iterator has not current");
629 list_ptr->num_elem += list.num_elem;
644 throw std::overflow_error (
"DynDlist Iterator has not current");
651 --list_ptr->num_elem;
674 this->
append(itor.get_curr_ne());
692 this->
append(itor.get_curr_ne());
740 DynDlist & rev() noexcept {
return reverse(); }
749 for (
auto it = this->
get_it(); it.has_curr(); it.next_ne())
750 ret.
insert(it.get_curr_ne());
Special_Ctors(DynDlist, T)
static Dnode * data_to_node(T &data) noexcept
Definition: tpl_dnode.H:194
T & append(T &&item)
Definition: tpl_dynDlist.H:160
Definition: htlist.H:1290
T & rear()
Definition: tpl_dynDlist.H:310
void erase(T &data) noexcept
Definition: tpl_dynDlist.H:350
void append(DynDlist &&list) noexcept
Definition: tpl_dynDlist.H:214
bool has_curr() const noexcept
Return true if the iterator has current item.
Definition: dlink.H:658
void split_list_ne(DynDlist &l, DynDlist &r) noexcept
Definition: tpl_dynDlist.H:374
void swap(DynDlist &l) noexcept
Definition: tpl_dynDlist.H:357
void next_ne() noexcept
Definition: dlink.H:715
T remove_last_ne() noexcept
Definition: tpl_dynDlist.H:265
Iterator(const DynDlist< T > &list) noexcept
Initialize the iterator to the first item of list
Definition: tpl_dynDlist.H:476
T & top() const
Definition: tpl_dynDlist.H:326
T & put(T &&item)
Definition: tpl_dynDlist.H:303
void append(const DynDlist &list) noexcept
Definition: tpl_dynDlist.H:207
void reset_last() noexcept
Reset the iterator to the last item of list.
Definition: dlink.H:645
auto get_it() const
Definition: htlist.H:151
Definition: tpl_dynDlist.H:51
long get_pos() const noexcept
Return the ordinal position of current item.
Definition: tpl_dynDlist.H:429
void append(T &&item)
Definition: tpl_dynDlist.H:571
~DynDlist()
Destructor.
Definition: tpl_dynDlist.H:98
T & front()
Definition: tpl_dynDlist.H:314
void insert(const DynDlist &list)
Definition: tpl_dynDlist.H:191
void reset_last() noexcept
Reset the iterator to the last item.
Definition: tpl_dynDlist.H:463
void append_list(DynDlist &list)
Definition: tpl_dynDlist.H:623
T & get_last() const
Return a modifiable reference to last item in the list.
Definition: tpl_dynDlist.H:240
T & insert(T &&item)
Definition: tpl_dynDlist.H:138
T & put(const T &item)
Definition: tpl_dynDlist.H:300
T & push(const T &item)
Definition: tpl_dynDlist.H:317
T pop()
Definition: tpl_dynDlist.H:323
typename GT::Node * Key_Type
The type of element that stores the container.
Definition: tpl_dynDlist.H:71
DynDlist(DynDlist< T > &&list) noexcept
Definition: tpl_dynDlist.H:703
Dnode< T > * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition: tpl_dnode.H:221
Dnode< T > *& get_next() const noexcept
Return the next node to this
Definition: tpl_dnode.H:53
Definition: tpl_dynDlist.H:413
T & push(T &&item)
Definition: tpl_dynDlist.H:320
size_t reverse() noexcept
Definition: dlink.H:499
void swap(Dlink *link) noexcept
Definition: dlink.H:82
T remove_last()
Definition: tpl_dynDlist.H:292
void prev()
Definition: tpl_dynDlist.H:449
void insert(DynDlist &&list) noexcept
Definition: tpl_dynDlist.H:198
T & get_first_ne() const noexcept
Return a modifiable reference to first item in the list.
Definition: tpl_dynDlist.H:220
void insert(const T &item)
Definition: tpl_dynDlist.H:514
void insert(T &&item)
Definition: tpl_dynDlist.H:533
void end() noexcept
Put theiterator at the end state (where there is no current item)
Definition: tpl_dynDlist.H:470
T & get_data() noexcept
Return a modifiable reference to the data contained in the node.
Definition: tpl_dnode.H:178
T & get_first() const
Return a modifiable reference to first item in the list.
Definition: tpl_dynDlist.H:232
Dnode< T > * remove_prev() noexcept
Remove the previous node to this; return its address.
Definition: tpl_dnode.H:59
void insert(Dlink *node) noexcept
Definition: dlink.H:205
DynDlist< T > reverse() const
Definition: tpl_dynDlist.H:746
void next_ne() noexcept
Definition: tpl_dynDlist.H:433
Dnode< T > *& get_prev() const noexcept
Return the previous node to this
Definition: tpl_dnode.H:56
void append_list(Dlink *head) noexcept
Definition: dlink.H:329
void reset_first() noexcept
Reset the iterator to the first item.
Definition: tpl_dynDlist.H:456
T & operator[](const size_t &n) const
Definition: tpl_dynDlist.H:725
DynDlist(const DynDlist &list)
Definition: tpl_dynDlist.H:686
void next()
Definition: tpl_dynDlist.H:441
bool is_empty() const noexcept
Return true if this (as header node) is empty.
Definition: dlink.H:192
Dnode< T > * remove_next() noexcept
Remove the next node to this; return its address.
Definition: tpl_dnode.H:62
Dnode< T > * get_curr() const
Definition: tpl_dnode.H:231
void split_list(DynDlist &l, DynDlist &r)
Definition: tpl_dynDlist.H:396
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
Definition: dlink.H:389
void prev()
Definition: dlink.H:706
Definition: tpl_dnode.H:206
void empty() noexcept
Empty the list.
Definition: tpl_dynDlist.H:90
const size_t & size() const noexcept
Return the number of elements (constant time)
Definition: tpl_dynDlist.H:74
void insert_list(Dlink *head) noexcept
Definition: dlink.H:307
void append(Dlink *node) noexcept
Definition: dlink.H:228
T & get_curr() const
Definition: tpl_dynDlist.H:495
T remove_first_ne() noexcept
Definition: tpl_dynDlist.H:251
T & get_last_ne() const noexcept
Return a modifiable reference to last item in the list.
Definition: tpl_dynDlist.H:226
void insert_list(DynDlist &list)
Definition: tpl_dynDlist.H:596
T del()
Definition: tpl_dynDlist.H:641
void reset_first() noexcept
Reset the iterator to the first item of list.
Definition: dlink.H:638
typename GT::Node * Item_Type
The type of element that stores the container.
Definition: tpl_dynDlist.H:68
T remove_first()
Definition: tpl_dynDlist.H:280
void append(const T &item)
Definition: tpl_dynDlist.H:552
void split(DynDlist &l, DynDlist &r)
Definition: tpl_dynDlist.H:404
T & insert(const T &item)
Definition: tpl_dynDlist.H:127
void next()
Definition: dlink.H:721
T & append(const T &item)
Definition: tpl_dynDlist.H:149