Branch data Line data Source code
1 : : /*
2 : : * AF2Binding.hpp
3 : : *
4 : : * An AF2Binding is an object that manages binding the edges and vertices
5 : : * that a rule has specified must exist (i.e., AF2RuleExistingEdge and
6 : : * AF2RuleExistingVertex) to edges and vertices (i.e., AF2Edge2D
7 : : * and AF2Point2D) that actually do exist in some AF2Neighborhood.
8 : : *
9 : : * The AF2Binding provides methods to bind an edge or a vertex and to check
10 : : * whether binding an edge or vertex is consistent with what has already
11 : : * been bound. Binding an edge implies binding the endpoint vertices
12 : : * of that edge. Attempting to bind an edge or vertex that is not
13 : : * consistent with what is already bound will result in an exception.
14 : : * Attempting to bind an edge or vertex that is already bound will succeed
15 : : * if the binding is consistent.
16 : : *
17 : : * AF2Binding also provides methods to release edges or vertices that are
18 : : * bound. Attempting to release an edge or vertex that is not bound
19 : : * will result in an exception. The model for binding a vertex tracks
20 : : * both whether the vertex has been explicitly bound with a call to the
21 : : * method that binds vertices and whether it is implicitly bound because it
22 : : * is an endpoint of an edge that is bound. Attempting to release a vertex
23 : : * that has been bound in both ways will release the explicit bound, but not
24 : : * the implicit bound. Attempting to release a vertex that is implicitly
25 : : * bound but not explicitly bound will result in an exception.
26 : : */
27 : :
28 : : #ifndef AF2BINDING_HPP
29 : : #define AF2BINDING_HPP
30 : :
31 : : // C++
32 : : #include <map>
33 : : #include <set>
34 : :
35 : : // MeshKit
36 : : #include "meshkit/AF2Edge2D.hpp"
37 : : #include "meshkit/AF2Point2D.hpp"
38 : : #include "meshkit/AF2RuleExistEdge.hpp"
39 : : #include "meshkit/AF2RuleExistVertex.hpp"
40 : :
41 [ + - ][ + - ]: 235863 : class AF2Binding
[ + - ]
42 : : {
43 : : private:
44 : :
45 : : struct VtxBindRec
46 : : {
47 : : const AF2Point2D* pointPtr;
48 : : unsigned int numBoundEdges;
49 : : bool xplctBound;
50 : :
51 : : /**
52 : : * \brief Constructor
53 : : */
54 : : VtxBindRec();
55 : : };
56 : :
57 : : std::map<const AF2RuleExistVertex*, VtxBindRec> vertexBindMap;
58 : : std::set<const AF2Point2D*> verticesInUse;
59 : : std::map<const AF2RuleExistEdge*, const AF2Edge2D*> edgeBindMap;
60 : : std::set<const AF2Edge2D*> edgesInUse;
61 : :
62 : : /**
63 : : * \brief Bind a vertex.
64 : : *
65 : : * \param isExplicit differentiate between binding a vertex due
66 : : * to an explicit method call from a user and binding a vertex
67 : : * implicitly because it is an endpoint of an edge
68 : : */
69 : : void bind(const AF2RuleExistVertex* ruleVertexPtr,
70 : : const AF2Point2D* ngbhdVertexPtr, bool isExplicit);
71 : :
72 : : /**
73 : : * \brief Release a vertex binding.
74 : : *
75 : : * \param isExplicit differentiate between releasing a vertex due
76 : : * to an explicit method call from a user and releasing an implicit
77 : : * binding of the vertex due to the vertex being an endpoint of
78 : : * an edge that is being released
79 : : */
80 : : void release(const AF2RuleExistVertex* ruleVertexPtr, bool isExplicit);
81 : :
82 : : public:
83 : :
84 : : /**
85 : : * \brief Bind a rule edge to a neighborhood edge.
86 : : *
87 : : * Binds a rule edge to a neighborhood edge and implicitly binds the
88 : : * rule vertices that are endpoints of the rule edge to the neighborhood
89 : : * vertices that are endpoints of the neighborhood edge. If binding
90 : : * the edge is not consistent, this method will throw an exception.
91 : : * The consistency of the binding can be checked before attempting
92 : : * the binding by calling the isConsistent method.
93 : : *
94 : : * This method does not take ownership of the pointers passed into
95 : : * it. The calling context must ensure that the pointers remain valid
96 : : * as long as this AF2Binding (or any copy of it) is in use.
97 : : *
98 : : * \param ruleEdgePtr a pointer to the rule edge that should be bound
99 : : * \param ngbhdEdgePtr a pointer to the neighborhood edge to which the
100 : : * rule edge should be bound
101 : : */
102 : : void bind(const AF2RuleExistEdge* ruleEdgePtr,
103 : : const AF2Edge2D* ngbhdEdgePtr);
104 : :
105 : : /**
106 : : * \brief Explicitly bind a rule vertex to a neighborhood vertex.
107 : : *
108 : : * Explicitly binds a rule vertex to a neighborhood vertex, even if
109 : : * the rule vertex is already implicitly bound to the neighborhood
110 : : * vertex. If binding the vertex is not consistent, this method will
111 : : * throw an exception. The consistency of the binding can be checked
112 : : * before attempting the binding by calling the isConsistent method.
113 : : *
114 : : * This method does not take ownership of the pointers passed into
115 : : * it. The calling context must ensure that the pointers remain valid
116 : : * as long as this AF2Binding (or any copy of it) is in use.
117 : : *
118 : : * \param ruleVertexPtr a pointer to the rule vertex that should be bound
119 : : * \param ngbhdVertexPtr a pointer to the neighborhood vertex to which the
120 : : * rule vertex should be bound
121 : : */
122 : : void bind(const AF2RuleExistVertex* ruleVertexPtr,
123 : : const AF2Point2D* ngbhdVertexPtr);
124 : :
125 : :
126 : : /**
127 : : * \brief Retrieve the neighborhood vertex to which a rule vertex is bound.
128 : : *
129 : : * If the rule vertex is bound to a neighborhood vertex implicitly,
130 : : * explicitly, or both implicitly and explicitly, this method will return
131 : : * a pointer to the neighborhood vertex that the rule vertex is bound to.
132 : : * If the rule vertex is not bound to any neighborhood vertex,
133 : : * this method will return a null pointer.
134 : : *
135 : : * \param ruleVertexPtr a pointer to the rule existing vertex for which
136 : : * to retrieve the bound value
137 : : * \return a pointer to the neighborhood vertex to which the rule
138 : : * existing vertex is bound, or a null pointer if rule veretx
139 : : * is not bound to any neighborhood vertex
140 : : */
141 : : const AF2Point2D* getBoundValue(
142 : : const AF2RuleExistVertex* ruleVertexPtr) const;
143 : :
144 : : /**
145 : : * \brief Check whether binding a rule edge to a neighborhood edge
146 : : * is consistent with this AF2Binding's current bindings.
147 : : *
148 : : * Binding an edge may be inconsistent for any of the following reasons.
149 : : * (1) The AF2Binding may have the rule edge bound to some other
150 : : * neighborhood edge.
151 : : * (2) The AF2Binding may have some other rule edge bound to the
152 : : * neighborhood edge.
153 : : * (3) There may be an inconsistency in binding one of the endpoints of
154 : : * the edge. See the isConsistent method for checking consistency of
155 : : * binding a rule vertex to a neighborhood vertex.
156 : : *
157 : : * \param ruleEdgePtr a pointer to a rule edge
158 : : * \param ngbhdEdgePtr a pointer to a neighborhood edge
159 : : * \return true if binding the rule edge to the neighborhood edge
160 : : * is consistent with this AF2Binding's current bindings; false otherwise
161 : : */
162 : : bool isConsistent(const AF2RuleExistEdge* ruleEdgePtr,
163 : : const AF2Edge2D* ngbhdEdgePtr) const;
164 : :
165 : : /**
166 : : * \brief Check whether binding a rule vertex to a neighborhood vertex
167 : : * is consistent with this AF2Binding's current bindings.
168 : : *
169 : : * Binding the specified rule vertex to the specified neighborhood
170 : : * vertex may be inconsistent for any of the following reasons.
171 : : * (1) The AF2Binding may have the rule vertex bound to some other
172 : : * neighborhood vertex.
173 : : * (2) The AF2Binding may have some other rule vertex bound to the
174 : : * neighborhood vertex.
175 : : *
176 : : * \param ruleVertexPtr a pointer to a rule vertex
177 : : * \param ngbhdVertexPtr a pointer to a neighborhood vertex
178 : : * \return true if binding the rule vertex to the neighborhood vertex
179 : : * is consistent with this AF2Binding's current bindings; false otherwise
180 : : */
181 : : bool isConsistent(const AF2RuleExistVertex* ruleVertexPtr,
182 : : const AF2Point2D* ngbhdVertexPtr) const;
183 : :
184 : : /**
185 : : * \brief Release the binding of the specified rule edge to whatever
186 : : * neighborhood edge it is bound to.
187 : : *
188 : : * Release the binding of the specified rule edge and release the
189 : : * implicit binding of the rule vertices that are endpoints of the
190 : : * rule edge. Releasing the endpoints will completely release an
191 : : * endpoint's vertex binding only if the vertex is not explicitly
192 : : * bound and there are no other bound edges that share the endpoint.
193 : : *
194 : : * This method will throw an exception if the rule edge is not bound
195 : : * to a neighborhood edge.
196 : : *
197 : : * \param ruleEdgePtr a pointer to the rule edge for which to release
198 : : * the binding
199 : : */
200 : : void release(const AF2RuleExistEdge* ruleEdgePtr);
201 : :
202 : : /**
203 : : * \brief Release the explicit binding of the specified rule vertex to
204 : : * whatever neighborhood vertex the rule vertex is bound to.
205 : : *
206 : : * This method will throw an exception if the specified rule vertex
207 : : * is not bound to any neighborhood vertex or if the vertex is
208 : : * only implicitly bound to a neighborhood vertex because it is
209 : : * the endpoint of one or more rule edges that are bound to
210 : : * neighborhood edges.
211 : : *
212 : : * \param ruleVertexPtr a pointer to the rule vertex for which to release
213 : : * the explicit binding
214 : : */
215 : : void release(const AF2RuleExistVertex* ruleVertexPtr);
216 : : };
217 : :
218 : : #endif
|