34#include "DGtal/base/Common.h"
35#include "DGtal/base/Clone.h"
36#include "DGtal/base/Alias.h"
37#include "DGtal/base/ConstAlias.h"
38#include "DGtal/helpers/StdDefs.h"
51 std::cout <<
" ~A1() " << std::endl;
54 A1(
int i ) : data( i )
56 std::cout <<
" A1( int i ) " << std::endl;
59 A1(
const A1 & a ) : data( a.data )
61 std::cout <<
" A1( const A1 & a ) " << std::endl;
64 A1& operator=(
const A1 & a )
67 std::cout <<
" A1::operator=( const A1 & a ) " << std::endl;
90 std::cout <<
" DByValue( A1 a) " << std::endl;
107 std::cout <<
" DByClone( Clone<A1> a) " << std::endl;
124 std::cout <<
" EByAlias( Alias<A1> a ) " << myA1 << std::endl;
137struct EByConstAlias {
141 std::cout <<
" EByConstAlias( Alias<A1> a ) " << myA1 << std::endl;
156 MyPoint(
const MyPoint & other )
157 : _x( other._x ), _y( other._y )
159 MyPoint(
int x,
int y ) : _x( x ), _y( y )
161 MyPoint
operator-(
const MyPoint & other )
const
163 return MyPoint( _x - other._x, _y - other._y );
167 double dx = (double) _x;
168 double dy = (double) _y;
169 return sqrt( dx * dx + dy * dy );
173 nbCreated = nbDeleted = 0;
177 static int nbCreated;
178 static int nbDeleted;
181int MyPoint::nbCreated = 0;
182int MyPoint::nbDeleted = 0;
187struct TriangleByConstReference {
188 TriangleByConstReference(
const Point & a,
const Point & b,
const Point & c )
189 : _a( a ), _b( b ), _c( c ) {}
190 double perimeter()
const
192 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
197struct TriangleByValue {
199 : _a( a ), _b( b ), _c( c ) {}
200 double perimeter()
const
202 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
207struct TriangleByClone {
209 : _a( a ), _b( b ), _c( c ) {}
210 double perimeter()
const
212 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
217template <
typename Triangle>
223 for (
int yb = 0; yb < size; ++yb )
224 for (
int xb = 0; xb < size; ++xb )
227 for (
int yc = 0; yc < size; ++yc )
228 for (
int xc = 0; xc < size; ++xc )
232 total += T.perimeter();
242 std::cout <<
" FByCloneHeap( Clone<A1> a ) " << myA1 << std::endl;
245 ~FByCloneHeap() {
if ( myA1 != 0 )
delete myA1; }
255struct FByCloneCowPtr {
259 std::cout <<
" FByCloneCowPtr( Clone<A1> a ) " << myA1 << std::endl;
275 unsigned int nbok = 0;
276 trace.
beginBlock (
"Number of A1 instances with standard by-value parameter passing." );
279 trace.
info() <<
"D: d1.value() = " << d1.value() << std::endl;
280 ++nb; nbok += A1::nbCreated==3 ? 1 : 0;
281 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
282 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
283 <<
" nbCreated=" << A1::nbCreated
284 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
286 trace.
beginBlock (
"Number of A1 instances with explicit by-value parameter passing (Clone)." );
288 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
289 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
290 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
291 <<
" nbCreated=" << A1::nbCreated
292 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
294 trace.
beginBlock (
"Number of A1 instances with explicit by-reference parameter passing (Alias)." );
296 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
297 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
298 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
299 <<
" nbCreated=" << A1::nbCreated
300 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
302 trace.
beginBlock (
"Number of A1 instances with explicit by-const reference parameter passing (Alias)." );
303 EByConstAlias ee1( a1 );
304 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
305 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
306 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
307 <<
" nbCreated=" << A1::nbCreated
308 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
310 trace.
beginBlock (
"Number of A1 instances with explicit by-value parameter passing into heap (Clone)." );
311 FByCloneHeap fe1( a1 );
312 ++nb; nbok += A1::nbCreated==5 ? 1 : 0;
313 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
314 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
315 <<
" nbCreated=" << A1::nbCreated
316 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
318 trace.
beginBlock (
"Number of A1 instances with explicit by-value parameter passing into CowPtr (Clone)." );
319 FByCloneCowPtr fe3( a1 );
320 ++nb; nbok += A1::nbCreated==6 ? 1 : 0;
321 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
322 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
323 <<
" nbCreated=" << A1::nbCreated
324 <<
" nbDeleted=" << A1::nbDeleted << std::endl;
328 trace.
beginBlock (
"Total perimeter of triangles with by-value parameter passing." );
329 double t1 = computeTriangles<TriangleByValue>( size );
330 trace.
info() <<
"Perimeter is " << t1 << std::endl;
331 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
332 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
333 <<
" Point nbCreated=" << Point::nbCreated
334 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
335 int nbC = Point::nbCreated;
338 trace.
beginBlock (
"Total perimeter of triangles with by-const reference parameter passing." );
339 double t2 = computeTriangles<TriangleByConstReference>( size );
340 trace.
info() <<
"Perimeter is " << t2 << std::endl;
341 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
342 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
343 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
344 <<
" Point nbCreated=" << Point::nbCreated
345 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
348 trace.
beginBlock (
"Total perimeter of triangles with by Clone parameter passing." );
349 double t3 = computeTriangles<TriangleByClone>( size );
350 trace.
info() <<
"Perimeter is " << t3 << std::endl;
351 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
352 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
353 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
354 <<
" Point nbCreated=" << Point::nbCreated
355 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
363 return ( nb == nbok ) ? 0 : 1;
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Aim: Copy on write shared pointer.
void beginBlock(const std::string &keyword="")
Container operator-(const Container &S1, const Container &S2)
DGtal is the top-level namespace which contains all DGtal functions and types.
Represents an unoriented triangle as three vertices.
double computeTriangles(int size)