Experimental Code
Code Written To Experiment With Various Techniques And Otherwise Not Very Useful...
DoubleLinkedList.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2013, Komodo Does Inc
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 - Neither the name of the Komodo Does Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 */
13 
14 #ifndef DOUBLE_LINKED_LIST_H
15 #define DOUBLE_LINKED_LIST_H
16 
17 /** \file
18  * Double Linked List defintion.
19  */
20 
21 #ifndef DOUBLE_LINKED_LIST_IMPL_H
22 #include "DoubleLinkedListImpl.h"
23 #endif // DOUBLE_LINKED_LIST_IMPL_H
24 
25 #ifndef ITERATOR_H
26 #include "Iterator.h"
27 #endif // ITERATOR_H
28 
29 namespace Experiment {
30 
31  /** DoubleLinkedList which can be iterated via DoubleLinkedList::iterator
32  *
33  * \tparam T the type of Data this DoubleLinkedList will hold
34  */
35  template<class T>
37  private:
38  /** Convenience typedef of Nodes contained in this list */
40  /** Convenience typedef of Nodes with valid data contained in this list */
42 
43  public:
44  /** Convenience typedef of the type of values in this list */
45  typedef T value_type;
46 
47  /** Convenience typedef of iterators of this list */
49 
50  private:
51  /** Convenience typedef of Nodes for iterators for keeping this lists's iterators
52  * at the correct position when Nodes are inserted, moved and removed.
53  *
54  * Yes, IterNodes could be single-linked, but that means writing the code for single
55  * linked Nodes. We are keeping the code simple.
56  */
58 
59  /** Convenience typedef of DataNodes containing iterators for keeping this lists's
60  * iterators at the correct position when nodes are inserted, moved and removed.
61  *
62  * \see IterNode
63  */
65 
66  public:
68 
70 
72 
73  void clear();
74 
75  bool isEmpty() const;
76 
77  iterator begin();
78 
79  iterator end();
80 
81  void push_front(const value_type& value);
82 
83  void push_back(const value_type& value);
84 
85  /// \todo add erase method
86 
87  /// \todo add insert method
88 
89  public:
90  void addIterator(iterator* iter);
91 
92  void removeIterator(iterator* iter);
93 
94  public:
95  // Note: This comes from iter rather than Node because Node doesn't know about list
96  void notifyItersSwapOccurred(Node* a, Node* b) const;
97 
98  void notifyItersInsertedBefore(int count, Node* firstAfter) const;
99 
100  void notifyItersRemovedBefore(int count, Node* firstAfter) const;
101 
102  private:
103  /** First element in the list, or NULL for none */
104  Node head;
105 
106  /** Last element in the list, who's next is NULL, or NULL for none */
107  Node tail;
108 
109  /** List of iterators */
110  IterNode iterHead;
111  };
112 
113 } // namespace Experiment
114 
115 #include "DoubleLinkedList.cpp"
116 
117 #endif // DOUBLE_LINKED_LIST_H
Implementations of longer template methods of the DoubleLinkedList.h file.
Implementation details of a DoubleLinkedList.
Iterator definition.
DoubleLinkedList which can be iterated via DoubleLinkedList::iterator.
void clear()
Remove all data from this list.
Experiment::Iterator< value_type, DoubleLinkedList< value_type >, Node > iterator
Convenience typedef of iterators of this list.
void push_back(const value_type &value)
Insert value as the last item in this list.
void notifyItersSwapOccurred(Node *a, Node *b) const
Notify all iterators that a swap occurred of nodes a and b so that they can update themselves to keep...
DoubleLinkedList()
Create a new list.
void addIterator(iterator *iter)
Record that iter has been created as an iterator of this list.
void notifyItersInsertedBefore(int count, Node *firstAfter) const
Notify all iterators that count Nodes were inserted before firstAfter.
void removeIterator(iterator *iter)
Record that iter that is being destroyed as an iterator of this list.
void push_front(const value_type &value)
Insert value as the first item in this list and udpate iterators to remain at same position.
void notifyItersRemovedBefore(int count, Node *firstAfter) const
Notify all iterators that count Nodes were removed before firstAfter.
T value_type
Convenience typedef of the type of values in this list.
DoubleLinkedList internal Node holding Data.
DoubleLinkedList internal Node base class.
Iterator class that works genericly on a List containing Node elements with data of type T.
Definition: Iterator.h:33
This file is to be included at the end of Iterator.h.