Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Lazy tentative to replace of auto_ptr with unique_ptr and move to c++14 #197

Merged
merged 2 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ if (CMAKE_CXX_COMPILER MATCHES ".*clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif ()

#-- C++ version --------------------------------------------
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
add_definitions("-std=c++98")
endif()

#-----------------------------------------------------------
# dependencies
#-----------------------------------------------------------
Expand All @@ -56,7 +51,7 @@ endif()

# 4.3 minimal
# 4.13 recommended
find_package( CGAL 4.3 COMPONENTS Core REQUIRED )
find_package( CGAL COMPONENTS Core REQUIRED )
message( STATUS "CGAL ${CGAL_VERSION} found" )

include_directories( ${CMAKE_BINARY_DIR}/include )
Expand Down
6 changes: 3 additions & 3 deletions example/SFCGAL-building/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ std::vector< InputData > readInputFile( const std::string & filename ){
void processFile( const std::string & filename ){
std::vector< InputData > data = readInputFile(filename);

std::auto_ptr< GeometryCollection > result( new GeometryCollection() );
std::unique_ptr< GeometryCollection > result( new GeometryCollection() );

std::cout << "#" << data.size() << std::endl;
for ( size_t i = 0; i < data.size(); i++ ){
std::auto_ptr< Geometry > g( io::readWkt( data[i].wkt ) );
std::auto_ptr< Geometry > building( generator::building( *g, data[i].wallHeight, data[i].roofSlope ) ) ;
std::unique_ptr< Geometry > g( io::readWkt( data[i].wkt ) );
std::unique_ptr< Geometry > building( generator::building( *g, data[i].wallHeight, data[i].roofSlope ) ) ;
result->addGeometry( building.release() );
}

Expand Down
6 changes: 3 additions & 3 deletions example/SFCGAL-export-osg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace SFCGAL ;

int main(){
detail::io::OsgFactory factory ;
std::auto_ptr< Geometry > g( io::readWkt("MULTILINESTRING((-2.705287 -6.782348, -2.052957 -4.368728, -0.356900 -3.912097, 0.980376 -4.857975, 1.339158 -5.966935, 0.328047 -7.043280, -1.987724 -8.706720, -1.922491 -10.076613, -1.726792 -11.087724, 0.882527 -12.457616, 3.491846 -12.490233, 4.242025 -11.120341, 3.720161 -9.489516, 2.480735 -9.098118, -0.519982 -9.130735, -0.291667 -8.413172, 0.915143 -7.075896, 1.958871 -6.619265, 3.883244 -6.358333, 5.677151 -6.651882, 6.231631 -7.238978, 6.329480 -8.413172, 5.481452 -9.326434, 4.829122 -9.717832, 4.698656 -10.207079, 4.861738 -10.826792, 5.350986 -11.381272, 6.329480 -11.479122, 8.514785 -11.479122, 10.112993 -11.022491, 10.700090 -10.533244, 12.265681 -8.967652, 12.493996 -7.858692, 12.526613 -7.108513, 12.233065 -5.999552, 10.765323 -5.412455, 8.319086 -5.249373, 6.133781 -5.184140, 5.057437 -5.021057, 4.926971 -4.401344, 5.253136 -3.814247, 6.786111 -3.422849, 7.699373 -3.879480, 8.090771 -4.531810, 8.938799 -4.629659, 11.156720 -4.597043, 11.287186 -3.031452, 13.766039 -0.487366, 17.908333 -0.389516, 20.615502 -4.075179, 18.267115 -10.598477, 26.975717 -13.109946))") );
std::unique_ptr< Geometry > g( io::readWkt("MULTILINESTRING((-2.705287 -6.782348, -2.052957 -4.368728, -0.356900 -3.912097, 0.980376 -4.857975, 1.339158 -5.966935, 0.328047 -7.043280, -1.987724 -8.706720, -1.922491 -10.076613, -1.726792 -11.087724, 0.882527 -12.457616, 3.491846 -12.490233, 4.242025 -11.120341, 3.720161 -9.489516, 2.480735 -9.098118, -0.519982 -9.130735, -0.291667 -8.413172, 0.915143 -7.075896, 1.958871 -6.619265, 3.883244 -6.358333, 5.677151 -6.651882, 6.231631 -7.238978, 6.329480 -8.413172, 5.481452 -9.326434, 4.829122 -9.717832, 4.698656 -10.207079, 4.861738 -10.826792, 5.350986 -11.381272, 6.329480 -11.479122, 8.514785 -11.479122, 10.112993 -11.022491, 10.700090 -10.533244, 12.265681 -8.967652, 12.493996 -7.858692, 12.526613 -7.108513, 12.233065 -5.999552, 10.765323 -5.412455, 8.319086 -5.249373, 6.133781 -5.184140, 5.057437 -5.021057, 4.926971 -4.401344, 5.253136 -3.814247, 6.786111 -3.422849, 7.699373 -3.879480, 8.090771 -4.531810, 8.938799 -4.629659, 11.156720 -4.597043, 11.287186 -3.031452, 13.766039 -0.487366, 17.908333 -0.389516, 20.615502 -4.075179, 18.267115 -10.598477, 26.975717 -13.109946))") );

osg::ref_ptr< osg::Group > root = new osg::Group ;

Expand All @@ -56,10 +56,10 @@ int main(){
//buffer & extrude
{
double radius = 0.7 ;
std::auto_ptr< MultiPolygon > buffer( algorithm::offset( *g, radius ) );
std::unique_ptr< MultiPolygon > buffer( algorithm::offset( *g, radius ) );
algorithm::translate( *buffer, Kernel::Vector_3( 0.0, 0.0, radius ) );

std::auto_ptr< Geometry > extruded( algorithm::extrude(*buffer,3.0,3.0,3.0) );
std::unique_ptr< Geometry > extruded( algorithm::extrude(*buffer,3.0,3.0,3.0) );

osg::Geometry * osgGeometry = factory.createGeometry( *extruded );
osg::Geode* geode = new osg::Geode;
Expand Down
4 changes: 2 additions & 2 deletions example/SFCGAL-offset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
using namespace SFCGAL ;

int main(){
std::auto_ptr< Geometry > g( io::readWkt("MULTIPOINT(0 0,5 6,3 2,7 1,4 1,3 5,2 9)") );
std::unique_ptr< Geometry > g( io::readWkt("MULTIPOINT(0 0,5 6,3 2,7 1,4 1,3 5,2 9)") );

for ( size_t i = 1; i <= 50; i++ ){
std::auto_ptr< Geometry > buffer( algorithm::offset( *g, 0.2*i ) );
std::unique_ptr< Geometry > buffer( algorithm::offset( *g, 0.2*i ) );
std::cout << buffer->asText(5) << std::endl ;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ bool Envelope::overlaps( const Envelope& a, const Envelope& b )
///
///
///
std::auto_ptr< LineString > Envelope::toRing() const
std::unique_ptr< LineString > Envelope::toRing() const
{
std::auto_ptr< LineString > ring( new LineString() ) ;
std::unique_ptr< LineString > ring( new LineString() ) ;

if ( isEmpty() ) {
return ring ;
Expand All @@ -201,18 +201,18 @@ std::auto_ptr< LineString > Envelope::toRing() const
///
///
///
std::auto_ptr< Polygon > Envelope::toPolygon() const
std::unique_ptr< Polygon > Envelope::toPolygon() const
{
return std::auto_ptr< Polygon >( new Polygon( toRing().release() ) ) ;
return std::unique_ptr< Polygon >( new Polygon( toRing().release() ) ) ;
}


///
///
///
std::auto_ptr< PolyhedralSurface > Envelope::toShell() const
std::unique_ptr< PolyhedralSurface > Envelope::toShell() const
{
std::auto_ptr< PolyhedralSurface > shell( new PolyhedralSurface() ) ;
std::unique_ptr< PolyhedralSurface > shell( new PolyhedralSurface() ) ;

if ( ! is3D() ) {
return shell ;
Expand Down Expand Up @@ -306,9 +306,9 @@ std::auto_ptr< PolyhedralSurface > Envelope::toShell() const
///
///
///
std::auto_ptr< Solid > Envelope::toSolid() const
std::unique_ptr< Solid > Envelope::toSolid() const
{
return std::auto_ptr< Solid >(
return std::unique_ptr< Solid >(
new Solid( toShell().release() )
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Envelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,23 @@ class SFCGAL_API Envelope {
* @brief convenience method to convert to 2D Polygon ring
* @warning empty LineString for empty Envelope, may be X or Y collapsed
*/
std::auto_ptr< LineString > toRing() const ;
std::unique_ptr< LineString > toRing() const ;
/**
* @brief convenience method to convert to 2D Polygon
* @warning empty Polygon for empty Envelope, may be X or Y collapsed
*/
std::auto_ptr< Polygon > toPolygon() const ;
std::unique_ptr< Polygon > toPolygon() const ;

/**
* @brief convenience method to convert to 3D Shell
* @warning empty Solid for empty or non 3D Envelope, may be X, Y or Z collapsed
*/
std::auto_ptr< PolyhedralSurface > toShell() const ;
std::unique_ptr< PolyhedralSurface > toShell() const ;
/**
* @brief convenience method to convert to 3D Solid
* @warning empty Solid for empty or non 3D Envelope, may be X, Y or Z collapsed
*/
std::auto_ptr< Solid > toSolid() const ;
std::unique_ptr< Solid > toSolid() const ;


/*
Expand Down
4 changes: 2 additions & 2 deletions src/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Envelope Geometry::envelope() const
///
///
///
std::auto_ptr< Geometry > Geometry::boundary() const
std::unique_ptr< Geometry > Geometry::boundary() const
{
algorithm::BoundaryVisitor visitor ;
accept( visitor );
return std::auto_ptr< Geometry >( visitor.releaseBoundary() ) ;
return std::unique_ptr< Geometry >( visitor.releaseBoundary() ) ;
}


Expand Down
4 changes: 2 additions & 2 deletions src/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ class SFCGAL_API Geometry {
* @todo In order to adapt to 3D, would be better to define an "Envelope type",
* otherway would lead to Polygon and PolyhedralSurface
*/
//std::auto_ptr< Geometry > envelope() const = 0 ;
//std::unique_ptr< Geometry > envelope() const = 0 ;
Envelope envelope() const ;

/**
* @brief [OGC/SFA]Returns the boundary of the geometry
*/
virtual std::auto_ptr< Geometry > boundary() const ;
virtual std::unique_ptr< Geometry > boundary() const ;

/**
* @brief Computes the distance to an other geometry
Expand Down
2 changes: 1 addition & 1 deletion src/PolyhedralSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SFCGAL_API PolyhedralSurface : public Surface {
* Convert to CGAL::Polyhedron_3
*/
template < typename K, typename Polyhedron >
std::auto_ptr<Polyhedron> toPolyhedron_3() const {
std::unique_ptr<Polyhedron> toPolyhedron_3() const {
TriangulatedSurface tri;
triangulate::triangulatePolygon3D( *this, tri );
return tri.toPolyhedron_3<K, Polyhedron>();
Expand Down
4 changes: 2 additions & 2 deletions src/PreparedGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ PreparedGeometry::PreparedGeometry() :
{
}

PreparedGeometry::PreparedGeometry( std::auto_ptr<Geometry> geometry, srid_t srid ) :
_geometry( geometry ),
PreparedGeometry::PreparedGeometry( std::unique_ptr<Geometry>&& geometry, srid_t srid ) :
_geometry( geometry.release() ),
Copy link

@lrineau lrineau Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a function claims ownership of a pointer, the unique_ptr is best taken by value:

PreparedGeometry::PreparedGeometry( std::unique_ptr<Geometry> geometry, srid_t srid ) 
    _geometry( std::move(geometry) ),

For a long explanation, you can read https://stackoverflow.com/a/8114913/1728537.

The semantic of void f(std::unique_ptr<Geometry>&& geometry) is that f may take the ownership.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, passing rvalue references of unique_ptr seems very confusing to me.

_srid( srid )
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/PreparedGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef uint32_t srid_t;
* A PreparedGeometry is a shell around a SFCGAL::Geometry.
* It is used to store annex data, like SRID or cached computations
*
* It is noncopyable since it stores a std::auto_ptr<SFCGAL::Geometry>
* It is noncopyable since it stores a std::unique_ptr<SFCGAL::Geometry>
*
*/
class SFCGAL_API PreparedGeometry : public boost::noncopyable {
Expand All @@ -55,7 +55,7 @@ class SFCGAL_API PreparedGeometry : public boost::noncopyable {
* Constructor
* @param geometry pointer to the underlying SFCGAL::Geometry. Takes ownership
*/
PreparedGeometry( std::auto_ptr<Geometry> geometry, srid_t srid = 0 );
PreparedGeometry( std::unique_ptr<Geometry>&& geometry, srid_t srid = 0 );

/**
* Constructor
Expand Down Expand Up @@ -131,7 +131,7 @@ class SFCGAL_API PreparedGeometry : public boost::noncopyable {

protected:
// Pointer to underlying Geometry
std::auto_ptr<Geometry> _geometry;
std::unique_ptr<Geometry> _geometry;

// SRID of the geometry
srid_t _srid;
Expand Down
8 changes: 4 additions & 4 deletions src/TriangulatedSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ struct Plane_from_facet {
};

template < typename K, typename Polyhedron >
std::auto_ptr<Polyhedron> TriangulatedSurface::toPolyhedron_3() const
std::unique_ptr<Polyhedron> TriangulatedSurface::toPolyhedron_3() const
{
Polyhedron* poly = new Polyhedron();
Triangulated2Polyhedron<typename Polyhedron::HalfedgeDS> converter( *this );
Expand All @@ -298,11 +298,11 @@ std::auto_ptr<Polyhedron> TriangulatedSurface::toPolyhedron_3() const
// compute planes
std::transform( poly->facets_begin(), poly->facets_end(), poly->planes_begin(), Plane_from_facet<Polyhedron>() );

return std::auto_ptr<Polyhedron>( poly );
return std::unique_ptr<Polyhedron>( poly );
}

template SFCGAL_API std::auto_ptr< detail::MarkedPolyhedron > TriangulatedSurface::toPolyhedron_3<Kernel, detail::MarkedPolyhedron >() const;
template SFCGAL_API std::auto_ptr< CGAL::Polyhedron_3<Kernel> > TriangulatedSurface::toPolyhedron_3<Kernel, CGAL::Polyhedron_3<Kernel> >() const;
template SFCGAL_API std::unique_ptr< detail::MarkedPolyhedron > TriangulatedSurface::toPolyhedron_3<Kernel, detail::MarkedPolyhedron >() const;
template SFCGAL_API std::unique_ptr< CGAL::Polyhedron_3<Kernel> > TriangulatedSurface::toPolyhedron_3<Kernel, CGAL::Polyhedron_3<Kernel> >() const;

}//SFCGAL

Expand Down
2 changes: 1 addition & 1 deletion src/TriangulatedSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class SFCGAL_API TriangulatedSurface : public Surface {
* @brief Converts a TriangulatedSurface to a CGAL::Polyhedron_3
*/
template < typename K, typename Polyhedron >
std::auto_ptr<Polyhedron> toPolyhedron_3() const;
std::unique_ptr<Polyhedron> toPolyhedron_3() const;

/**
* Serializer
Expand Down
10 changes: 5 additions & 5 deletions src/algorithm/BoundaryVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void BoundaryVisitor::visit( const LineString& g )
_boundary.reset() ;
}
else {
std::auto_ptr< MultiPoint > boundary( new MultiPoint );
std::unique_ptr< MultiPoint > boundary( new MultiPoint );
boundary->addGeometry( g.startPoint() );
boundary->addGeometry( g.endPoint() );
_boundary.reset( boundary.release() );
Expand All @@ -83,7 +83,7 @@ void BoundaryVisitor::visit( const Polygon& g )
_boundary.reset( g.exteriorRing().clone() );
}
else {
std::auto_ptr< MultiLineString > boundary( new MultiLineString );
std::unique_ptr< MultiLineString > boundary( new MultiLineString );

for ( size_t i = 0; i < g.numRings(); i++ ) {
boundary->addGeometry( g.ringN( i ) );
Expand All @@ -103,7 +103,7 @@ void BoundaryVisitor::visit( const Triangle& g )
return ;
}

std::auto_ptr< LineString > boundary( new LineString );
std::unique_ptr< LineString > boundary( new LineString );

for ( size_t i = 0; i < 4; i++ ) {
boundary->addPoint( g.vertex( i ) );
Expand Down Expand Up @@ -255,7 +255,7 @@ void BoundaryVisitor::getBoundaryFromLineStrings( const graph::GeometryGraph& gr
_boundary.reset( new Point( graph[ vertices[0] ].coordinate ) );
}
else {
std::auto_ptr< MultiPoint > boundary( new MultiPoint );
std::unique_ptr< MultiPoint > boundary( new MultiPoint );

for ( size_t i = 0; i < vertices.size(); i++ ) {
boundary->addGeometry( new Point( graph[ vertices[i] ].coordinate ) ) ;
Expand Down Expand Up @@ -292,7 +292,7 @@ void BoundaryVisitor::getBoundaryFromPolygons( const graph::GeometryGraph& g )
}
else {
//TODO merge Line Segments into LineString
std::auto_ptr< MultiLineString > boundary( new MultiLineString );
std::unique_ptr< MultiLineString > boundary( new MultiLineString );

for ( size_t i = 0; i < boundaryEdges.size(); i++ ) {
const edge_descriptor& edge = boundaryEdges[i] ;
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/BoundaryVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SFCGAL_API BoundaryVisitor : public ConstGeometryVisitor {
void getBoundaryFromPolygons( const graph::GeometryGraph& g );

private:
std::auto_ptr< Geometry > _boundary ;
std::unique_ptr< Geometry > _boundary ;
};


Expand Down
12 changes: 6 additions & 6 deletions src/algorithm/collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,40 @@

namespace SFCGAL {
namespace algorithm {
std::auto_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb )
std::unique_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb )
{
if ( ga.geometryTypeId() == gb.geometryTypeId() ) {
if ( ga.geometryTypeId() == TYPE_POINT ) {
MultiPoint* mp = new MultiPoint;
mp->addGeometry( ga );
mp->addGeometry( gb );
return std::auto_ptr<Geometry>( mp );
return std::unique_ptr<Geometry>( mp );
}
else if ( ga.geometryTypeId() == TYPE_LINESTRING ) {
MultiLineString* mls = new MultiLineString();
mls->addGeometry( ga );
mls->addGeometry( gb );
return std::auto_ptr<Geometry>( mls );
return std::unique_ptr<Geometry>( mls );
}
else if ( ga.geometryTypeId() == TYPE_POLYGON ) {
MultiPolygon* mp = new MultiPolygon();
mp->addGeometry( ga );
mp->addGeometry( gb );
return std::auto_ptr<Geometry>( mp );
return std::unique_ptr<Geometry>( mp );
}
else if ( ga.geometryTypeId() == TYPE_SOLID ) {
MultiSolid* mp = new MultiSolid();
mp->addGeometry( ga );
mp->addGeometry( gb );
return std::auto_ptr<Geometry>( mp );
return std::unique_ptr<Geometry>( mp );
}
}

// else
GeometryCollection* coll = new GeometryCollection();
coll->addGeometry( ga );
coll->addGeometry( gb );
return std::auto_ptr<Geometry>( coll );
return std::unique_ptr<Geometry>( coll );
}
}
}
6 changes: 3 additions & 3 deletions src/algorithm/collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ namespace algorithm {
* Returns an aggregate of ga and gb
* @ingroup detail
*/
SFCGAL_API std::auto_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb );
SFCGAL_API std::unique_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb );

/**
* Returns an aggregate of a list of geometries
* @ingroup detail
*/
template <typename GeometryIterator>
std::auto_ptr<Geometry> collect( GeometryIterator begin, GeometryIterator end )
std::unique_ptr<Geometry> collect( GeometryIterator begin, GeometryIterator end )
{
GeometryIterator it;
// FIXME: optimize type. For instance, if all the given geometries are points, return a MultiPoint instead of a GeometryCollection
Expand All @@ -49,7 +49,7 @@ std::auto_ptr<Geometry> collect( GeometryIterator begin, GeometryIterator end )
coll->addGeometry( *it );
}

return std::auto_ptr<Geometry>( coll );
return std::unique_ptr<Geometry>( coll );
}
}
}
Expand Down
Loading