/src/geos/include/geos/planargraph/GraphComponent.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
7 | | * Copyright (C) 2005-2006 Refractions Research Inc. |
8 | | * |
9 | | * This is free software; you can redistribute and/or modify it under |
10 | | * the terms of the GNU Lesser General Public Licence as published |
11 | | * by the Free Software Foundation. |
12 | | * See the COPYING file for more information. |
13 | | * |
14 | | ********************************************************************** |
15 | | * |
16 | | * Last port: planargraph/GraphComponent.java rev. 1.7 (JTS-1.7) |
17 | | * |
18 | | **********************************************************************/ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <geos/export.h> |
23 | | |
24 | | namespace geos { |
25 | | namespace planargraph { // geos.planargraph |
26 | | |
27 | | /** |
28 | | * \brief The base class for all graph component classes. |
29 | | * |
30 | | * Maintains flags of use in generic graph algorithms. |
31 | | * Provides two flags: |
32 | | * |
33 | | * - <b>marked</b> - typically this is used to indicate a state that |
34 | | * persists for the course of the graph's lifetime. For instance, |
35 | | * it can be used to indicate that a component has been logically |
36 | | * deleted from the graph. |
37 | | * - <b>visited</b> - this is used to indicate that a component has been |
38 | | * processed or visited by an single graph algorithm. For instance, |
39 | | * a breadth-first traversal of the graph might use this to indicate |
40 | | * that a node has already been traversed. |
41 | | * The visited flag may be set and cleared many times during the |
42 | | * lifetime of a graph. |
43 | | * |
44 | | */ |
45 | | class GEOS_DLL GraphComponent { |
46 | | |
47 | | protected: |
48 | | |
49 | | /// Variable holding ''marked'' status |
50 | | bool isMarkedVar; |
51 | | |
52 | | /// Variable holding ''visited'' status |
53 | | bool isVisitedVar; |
54 | | |
55 | | public: |
56 | | |
57 | | GraphComponent() |
58 | | : |
59 | 0 | isMarkedVar(false), |
60 | 0 | isVisitedVar(false) |
61 | 0 | {} |
62 | | |
63 | | virtual |
64 | 0 | ~GraphComponent() {} |
65 | | |
66 | | /** \brief |
67 | | * Tests if a component has been visited during the course |
68 | | * of a graph algorithm. |
69 | | * |
70 | | * @return <code>true</code> if the component has been visited |
71 | | */ |
72 | | virtual bool |
73 | | isVisited() const |
74 | 0 | { |
75 | 0 | return isVisitedVar; |
76 | 0 | } |
77 | | |
78 | | /** \brief |
79 | | * Sets the visited flag for this component. |
80 | | * @param p_isVisited the desired value of the visited flag |
81 | | */ |
82 | | virtual void |
83 | | setVisited(bool p_isVisited) |
84 | 0 | { |
85 | 0 | isVisitedVar = p_isVisited; |
86 | 0 | } |
87 | | |
88 | | /** \brief |
89 | | * Sets the Visited state for the elements of a container, |
90 | | * from start to end iterator. |
91 | | * |
92 | | * @param start the start element |
93 | | * @param end one past the last element |
94 | | * @param visited the state to set the visited flag to |
95 | | */ |
96 | | template <typename T> |
97 | | static void |
98 | | setVisited(T start, T end, bool visited) |
99 | | { |
100 | | for(T i = start; i != end; ++i) { |
101 | | (*i)->setVisited(visited); |
102 | | } |
103 | | } |
104 | | |
105 | | /** \brief |
106 | | * Sets the Visited state for the values of each map |
107 | | * container element, from start to end iterator. |
108 | | * |
109 | | * @param start the start element |
110 | | * @param end one past the last element |
111 | | * @param visited the state to set the visited flag to |
112 | | */ |
113 | | template <typename T> |
114 | | static void |
115 | | setVisitedMap(T start, T end, bool visited) |
116 | | { |
117 | | for(T i = start; i != end; ++i) { |
118 | | i->second->setVisited(visited); |
119 | | } |
120 | | } |
121 | | |
122 | | /** \brief |
123 | | * Sets the Marked state for the elements of a container, |
124 | | * from start to end iterator. |
125 | | * |
126 | | * @param start the start element |
127 | | * @param end one past the last element |
128 | | * @param marked the state to set the marked flag to |
129 | | */ |
130 | | template <typename T> |
131 | | static void |
132 | | setMarked(T start, T end, bool marked) |
133 | 0 | { |
134 | 0 | for(T i = start; i != end; ++i) { |
135 | 0 | (*i)->setMarked(marked); |
136 | 0 | } |
137 | 0 | } |
138 | | |
139 | | |
140 | | /** \brief |
141 | | * Sets the Marked state for the values of each map |
142 | | * container element, from start to end iterator. |
143 | | * |
144 | | * @param start the start element |
145 | | * @param end one past the last element |
146 | | * @param marked the state to set the visited flag to |
147 | | */ |
148 | | template <typename T> |
149 | | static void |
150 | | setMarkedMap(T start, T end, bool marked) |
151 | 0 | { |
152 | 0 | for(T i = start; i != end; ++i) { |
153 | 0 | i->second->setMarked(marked); |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | /** \brief |
158 | | * Tests if a component has been marked at some point |
159 | | * during the processing involving this graph. |
160 | | * @return <code>true</code> if the component has been marked |
161 | | */ |
162 | | virtual bool |
163 | | isMarked() const |
164 | 0 | { |
165 | 0 | return isMarkedVar; |
166 | 0 | } |
167 | | |
168 | | /** \brief |
169 | | * Sets the marked flag for this component. |
170 | | * @param p_isMarked the desired value of the marked flag |
171 | | */ |
172 | | virtual void |
173 | | setMarked(bool p_isMarked) |
174 | 0 | { |
175 | 0 | isMarkedVar = p_isMarked; |
176 | 0 | } |
177 | | |
178 | | }; |
179 | | |
180 | | } // namespace geos::planargraph |
181 | | } // namespace geos |
182 | | |