Skip to content

Commit

Permalink
include/geos/geomgraph: remove useless virtual qualifiers, add final …
Browse files Browse the repository at this point in the history
…and improve a bit const safety (#1140)

* Add -Wsuggest-override for gcc, and add missing override qualifiers

* include/geos/geomgraph: remove useless virtual qualifiers, add final and improve a bit const safety

The removal of the useless virtual qualifiers is safe since the addition
of -Wsuggest-override in a previous commit makes sure that all
overloaded methods (of methods that ware marked as 'virtual') are marked
as 'override', which in turns ensures that all base methods that are overriden
are marked as 'virtual'.
(This doesn't change the status quo if a method was overloaded, but the
base class lacked a 'virtual' and the overloaded method lacked a
'override'...)

Said otherwise, the dangerous situation would be a
class A { virtual void foo(); };
class B: public A { virtual void foo(); };
where we would erroneously remove the virtual qualifier.

But given -Wsuggest-override, the above code would have been corrected
to
class A { virtual void foo(); };
class B: public A { virtual void foo() override; };

And thus if we erroneously remove the virtual qualifier from A::foo() the
compiler will error out.

This results in a small reduction in the size of libgeos.so (5954240 to 5946336),
suggesting that de-virtualizations are done.
  • Loading branch information
rouault authored Aug 22, 2024
1 parent eaf9005 commit 5ab1b4b
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 114 deletions.
2 changes: 1 addition & 1 deletion include/geos/geomgraph/DirectedEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace geos {
namespace geomgraph { // geos.geomgraph

/// A directed EdgeEnd
class GEOS_DLL DirectedEdge: public EdgeEnd {
class GEOS_DLL DirectedEdge final: public EdgeEnd {

public:

Expand Down
55 changes: 31 additions & 24 deletions include/geos/geomgraph/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace geos {
namespace geomgraph { // geos.geomgraph

/** The edge component of a geometry graph */
class GEOS_DLL Edge: public GraphComponent {
class GEOS_DLL Edge final: public GraphComponent {
using GraphComponent::updateIM;

private:
Expand Down Expand Up @@ -102,36 +102,36 @@ class GEOS_DLL Edge: public GraphComponent {

~Edge() override;

virtual size_t
size_t
getNumPoints() const
{
return pts->getSize();
}

virtual const geom::CoordinateSequence*
const geom::CoordinateSequence*
getCoordinates() const
{
testInvariant();
return pts.get();
}

virtual const geom::Coordinate&
const geom::Coordinate&
getCoordinate(std::size_t i) const
{
testInvariant();
return pts->getAt(i);
}

virtual const geom::Coordinate&
const geom::Coordinate&
getCoordinate() const
{
testInvariant();
return pts->getAt(0);
}


virtual Depth&
getDepth()
const Depth&
getDepth() const
{
testInvariant();
return depth;
Expand All @@ -142,41 +142,48 @@ class GEOS_DLL Edge: public GraphComponent {
*
* @return the change in depth as the edge is crossed from R to L
*/
virtual int
int
getDepthDelta() const
{
testInvariant();
return depthDelta;
}

virtual void
void
setDepthDelta(int newDepthDelta)
{
depthDelta = newDepthDelta;
testInvariant();
}

virtual size_t
size_t
getMaximumSegmentIndex() const
{
testInvariant();
return getNumPoints() - 1;
}

virtual EdgeIntersectionList&
EdgeIntersectionList&
getEdgeIntersectionList()
{
testInvariant();
return eiList;
}

const EdgeIntersectionList&
getEdgeIntersectionList() const
{
testInvariant();
return eiList;
}

/// \brief
/// Return this Edge's index::MonotoneChainEdge,
/// ownership is retained by this object.
///
virtual index::MonotoneChainEdge* getMonotoneChainEdge();
index::MonotoneChainEdge* getMonotoneChainEdge();

virtual bool
bool
isClosed() const
{
testInvariant();
Expand All @@ -187,11 +194,11 @@ class GEOS_DLL Edge: public GraphComponent {
* An Edge is collapsed if it is an Area edge and it consists of
* two segments which are equal and opposite (eg a zero-width V).
*/
virtual bool isCollapsed() const;
bool isCollapsed() const;

virtual Edge* getCollapsedEdge();
Edge* getCollapsedEdge();

virtual void
void
setIsolated(bool newIsIsolated)
{
isIsolatedVar = newIsIsolated;
Expand All @@ -209,15 +216,15 @@ class GEOS_DLL Edge: public GraphComponent {
* Adds EdgeIntersections for one or both
* intersections found for a segment of an edge to the edge intersection list.
*/
virtual void addIntersections(algorithm::LineIntersector* li, std::size_t segmentIndex,
void addIntersections(algorithm::LineIntersector* li, std::size_t segmentIndex,
std::size_t geomIndex);

/// Add an EdgeIntersection for intersection intIndex.
//
/// An intersection that falls exactly on a vertex of the edge is normalized
/// to use the higher of the two possible segmentIndexes
///
virtual void addIntersection(algorithm::LineIntersector* li, std::size_t segmentIndex,
void addIntersection(algorithm::LineIntersector* li, std::size_t segmentIndex,
std::size_t geomIndex, std::size_t intIndex);

/// Update the IM with the contribution for this component.
Expand All @@ -233,11 +240,11 @@ class GEOS_DLL Edge: public GraphComponent {
}

/// return true if the coordinate sequences of the Edges are identical
virtual bool isPointwiseEqual(const Edge* e) const;
bool isPointwiseEqual(const Edge* e) const;

virtual std::string print() const;
std::string print() const;

virtual std::string printReverse() const;
std::string printReverse() const;

/**
* equals is defined to be:
Expand All @@ -246,16 +253,16 @@ class GEOS_DLL Edge: public GraphComponent {
* <b>iff</b>
* the coordinates of e1 are the same or the reverse of the coordinates in e2
*/
virtual bool equals(const Edge& e) const;
bool equals(const Edge& e) const;

virtual bool
bool
equals(const Edge* e) const
{
assert(e);
return equals(*e);
}

virtual const geom::Envelope* getEnvelope();
const geom::Envelope* getEnvelope();
};


Expand Down
22 changes: 11 additions & 11 deletions include/geos/geomgraph/EdgeEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace geomgraph { // geos.geomgraph
* "a has a greater angle with the x-axis than b".
* This ordering is used to sort EdgeEnds around a node.
*/
class GEOS_DLL EdgeEnd {
class GEOS_DLL EdgeEnd /* non-final */ {

public:

Expand Down Expand Up @@ -101,7 +101,7 @@ class GEOS_DLL EdgeEnd {
return label;
}

virtual geom::Coordinate& getCoordinate() {
geom::Coordinate& getCoordinate() {
return p0;
}

Expand All @@ -111,19 +111,19 @@ class GEOS_DLL EdgeEnd {
return p0;
}

virtual geom::Coordinate& getDirectedCoordinate();
geom::Coordinate& getDirectedCoordinate();

virtual int getQuadrant();
int getQuadrant();

virtual double getDx();
double getDx();

virtual double getDy();
double getDy();

virtual void setNode(Node* newNode);
void setNode(Node* newNode);

virtual Node* getNode();
Node* getNode();

virtual int compareTo(const EdgeEnd* e) const;
int compareTo(const EdgeEnd* e) const;

/**
* Implements the total order relation:
Expand All @@ -141,7 +141,7 @@ class GEOS_DLL EdgeEnd {
* computeOrientation function can be used to decide
* the relative orientation of the vectors.
*/
virtual int compareDirection(const EdgeEnd* e) const;
int compareDirection(const EdgeEnd* e) const;

virtual void computeLabel(const algorithm::BoundaryNodeRule& bnr);

Expand All @@ -155,7 +155,7 @@ class GEOS_DLL EdgeEnd {

EdgeEnd(Edge* newEdge);

virtual void init(const geom::Coordinate& newP0,
void init(const geom::Coordinate& newP0,
const geom::Coordinate& newP1);

private:
Expand Down
36 changes: 18 additions & 18 deletions include/geos/geomgraph/EdgeEndStar.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace geomgraph { // geos.geomgraph
*
* @version 1.4
*/
class GEOS_DLL EdgeEndStar {
class GEOS_DLL EdgeEndStar /* non-final */ {
public:

typedef std::set<EdgeEnd*, EdgeEndLT> container;
Expand All @@ -86,46 +86,46 @@ class GEOS_DLL EdgeEndStar {
* a Coordinate owned by the specific EdgeEnd happening
* to be the first in the star (ordered CCW)
*/
virtual geom::Coordinate& getCoordinate();
geom::Coordinate& getCoordinate();

const geom::Coordinate& getCoordinate() const;

virtual std::size_t getDegree();
std::size_t getDegree();

virtual iterator begin();
iterator begin();

virtual iterator end();
iterator end();

virtual reverse_iterator rbegin();
reverse_iterator rbegin();

virtual reverse_iterator rend();
reverse_iterator rend();

virtual const_iterator
const_iterator
begin() const
{
return edgeMap.begin();
}

virtual const_iterator
const_iterator
end() const
{
return edgeMap.end();
}

virtual container& getEdges();
container& getEdges();

virtual EdgeEnd* getNextCW(EdgeEnd* ee);
EdgeEnd* getNextCW(EdgeEnd* ee);

virtual void computeLabelling(const std::vector<std::unique_ptr<GeometryGraph>>&geomGraph);
// throw(TopologyException *);

virtual bool isAreaLabelsConsistent(const GeometryGraph& geomGraph);
bool isAreaLabelsConsistent(const GeometryGraph& geomGraph);

virtual void propagateSideLabels(uint32_t geomIndex);
void propagateSideLabels(uint32_t geomIndex);
// throw(TopologyException *);

//virtual int findIndex(EdgeEnd *eSearch);
virtual iterator find(EdgeEnd* eSearch);
iterator find(EdgeEnd* eSearch);

virtual std::string print() const;

Expand All @@ -140,15 +140,15 @@ class GEOS_DLL EdgeEndStar {
/** \brief
* Insert an EdgeEnd into the map.
*/
virtual void
void
insertEdgeEnd(EdgeEnd* e)
{
edgeMap.insert(e);
}

private:

virtual geom::Location getLocation(uint32_t geomIndex,
geom::Location getLocation(uint32_t geomIndex,
const geom::Coordinate&p,
const std::vector<std::unique_ptr<GeometryGraph>>&geom);

Expand All @@ -158,9 +158,9 @@ class GEOS_DLL EdgeEndStar {
*/
std::array<geom::Location, 2> ptInAreaLocation;

virtual void computeEdgeEndLabels(const algorithm::BoundaryNodeRule&);
void computeEdgeEndLabels(const algorithm::BoundaryNodeRule&);

virtual bool checkAreaLabelsConsistent(uint32_t geomIndex);
bool checkAreaLabelsConsistent(uint32_t geomIndex);

};

Expand Down
2 changes: 1 addition & 1 deletion include/geos/geomgraph/EdgeIntersection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace geomgraph { // geos.geomgraph
* The intersection point must be precise.
*
*/
class GEOS_DLL EdgeIntersection {
class GEOS_DLL EdgeIntersection final {
public:

// the point of intersection
Expand Down
2 changes: 1 addition & 1 deletion include/geos/geomgraph/EdgeIntersectionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace geomgraph { // geos.geomgraph
* Implements splitting an edge with intersections
* into multiple resultant edges.
*/
class GEOS_DLL EdgeIntersectionList {
class GEOS_DLL EdgeIntersectionList final {
public:
// Instead of storing edge intersections in a set, as JTS does, we store them
// in a vector and then sort the vector if needed before iterating among the
Expand Down
4 changes: 2 additions & 2 deletions include/geos/geomgraph/EdgeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace geomgraph { // geos.geomgraph
* It supports locating edges
* that are pointwise equals to a target edge.
*/
class GEOS_DLL EdgeList {
class GEOS_DLL EdgeList final {

private:

Expand Down Expand Up @@ -85,7 +85,7 @@ class GEOS_DLL EdgeList {
ocaMap()
{}

virtual ~EdgeList() = default;
~EdgeList() = default;

/**
* Insert an edge unless it is already in the list
Expand Down
2 changes: 1 addition & 1 deletion include/geos/geomgraph/EdgeNodingValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace geomgraph { // geos.geomgraph
*
* Throws an appropriate exception if an noding error is found.
*/
class GEOS_DLL EdgeNodingValidator {
class GEOS_DLL EdgeNodingValidator final {

private:
std::vector<noding::SegmentString*>& toSegmentStrings(std::vector<Edge*>& edges);
Expand Down
2 changes: 1 addition & 1 deletion include/geos/geomgraph/EdgeRing.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace geos {
namespace geomgraph { // geos.geomgraph

/** EdgeRing */
class GEOS_DLL EdgeRing {
class GEOS_DLL EdgeRing /* non-final */ {

public:
friend std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
Expand Down
Loading

0 comments on commit 5ab1b4b

Please sign in to comment.