GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/PhoenixGraph/src/Node_impl.h Lines: 79 80 98.8 %
Date: 2024-12-09 15:41:43 Branches: 42 49 85.7 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#ifndef __NODE_H_IMPL__
8
#define __NODE_H_IMPL__
9
10
#include <sstream>
11
12
#include "Node.h"
13
14
///Convert a type into a string
15
/**	@param val : value to be converted
16
 * 	@return converted string
17
*/
18
template<typename T>
19
119
std::string node_convertToString(const T & val){
20
238
	std::stringstream str;
21
119
	str << val;
22
23
357
	std::string varStr(str.str()), outputStr(""), strCheck(" \t\n/.:-");
24
238
	for(size_t i(0lu); i < varStr.size(); ++i){
25
119
		char ch = varStr[i];
26
119
		bool isNotFound(true);
27

952
		for(size_t j(0lu); j < strCheck.size() && isNotFound; ++j){
28
833
			isNotFound &= ch != strCheck[j];
29
		}
30
119
		if(isNotFound){
31
119
			outputStr += ch;
32
		}
33
	}
34
238
	return outputStr;
35
}
36
37
///Default constructor of Node
38
/**	@param name : name of th current Node
39
*/
40
template<typename T, typename UIdx>
41
26
Node<T, UIdx>::Node(const std::string & name){
42
26
	initialisationNode();
43
26
	p_name = name;
44
26
}
45
///Constructor of Node
46
/**	@param data : data of the current Node
47
 * 	@param name : name of th current Node
48
*/
49
template<typename T, typename UIdx>
50
26
Node<T, UIdx>::Node(const T & data, const std::string & name){
51
26
	initialisationNode();
52
26
	p_name = name;
53
26
	p_data = data;
54
26
}
55
56
///Copy constructor of Node
57
/**	@param other : class to copy
58
*/
59
template<typename T, typename UIdx>
60
6
Node<T, UIdx>::Node(const Node<T, UIdx> & other){
61
6
	copyNode(other);
62
6
}
63
64
///Destructor of Node
65
template<typename T, typename UIdx>
66
116
Node<T, UIdx>::~Node(){
67
68
}
69
70
///Definition of equal operator of Node
71
/**	@param other : class to copy
72
 * 	@return copied class
73
*/
74
template<typename T, typename UIdx>
75
26
Node<T, UIdx> & Node<T, UIdx>::operator = (const Node<T, UIdx> & other){
76
26
	copyNode(other);
77
26
	return *this;
78
}
79
80
///Add a child to the current Node
81
/**	@param child : index of the corresponding child Node
82
*/
83
template<typename T, typename UIdx>
84
25
void Node<T, UIdx>::addChild(UIdx child){
85
25
	p_listChild.push_back(child);
86
25
}
87
88
///Add a parent to the current Node
89
/**	@param parent : index of the corresponding parent Node
90
*/
91
template<typename T, typename UIdx>
92
25
void Node<T, UIdx>::addParent(UIdx parent){
93
25
	p_listParent.push_back(parent);
94
25
}
95
96
///Remove connection with child
97
/**	@param child : index of the child to be removed
98
*/
99
template<typename T, typename UIdx>
100
2
void Node<T, UIdx>::removeChild(UIdx child){
101
2
	listindex_remove(p_listChild, child);
102
2
}
103
104
///Remove connection with parent
105
/**	@param parent : index of the parent to be removed
106
*/
107
template<typename T, typename UIdx>
108
2
void Node<T, UIdx>::removeParent(UIdx parent){
109
2
	listindex_remove(p_listParent, parent);
110
2
}
111
112
///Set the list of children of the Node
113
/**	@param listChild : list of children of the Node
114
*/
115
template<typename T, typename UIdx>
116
void Node<T, UIdx>::setListChild(const std::list<UIdx> & listChild){p_listChild = listChild;}
117
118
///Set the list of parents of the Node
119
/**	@param listParent : list of parents of the Node
120
*/
121
template<typename T, typename UIdx>
122
void Node<T, UIdx>::setListParent(const std::list<UIdx> & listParent){p_listParent = listParent;}
123
124
///Set the index of the Node
125
/**	@param index : index of the Node
126
*/
127
template<typename T, typename UIdx>
128
26
void Node<T, UIdx>::setIndex(UIdx index){p_index = index;}
129
130
///Set the name of the Node
131
/**	@param name : name of the Node
132
*/
133
template<typename T, typename UIdx>
134
void Node<T, UIdx>::setName(const std::string & name){p_name = name;}
135
136
///Say if the node is updated
137
/**	@param isUpdated : true if the Node is updated, false otherwise
138
*/
139
template<typename T, typename UIdx>
140
26
void Node<T, UIdx>::setIsUpdated(bool isUpdated){p_isUpdated = isUpdated;}
141
142
///Set the data of the Node
143
/**	@param data : data of the Node
144
*/
145
template<typename T, typename UIdx>
146
void Node<T, UIdx>::setData(const T & data){p_data = data;}
147
148
///Get the list of children of the Node
149
/**	@return list of children of the Node
150
*/
151
template<typename T, typename UIdx>
152
47
const std::list<UIdx> & Node<T, UIdx>::getListChild() const{return p_listChild;}
153
154
///Get the list of children of the Node
155
/**	@return list of children of the Node
156
*/
157
template<typename T, typename UIdx>
158
11
std::list<UIdx> & Node<T, UIdx>::getListChild(){return p_listChild;}
159
160
///Get the list of parents of the Node
161
/**	@return list of parents of the Node
162
*/
163
template<typename T, typename UIdx>
164
5
const std::list<UIdx> & Node<T, UIdx>::getListParent() const{return p_listParent;}
165
166
///Get the list of parents of the Node
167
/**	@return list of parents of the Node
168
*/
169
template<typename T, typename UIdx>
170
10
std::list<UIdx> & Node<T, UIdx>::getListParent(){return p_listParent;}
171
172
///Get the index of the Node
173
/**	@return index of the Node
174
*/
175
template<typename T, typename UIdx>
176
UIdx Node<T, UIdx>::getIndex() const{return p_index;}
177
178
///Get the name of the Node
179
/**	@return name of the Node
180
*/
181
template<typename T, typename UIdx>
182
const std::string & Node<T, UIdx>::getName() const{return p_name;}
183
184
///Get the name of the Node
185
/**	@return name of the Node
186
*/
187
template<typename T, typename UIdx>
188
std::string & Node<T, UIdx>::getName(){return p_name;}
189
190
///Say if the node is updated
191
/**	@return true if the Node is updated, false otherwise
192
*/
193
template<typename T, typename UIdx>
194
10
bool Node<T, UIdx>::getIsUpdated() const{return p_isUpdated;}
195
196
///Say if the node is updated
197
/**	@return true if the Node is updated, false otherwise
198
*/
199
template<typename T, typename UIdx>
200
8
bool & Node<T, UIdx>::getIsUpdated(){return p_isUpdated;}
201
202
///Get the data of the Node
203
/**	@return data of the Node
204
*/
205
template<typename T, typename UIdx>
206
const T & Node<T, UIdx>::getData() const{return p_data;}
207
208
///Get the data of the Node
209
/**	@return data of the Node
210
*/
211
template<typename T, typename UIdx>
212
T & Node<T, UIdx>::getData(){return p_data;}
213
214
///Say if the current Node has no parent
215
/**	@return true if the current Node has no parent, false otherwise
216
*/
217
template<typename T, typename UIdx>
218
46
bool Node<T, UIdx>::isStart() const{return p_listParent.size() == 0lu;}
219
220
///Say if the current Node has no child
221
/**	@return true if the current Node has no child, false otherwise
222
*/
223
template<typename T, typename UIdx>
224
27
bool Node<T, UIdx>::isEnd() const{return p_listChild.size() == 0lu;}
225
226
///Get the dot name of the current Node
227
/**	@return dot name of the current Node
228
*/
229
template<typename T, typename UIdx>
230
119
std::string Node<T, UIdx>::getDotName() const{
231
119
	std::string body("");
232
119
	body += "node";
233
119
	body += node_convertToString(p_index);
234
119
	return body;
235
}
236
237
///Get the dot definition name of the current Node
238
/**	@return dot definition name of the current Node
239
*/
240
template<typename T, typename UIdx>
241
41
std::string Node<T, UIdx>::getDotDefinition() const{
242
41
	std::string body("");
243
82
	std::string strName(p_name);
244
41
	if(strName == ""){
245
		strName = node_convertToString(p_index);
246
	}
247

41
	body += "\t" + getDotName() + "[label=\"" + strName + "\"][color=\"blue\"]";
248
41
	if(isStart()){
249
19
		body += "[shape=octagon]";
250
22
	}else if(isEnd()){
251
7
		body += "[shape=cylinder]";
252
	}else{
253
15
		body += "[shape=record]";
254
	}
255
41
	body += ";\n";
256
82
	return body;
257
}
258
259
///Copy function of Node
260
/**	@param other : class to copy
261
*/
262
template<typename T, typename UIdx>
263
32
void Node<T, UIdx>::copyNode(const Node<T, UIdx> & other){
264
32
	p_listChild = other.p_listChild;
265
32
	p_listParent = other.p_listParent;
266
32
	p_index = other.p_index;
267
32
	p_name = other.p_name;
268
32
	p_isUpdated = other.p_isUpdated;
269
32
	p_data = other.p_data;
270
32
}
271
272
///Initialisation function of the class Node
273
template<typename T, typename UIdx>
274
52
void Node<T, UIdx>::initialisationNode(){
275
52
	p_name = "";
276
52
	p_isUpdated = false;
277
52
}
278
279
280
281
282
283
#endif
284
285
286