ScummVM API documentation
dgGraph.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /****************************************************************************
23 *
24 * Visual C++ 6.0 created by: Julio Jerez
25 *
26 ****************************************************************************/
27 #ifndef __dgGraph__
28 #define __dgGraph__
29 
30 #include "dgStdafx.h"
31 #include "dgRef.h"
32 #include "dgList.h"
33 
34 
35 template<class dgNodeData, class dgEdgeData> class dgGraphEdge;
36 template<class dgNodeData, class dgEdgeData> class dgGraphNode;
37 
38 template<class dgNodeData, class dgEdgeData>
39 class dgGraph: public dgList<dgGraphNode<dgNodeData, dgEdgeData> > {
40 public:
41 // dgGraph ();
42  dgGraph(dgMemoryAllocator *const allocator);
43  ~dgGraph();
44 
45 
47  void DeleteNode(typename dgGraph<dgNodeData, dgEdgeData>::dgListNode *const node);
48 
49  void Trace() const;
50 
51 #ifdef _DEBUG
52  dgInt32 m_counter;
53 #endif
54 };
55 
56 template<class dgNodeData, class dgEdgeData>
57 class dgGraphNode: public dgList<dgGraphEdge<dgNodeData, dgEdgeData> > {
58 public:
59  dgGraphNode();
60  ~dgGraphNode();
61 
63  void DeleteHalfEdge(typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *const edge);
64  void DeleteEdge(typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *const edge);
65 
66  void Trace() const;
67 
68 #ifdef _DEBUG
69  dgInt32 m_index;
70 #endif
71 
72  dgNodeData m_nodeData;
73 };
74 
75 template<class dgNodeData, class dgEdgeData>
76 class dgGraphEdge {
77 public:
78  dgGraphEdge();
79  ~dgGraphEdge();
80 
82  dgEdgeData m_edgeData;
83 };
84 
85 
86 /*
87 template<class dgNodeData, class dgEdgeData>
88 dgGraph<dgNodeData, dgEdgeData>::dgGraph ()
89  :dgList<dgGraphNode<dgNodeData, dgEdgeData> >()
90 {
91 #ifdef _DEBUG
92  m_counter = 0;
93 #endif
94 }
95 */
96 
97 template<class dgNodeData, class dgEdgeData>
100 #ifdef _DEBUG
101  m_counter = 0;
102 #endif
103 }
104 
105 
106 template<class dgNodeData, class dgEdgeData>
108 }
109 
110 template<class dgNodeData, class dgEdgeData>
113 
114  node->GetInfo().SetAllocator(dgGraph<dgNodeData, dgEdgeData>::GetAllocator());
115 #ifdef _DEBUG
116  node->GetInfo().m_index = m_counter;
117  m_counter ++;
118 #endif
119 
120  return node;
121 }
122 
123 template<class dgNodeData, class dgEdgeData>
125  for (typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *link = node->GetInfo().GetFirst(); link; link = link->GetNext()) {
126  typename dgGraph<dgNodeData, dgEdgeData>::dgListNode *const twinNode = link->GetInfo().m_node;
127  for (typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *link1 = twinNode->GetInfo().GetFirst(); link1; link1 = link1->GetNext()) {
128  if (link1->GetInfo().m_node == node) {
129  twinNode->GetInfo().Remove(link1);
130  break;
131  }
132  }
133  }
135 }
136 
137 template<class dgNodeData, class dgEdgeData>
139  for (typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *link = dgGraphNode<dgNodeData, dgEdgeData>::GetFirst(); link; link = link->GetNext()) {
140  link->GetInfo().Trace();
141 // dgTrace (("%d: ", link->GetInfo().m_index));
142 // for (dgGraphNode<dgNodeData, dgEdgeData>::dgListNode* edge = link->GetInfo().GetFirst(); edge; edge = edge->GetNext()) {
143 // dgListNode* node;
144 // node = edge->GetInfo().m_node;
145 // dgTrace (("%d ", node->GetInfo().m_index));
146 // }
147 // dgTrace (("\n"));
148  }
149  dgTrace(("\n"));
150 }
151 
152 
153 template<class dgNodeData, class dgEdgeData>
156 
157 }
158 
159 
160 template<class dgNodeData, class dgEdgeData>
162 
163 }
164 
165 template<class dgNodeData, class dgEdgeData>
168 
169  edge->GetInfo().m_node = node;
170  return edge;
171 }
172 
173 template<class dgNodeData, class dgEdgeData>
176 }
177 
178 template<class dgNodeData, class dgEdgeData>
180  typename dgGraph<dgNodeData, dgEdgeData>::dgListNode *const node = edge->GetInfo().m_node;
181 
182  for (typename dgGraphNode<dgNodeData, dgEdgeData>::dgListNode *twinEdge = node->GetInfo().GetFirst(); twinEdge; twinEdge = twinEdge->GetNext()) {
183  if (&twinEdge->GetInfo().m_node->GetInfo() == this) {
184  node->GetInfo().DeleteHalfEdge(twinEdge);
185  break;
186  }
187  }
188 
189  DeleteHalfEdge(edge);
190 }
191 
192 template<class dgNodeData, class dgEdgeData>
194  dgTrace(("%d: ", m_index));
195  for (typename dgGraph<dgNodeData, dgEdgeData>::dgListNode *edge = typename dgGraph<dgNodeData, dgEdgeData>::GetFirst(); edge; edge = edge->GetNext()) {
196  typename dgGraph<dgNodeData, dgEdgeData>::dgListNode *const node;
197  node = edge->GetInfo().m_node;
198  dgTrace(("%d ", node->GetInfo().m_index));
199  }
200  dgTrace(("\n"));
201 
202 }
203 
204 
205 template<class dgNodeData, class dgEdgeData>
207 
208 }
209 
210 template<class dgNodeData, class dgEdgeData>
212 
213 }
214 
215 
216 
217 #endif
218 
Definition: dgGraph.h:39
Definition: dgList.h:33
Definition: dgGraph.h:35
Definition: dgGraph.h:36
Definition: dgMemory.h:80