using System.Collections;
namespace GisSharpBlog.NetTopologySuite.Planargraph
{
///
/// The base class for all graph component classes.
/// Maintains flags of use in generic graph algorithms.
/// Provides two flags:
/// marked - typically this is used to indicate a state that persists
/// for the course of the graph's lifetime. For instance, it can be
/// used to indicate that a component has been logically deleted from the graph.
/// visited - this is used to indicate that a component has been processed
/// or visited by an single graph algorithm. For instance, a breadth-first traversal of the
/// graph might use this to indicate that a node has already been traversed.
/// The visited flag may be set and cleared many times during the lifetime of a graph.
///
public abstract class GraphComponent
{
///
///
///
protected bool isMarked = false;
///
///
///
protected bool isVisited = false;
///
/// Tests if a component has been visited during the course of a graph algorithm.
///
public bool IsVisited
{
get
{
return Visited;
}
}
///
/// Gets/Sets the visited flag for this component.
///
public bool Visited
{
get
{
return isVisited;
}
set
{
isVisited = value;
}
}
///
/// Tests if a component has been marked at some point during the processing
/// involving this graph.
///
public bool IsMarked
{
get
{
return Marked;
}
}
///
/// Gets/Sets the marked flag for this component.
///
public bool Marked
{
get
{
return isMarked;
}
set
{
isMarked = value;
}
}
///
/// Tests whether this component has been removed from its containing graph.
///
public abstract bool IsRemoved { get; }
#region Static
///
/// Sets the state
/// for all s in an .
///
/// A to scan.
/// The state to set the flag to.
public static void SetVisited(IEnumerator i, bool visited)
{
while (i.MoveNext())
{
GraphComponent comp = (GraphComponent) i.Current;
comp.Visited = visited;
}
}
///
/// Sets the state
/// for all s in an .
///
/// A to scan.
/// The state to set the flag to.
public static void SetMarked(IEnumerator i, bool marked)
{
while (i.MoveNext())
{
GraphComponent comp = (GraphComponent) i.Current;
comp.Marked = marked;
}
}
///
/// Finds the first
/// in a set
/// which has the specified state.
///
/// A to scan.
/// The state to test.
/// The first found, or null if none found.
public static GraphComponent GetComponentWithVisitedState(IEnumerator i, bool visitedState)
{
while (i.MoveNext())
{
GraphComponent comp = (GraphComponent) i.Current;
if (comp.IsVisited == visitedState)
{
return comp;
}
}
return null;
}
#endregion
}
}