Debian Codegraph @

Source/Utilities/CLinker.hpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef KONCLUDE_UTILITIES_CLINKER_H
22 #define KONCLUDE_UTILITIES_CLINKER_H
23
24 // Libraries includes
25 #include <QLinkedListIterator>
26
27
28 // Namespace includes
29 #include "CAllocationObject.h"
30
31 // Other includes
32
33
34 // Logger includes
35 #include "Logger/CLogger.h"
36
37
38
39 namespace Konclude {
40
41 namespace Utilities {
42
43
44 /*!
45 *
46 * \class CLinker
47 * \author Andreas Steigmiller
48 * \version 0.1
49 * \brief TODO
50 *
51 */
52 template<class T>
53 class CLinker : public CAllocationObject {
54 // public methods
55 public:
56 //! Constructor
57 CLinker();
58 CLinker(T dataElement, CLinker<T> *nextLink = 0);
59
60 //! Destructor
61 virtual ~CLinker();
62
63
64 CLinker<T> *init(T dataElement, CLinker<T> *nextLink = 0);
65
66 bool hasNext();
67
68
69 CLinker<T> *insertNext(CLinker<T> *nextLink);
70 CLinker<T> *getNext();
71
72 CLinker<T> *setNext(CLinker<T> *nextLink);
73
74 T getData();
75 CLinker<T> *setData(T dataElement);
76
77
78 CLinker<T> *append(CLinker<T> *appendingList);
79
80 CLinker<T> *removeNext();
81
82 CLinker<T> *getLastListLink();
83
84
85 // protected methods
86 protected:
87
88 // private methods
89 private:
90
91 // private variables
92 private:
93 CLinker<T> *next;
94 T data;
95
96 };
97
98
99 template<class T>
100 CLinker<T>::CLinker() {
101 next = 0;
102 }
103
104 template<class T>
105 CLinker<T>::CLinker(T dataElement, CLinker<T> *nextLink) {
106 next = 0;
107 setNext(nextLink);
108 data = dataElement;
109 }
110
111 template<class T>
112 CLinker<T> *CLinker<T>::init(T dataElement, CLinker<T> *nextLink) {
113 next = 0;
114 setNext(nextLink);
115 data = dataElement;
116 return this;
117 }
118
119
120 template<class T>
121 CLinker<T>::~CLinker() {
122 }
123
124
125 template<class T>
126 bool CLinker<T>::hasNext() {
127 return next != 0;
128 }
129
130
131 template<class T>
132 CLinker<T> *CLinker<T>::insertNext(CLinker<T> *nextLink) {
133 if (nextLink) {
134 CLinker<T> *tmpNext = next;
135 next = nextLink;
136 if (tmpNext) {
137 nextLink->append(tmpNext);
138 }
139 }
140 return this;
141 }
142
143
144
145 template<class T>
146 CLinker<T> *CLinker<T>::setNext(CLinker<T> *nextLink) {
147 next = nextLink;
148 return this;
149 }
150
151
152
153 template<class T>
154 CLinker<T> *CLinker<T>::getNext() {
155 return next;
156 }
157
158
159
160 template<class T>
161 T CLinker<T>::getData() {
162 return data;
163 }
164
165
166
167 template<class T>
168 CLinker<T> *CLinker<T>::setData(T dataElement) {
169 data = dataElement;
170 return this;
171 }
172
173
174
175 template<class T>
176 CLinker<T> *CLinker<T>::append(CLinker<T> *appendingList) {
177 CLinker<T> *last = getLastListLink();
178 last->insertNext(appendingList);
179 return this;
180 }
181
182 template<class T>
183 CLinker<T> *CLinker<T>::removeNext() {
184 CLinker<T> *tmpNext = next;
185 if (next) {
186 CLinker<T> *tmpNextNext = next->next;
187 next->next = 0;
188 setNext(tmpNextNext);
189 }
190 return tmpNext;
191 }
192
193
194 template<class T>
195 CLinker<T> *CLinker<T>::getLastListLink() {
196 CLinker<T> *lastListLink = this;
197 while (lastListLink->hasNext()) {
198 lastListLink = lastListLink->getNext();
199 }
200 return lastListLink;
201 }
202
203
204
205 }; // end namespace Utilities
206
207 }; // end namespace Konclude
208
209 #endif // KONCLUDE_UTILITIES_CLINKER_H