/**********************************************************************
* $Id: GraphComponent.h 1820 2006-09-06 16:54:23Z mloskot $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2001-2002 Vivid Solutions Inc.
* Copyright (C) 2005-2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#ifndef GEOS_PLANARGRAPH_GRAPHCOMPONENT_H
#define GEOS_PLANARGRAPH_GRAPHCOMPONENT_H
namespace geos {
namespace planargraph { // geos.planargraph
/**
* \brief 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.
*
* Last port: planargraph/GraphComponent.java rev. 1.7 (JTS-1.7)
*
*/
class GraphComponent {
protected:
/// Variable holding ''marked'' status
bool isMarkedVar;
/// Variable holding ''visited'' status
bool isVisitedVar;
public:
GraphComponent()
:
isMarkedVar(false),
isVisitedVar(false)
{}
virtual ~GraphComponent() {};
/** \brief
* Tests if a component has been visited during the course
* of a graph algorithm.
*
* @return true if the component has been visited
*/
virtual bool isVisited() const { return isVisitedVar; }
/** \brief
* Sets the visited flag for this component.
* @param isVisited the desired value of the visited flag
*/
virtual void setVisited(bool isVisited) { isVisitedVar=isVisited; }
/** \brief
* Sets the Visited state for the elements of a container,
* from start to end iterator.
*
* @param start the start element
* @param end one past the last element
* @param visited the state to set the visited flag to
*/
template
static void setVisited(T start, T end, bool visited) {
for(T i=start; i!=end; ++i) {
//i->second->setVisited(visited);
(*i)->setVisited(visited);
}
}
/** \brief
* Sets the Visited state for the values of each map
* container element, from start to end iterator.
*
* @param start the start element
* @param end one past the last element
* @param visited the state to set the visited flag to
*/
template
static void setVisitedMap(T start, T end, bool visited) {
for(T i=start; i!=end; ++i) {
i->second->setVisited(visited);
}
}
/** \brief
* Tests if a component has been marked at some point
* during the processing involving this graph.
* @return true if the component has been marked
*/
virtual bool isMarked() const { return isMarkedVar; }
/** \brief
* Sets the marked flag for this component.
* @param isMarked the desired value of the marked flag
*/
virtual void setMarked(bool isMarked) { isMarkedVar=isMarked; }
};
// For backward compatibility
//typedef GraphComponent planarGraphComponent;
} // namespace geos::planargraph
} // namespace geos
#endif // GEOS_PLANARGRAPH_GRAPHCOMPONENT_H
/**********************************************************************
* $Log$
* Revision 1.1 2006/03/21 21:42:54 strk
* planargraph.h header split, planargraph:: classes renamed to match JTS symbols
*
**********************************************************************/