Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Forstner, Matyas | |
11 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #include "Node.hh" |
14 | #include "error.h" | |
15 | #include <stdio.h> | |
16 | ||
17 | // ================================= | |
18 | // ===== Node | |
19 | // ================================= | |
20 | ||
21 | int Node::counter=0; | |
22 | #ifdef MEMORY_DEBUG | |
23 | static Node *list_head = 0, *list_tail = 0; | |
24 | #endif | |
25 | ||
26 | Node::Node() | |
27 | { | |
28 | #ifdef MEMORY_DEBUG | |
29 | prev_node = list_tail; | |
30 | next_node = 0; | |
31 | if (list_tail) list_tail->next_node = this; | |
32 | else list_head = this; | |
33 | list_tail = this; | |
34 | #endif | |
35 | counter++; | |
36 | } | |
37 | ||
38 | Node::Node(const Node& p) | |
39 | { | |
40 | #ifdef MEMORY_DEBUG | |
41 | prev_node = list_tail; | |
42 | next_node = 0; | |
43 | if (list_tail) list_tail->next_node = this; | |
44 | else list_head = this; | |
45 | list_tail = this; | |
46 | #endif | |
47 | counter++; | |
48 | } | |
49 | ||
50 | Node::~Node() | |
51 | { | |
52 | counter--; | |
53 | #ifdef MEMORY_DEBUG | |
54 | if (prev_node) prev_node->next_node = next_node; | |
55 | else list_head = next_node; | |
56 | if (next_node) next_node->prev_node = prev_node; | |
57 | else list_tail = prev_node; | |
58 | #endif | |
59 | } | |
60 | ||
61 | void Node::chk_counter() | |
62 | { | |
63 | DEBUG(1, "Node::counter is %d", counter); | |
64 | if(counter) | |
65 | WARNING("%d nodes were not deleted." | |
66 | " Please send a bug report including" | |
67 | " the current input file(s).", counter); | |
68 | #ifdef MEMORY_DEBUG | |
69 | for(Node *iter = list_head; iter; iter = iter->next_node) { | |
70 | fprintf(stderr, "Undeleted node address: %p.\n", iter); | |
71 | } | |
72 | list_head = 0; | |
73 | list_tail = 0; | |
74 | #endif | |
75 | } | |
76 |