34 #include "DGtal/base/Common.h"
35 #include "DGtal/base/CountedPtr.h"
36 #include "DGtal/base/CountedPtrOrPtr.h"
37 #include "DGtal/base/CountedConstPtrOrConstPtr.h"
38 #include "DGtal/base/CowPtr.h"
39 #include "DGtal/base/Clone.h"
40 #include "DGtal/base/Alias.h"
41 #include "DGtal/base/ConstAlias.h"
42 #include "DGtal/helpers/StdDefs.h"
44 using namespace DGtal;
75 inline NClone (
const NClone & ) { ASSERT(
false ); }
83 inline NClone(
const T & t ) : myCowPtr( const_cast<T*>( &t ) ) {}
95 inline NClone(
CowPtr<T> ptr ) : myCowPtr( ptr ) {}
102 inline operator T()
const
103 {
return myCowPtr.unique()
104 ? T( *(
const_cast< CowPtr<T>&
>( myCowPtr ).drop() ) )
105 : T( *( myCowPtr.get() ) );
115 {
return myCowPtr.
unique()
147 NClone & operator= (
const NClone & other );
167 std::cout <<
" ~DummyTbl() this=" <<
this <<
" data=" << data << std::endl;
169 std::cout <<
" - freed =" << allocated << std::endl;
173 std::cout <<
" - nothing to do (already moved)" << std::endl;
176 DummyTbl(
int i,
int val )
177 : size( 0 ), allocated( i )
179 std::cout <<
" DummyTbl( " << i <<
" ) this=" <<
this << std::endl;
180 data =
new Element[ allocated ];
181 data[ size++ ] = val;
182 std::cout <<
" - allocated=" << allocated << std::endl;
183 std::cout <<
" - copied =" << size << std::endl;
186 DummyTbl(
const DummyTbl & a ) : size( a.size ), allocated( a.allocated )
188 std::cout <<
" DummyTbl( const DummyTbl & a ) this=" <<
this <<
" a=" << &a << std::endl;
189 data =
new Element[ allocated ];
190 for (
int i = 0; i < size; ++i ) data[ i ] = a.data[ i ];
191 std::cout <<
" - allocated=" << allocated << std::endl;
192 std::cout <<
" - copied =" << size << std::endl;
196 DummyTbl( DummyTbl && a ) noexcept
197 : size( std::move( a.size ) ), allocated( std::move( a.allocated ) )
199 data = a.data; a.data = 0;
200 std::cout <<
" DummyTbl( DummyTbl && a ) this=" <<
this <<
" a=" << &a << std::endl;
201 std::cout <<
" - check data: a=" << allocated <<
" s=" << size << std::endl;
206 int value()
const {
return data[ 0 ]; }
207 void setValue(
int v )
const { data[ 0 ] = v; }
210 DummyTbl& operator=(
const DummyTbl & a )
213 std::cout <<
" DummyTbl::operator=( const DummyTbl & a ) " << std::endl;
217 static void reset() {
226 static int nbCreated;
227 static int nbDeleted;
231 int DummyTbl::nbCreated = 0;
232 int DummyTbl::nbDeleted = 0;
233 int DummyTbl::nbMoved = 0;
236 struct CloneToValueMember {
238 inline int value()
const {
return myDummyTbl.value(); }
242 struct CloneToCountedMember {
244 : myDummyTbl( a1 ) {}
245 inline int value()
const {
return myDummyTbl->value(); }
249 struct CloneToCowMember {
251 inline int value()
const {
return myDummyTbl->value(); }
252 inline void setValue(
int v ) { myDummyTbl->setValue( v ); }
256 struct CloneToPtrMember {
257 inline CloneToPtrMember() : myDummyTbl( 0 ) {}
259 inline ~CloneToPtrMember() {
if ( myDummyTbl != 0 )
delete myDummyTbl;
else std::cerr <<
"[~CloneToPtrMember] error." << std::endl; }
260 inline int value()
const {
return myDummyTbl->value(); }
261 inline void setValue(
int v ) { myDummyTbl->setValue( v ); }
262 DummyTbl* myDummyTbl;
265 struct AliasToRefMember {
267 inline int value()
const {
return myDummyTbl.value(); }
268 DummyTbl& myDummyTbl;
271 struct AliasToPtrMember {
273 inline int value()
const {
return myDummyTbl->value(); }
274 DummyTbl* myDummyTbl;
278 struct AliasToCountedPtrOrPtrMember {
279 inline AliasToCountedPtrOrPtrMember(
Alias<DummyTbl> a1 ) : myDummyTbl( a1 ) {}
280 inline int value()
const {
return myDummyTbl->value(); }
284 struct AliasToConstRefMember {
285 inline AliasToConstRefMember(
Alias<DummyTbl> a1 ) : myDummyTbl( a1 ) {}
286 inline int value()
const {
return myDummyTbl.value(); }
287 const DummyTbl& myDummyTbl;
290 struct ConstAliasToConstRefMember {
292 inline int value()
const {
return myDummyTbl.value(); }
293 const DummyTbl& myDummyTbl;
296 struct ConstAliasToConstPtrMember {
298 inline int value()
const {
return myDummyTbl->value(); }
299 const DummyTbl* myDummyTbl;
302 struct ConstAliasToCountedConstPtrOrConstPtrMember {
303 inline ConstAliasToCountedConstPtrOrConstPtrMember(
ConstAlias<DummyTbl> a1 ) : myDummyTbl( a1 ) {}
304 inline int value()
const {
return myDummyTbl->value(); }
320 MyPoint(
const MyPoint & other )
321 : _x( other._x ), _y( other._y )
323 MyPoint(
int x,
int y ) : _x( x ), _y( y )
325 MyPoint
operator-(
const MyPoint & other )
const
327 return MyPoint( _x - other._x, _y - other._y );
331 double dx = (double) _x;
332 double dy = (double) _y;
333 return sqrt( dx * dx + dy * dy );
337 nbCreated = nbDeleted = 0;
341 static int nbCreated;
342 static int nbDeleted;
345 int MyPoint::nbCreated = 0;
346 int MyPoint::nbDeleted = 0;
352 MyPointD(
const MyPointD & other )
353 : _x( other._x ), _y( other._y )
355 MyPointD(
int x,
int y ) : _x( x ), _y( y )
357 MyPointD(
double x,
double y ) : _x( x ), _y( y )
359 MyPointD
operator-(
const MyPointD & other )
const
361 return MyPointD( _x - other._x, _y - other._y );
365 double dx = (double) _x;
366 double dy = (double) _y;
367 return sqrt( dx * dx + dy * dy );
371 nbCreated = nbDeleted = 0;
375 static int nbCreated;
376 static int nbDeleted;
379 int MyPointD::nbCreated = 0;
380 int MyPointD::nbDeleted = 0;
386 struct TriangleByConstReference {
387 TriangleByConstReference(
const Point & a,
const Point & b,
const Point & c )
388 : _a( a ), _b( b ), _c( c ) {}
389 double perimeter()
const
391 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
396 struct TriangleByValue {
398 : _a( a ), _b( b ), _c( c ) {}
399 double perimeter()
const
401 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
406 struct TriangleByClone {
408 : _a( a ), _b( b ), _c( c ) {}
409 double perimeter()
const
411 return (_a - _b).norm() + (_b - _c).norm() + (_c - _a).norm();
416 struct TriangleByCloneAndCow {
418 : _a( a ), _b( b ), _c( c ) {}
419 double perimeter()
const
421 return (*_a - *_b).norm() + (*_b - *_c).norm() + (*_c - *_a).norm();
426 template <
typename Triangle>
432 for (
int yb = 0; yb < size; ++yb )
433 for (
int xb = 0; xb < size; ++xb )
436 for (
int yc = 0; yc < size; ++yc )
437 for (
int xc = 0; xc < size; ++xc )
441 total += T.perimeter();
447 template <
typename Triangle>
453 for (
int yb = 0; yb < size; ++yb )
454 for (
int xb = 0; xb < size; ++xb )
457 for (
int yc = 0; yc < size; ++yc )
458 for (
int xc = 0; xc < size; ++xc )
462 total += T.perimeter();
480 unsigned int nbok = 0;
481 DummyTbl a1( 100, 10 );
482 DummyTbl* ptr_a2 =
new DummyTbl( 100, 18 );
494 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl& to DummyTbl& member. no duplication (0/0)" );
495 AliasToRefMember c00( a1 );
496 trace.
info() <<
"D: d1.value() = " << c00.value() << std::endl;
497 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
498 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
499 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
500 <<
" nbCreated=" << DummyTbl::nbCreated
501 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
504 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl* to DummyTbl& member. no duplication (0/0)" );
505 AliasToRefMember c10( ptr_a2 );
506 trace.
info() <<
"D: d1.value() = " << c10.value() << std::endl;
507 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
508 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
509 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
510 <<
" nbCreated=" << DummyTbl::nbCreated
511 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
514 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl& to DummyTbl* member. no duplication (0/0)" );
515 AliasToPtrMember c01( a1 );
516 trace.
info() <<
"D: d1.value() = " << c01.value() << std::endl;
517 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
518 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
519 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
520 <<
" nbCreated=" << DummyTbl::nbCreated
521 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
524 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl* to DummyTbl* member. no duplication (0/0)" );
525 AliasToPtrMember c11( ptr_a2 );
526 trace.
info() <<
"D: d1.value() = " << c11.value() << std::endl;
527 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
528 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
529 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
530 <<
" nbCreated=" << DummyTbl::nbCreated
531 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
534 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl& to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
535 AliasToCountedPtrOrPtrMember c06( a1 );
536 trace.
info() <<
"D: d1.value() = " << c06.value() << std::endl;
537 trace.
info() << c06.myDummyTbl << std::endl;
538 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
539 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
540 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
541 <<
" nbCreated=" << DummyTbl::nbCreated
542 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
545 trace.
beginBlock (
"Alias: #DummyTbl with DummyTbl* to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
546 AliasToCountedPtrOrPtrMember c16( a1 );
547 trace.
info() <<
"D: d1.value() = " << c16.value() << std::endl;
548 trace.
info() << c16.myDummyTbl << std::endl;
549 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
550 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
551 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
552 <<
" nbCreated=" << DummyTbl::nbCreated
553 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
579 unsigned int nbok = 0;
580 DummyTbl a1( 100, 10 );
581 DummyTbl* ptr_a2 =
new DummyTbl( 100, 18 );
595 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl& member. no duplication (0/0)" );
596 ConstAliasToConstRefMember c00( a1 );
597 trace.
info() <<
"D: d1.value() = " << c00.value() << std::endl;
598 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
599 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
600 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
601 <<
" nbCreated=" << DummyTbl::nbCreated
602 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
605 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl& member. no duplication (0/0)" );
606 ConstAliasToConstRefMember c10( ptr_a2 );
607 trace.
info() <<
"D: d1.value() = " << c10.value() << std::endl;
608 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
609 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
610 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
611 <<
" nbCreated=" << DummyTbl::nbCreated
612 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
615 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl* member. no duplication (0/0)" );
616 ConstAliasToConstPtrMember c01( a1 );
617 trace.
info() <<
"D: d1.value() = " << c01.value() << std::endl;
618 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
619 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
620 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
621 <<
" nbCreated=" << DummyTbl::nbCreated
622 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
625 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl* member. no duplication (0/0)" );
626 ConstAliasToConstPtrMember c11( ptr_a2 );
627 trace.
info() <<
"D: d1.value() = " << c11.value() << std::endl;
628 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
629 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
630 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
631 <<
" nbCreated=" << DummyTbl::nbCreated
632 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
635 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
636 ConstAliasToCountedConstPtrOrConstPtrMember c17( ptr_a2 );
637 trace.
info() <<
"D: d1.value() = " << c17.value() << std::endl;
638 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
639 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
640 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
641 <<
" nbCreated=" << DummyTbl::nbCreated
642 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
645 trace.
beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
646 ConstAliasToCountedConstPtrOrConstPtrMember c07( a1 );
647 trace.
info() <<
"D: d1.value() = " << c07.value() << std::endl;
648 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
649 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
650 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
651 <<
" nbCreated=" << DummyTbl::nbCreated
652 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
655 trace.
beginBlock (
"ConstAlias: #DummyTbl with CountedPtr<DummyTbl> to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
656 ConstAliasToCountedConstPtrOrConstPtrMember c37( counted_a1 );
657 trace.
info() <<
"D: d1.value() = " << c37.value() << std::endl;
658 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
659 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
660 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
661 <<
" nbCreated=" << DummyTbl::nbCreated
662 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
696 unsigned int nbok = 0;
697 DummyTbl a1( 50, 10 );
704 trace.
beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to DummyTbl member. Duplication (+1/0)" );
705 CloneToValueMember c00( a1 );
706 trace.
info() <<
"D: d1.value() = " << c00.value() << std::endl;
707 ++nb; nbok += DummyTbl::nbCreated==1 ? 1 : 0;
708 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
709 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
710 <<
" nbCreated=" << DummyTbl::nbCreated
711 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
714 trace.
beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl member. Duplication (+1/0)" );
715 CloneToValueMember c30( a1 );
716 trace.
info() <<
"D: d1.value() = " << c30.value() << std::endl;
717 ++nb; nbok += DummyTbl::nbCreated==2 ? 1 : 0;
718 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
719 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
720 <<
" nbCreated=" << DummyTbl::nbCreated
721 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
724 trace.
beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to CountedPtr<DummyTbl> member. Duplication (+1/0)" );
725 CloneToCountedMember c03( a1 );
726 trace.
info() <<
"D: d1.value() = " << c03.value() << std::endl;
727 ++nb; nbok += DummyTbl::nbCreated==3 ? 1 : 0;
728 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
729 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
730 <<
" nbCreated=" << DummyTbl::nbCreated
731 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
734 trace.
beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to CowPtr<DummyTbl> member. Duplication (+1/0)" );
735 CloneToCowMember c02( a1 );
736 trace.
info() <<
"D: d1.value() = " << c02.value() << std::endl;
737 ++nb; nbok += DummyTbl::nbCreated==4 ? 1 : 0;
738 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
739 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
740 <<
" nbCreated=" << DummyTbl::nbCreated
741 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
744 trace.
beginBlock (
"Clone: #DummyTbl with (CowPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
745 CloneToCowMember c22( cow_a1 );
746 trace.
info() <<
"D: d1.value() = " << c22.value() << std::endl;
747 ++nb; nbok += DummyTbl::nbCreated==4 ? 1 : 0;
748 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
749 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
750 <<
" nbCreated=" << DummyTbl::nbCreated
751 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
753 trace.
info() <<
"D: d1.setValue( 17 ) -> now duplicating " << std::endl;
754 trace.
info() <<
"D: d1.value() = " << c22.value() << std::endl;
755 ++nb; nbok += DummyTbl::nbCreated==5 ? 1 : 0;
756 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
757 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
758 <<
" nbCreated=" << DummyTbl::nbCreated
759 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
762 trace.
beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
763 CloneToCowMember c32( counted_a1 );
764 trace.
info() <<
"D: d1.value() = " << c32.value() << std::endl;
765 ++nb; nbok += DummyTbl::nbCreated==5 ? 1 : 0;
766 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
767 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
768 <<
" nbCreated=" << DummyTbl::nbCreated
769 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
771 trace.
info() <<
"D: d1.setValue( 21 ) -> now duplicating " << std::endl;
772 trace.
info() <<
"D: d1.value() = " << c32.value() << std::endl;
773 ++nb; nbok += DummyTbl::nbCreated==6 ? 1 : 0;
774 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
775 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
776 <<
" nbCreated=" << DummyTbl::nbCreated
777 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
780 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to DummyTbl member. Acquisition, duplication, delete (+2/+1)" );
781 CloneToValueMember c10(
new DummyTbl( 50, 2 ) );
782 trace.
info() <<
"D: d1.value() = " << c10.value() << std::endl;
783 ++nb; nbok += DummyTbl::nbCreated==8 ? 1 : 0;
784 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
785 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
786 <<
" nbCreated=" << DummyTbl::nbCreated
787 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
790 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to CowPtr<DummyTbl> member. Acquisition, no duplication (+1/0)" );
791 CloneToCowMember c12(
new DummyTbl( 50, 15 ) );
792 trace.
info() <<
"D: d1.value() = " << c12.value() << std::endl;
793 ++nb; nbok += DummyTbl::nbCreated==9 ? 1 : 0;
794 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
795 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
796 <<
" nbCreated=" << DummyTbl::nbCreated
797 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
800 trace.
beginBlock (
"Clone: #DummyTbl with (const DummyTbl&) to DummyTbl* member. Duplication (+1/0)" );
801 CloneToPtrMember c01( a1 );
802 trace.
info() <<
"D: d1.value() = " << c01.value() << std::endl;
803 ++nb; nbok += DummyTbl::nbCreated==10 ? 1 : 0;
804 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
805 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
806 <<
" nbCreated=" << DummyTbl::nbCreated
807 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
810 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to DummyTbl* member. Acquisition (+1/0)" );
811 CloneToPtrMember c11(
new DummyTbl( 50, 42 ) );
812 trace.
info() <<
"D: d1.value() = " << c11.value() << std::endl;
813 ++nb; nbok += DummyTbl::nbCreated==11 ? 1 : 0;
814 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
815 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
816 <<
" nbCreated=" << DummyTbl::nbCreated
817 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
820 trace.
beginBlock (
"Clone: #DummyTbl with (CowPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
821 CloneToPtrMember c21( cow_a1 );
822 trace.
info() <<
"D: d1.value() = " << c21.value() << std::endl;
823 ++nb; nbok += DummyTbl::nbCreated==12 ? 1 : 0;
824 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
825 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
826 <<
" nbCreated=" << DummyTbl::nbCreated
827 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
830 trace.
beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
831 CloneToPtrMember c31( counted_a1 );
832 trace.
info() <<
"D: d1.value() = " << c31.value() << std::endl;
833 ++nb; nbok += DummyTbl::nbCreated==13 ? 1 : 0;
834 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
835 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
836 <<
" nbCreated=" << DummyTbl::nbCreated
837 <<
" nbDeleted=" << DummyTbl::nbDeleted << std::endl;
840 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to DummyTbl member. Duplication by move (+2/+1/+1)" );
841 CloneToValueMember c40( DummyTbl( 50, -4 ) );
842 trace.
info() <<
"D: d1.value() = " << c40.value() << std::endl;
843 ++nb; nbok += DummyTbl::nbCreated==15 ? 1 : 0;
844 ++nb; nbok += DummyTbl::nbDeleted==2 ? 1 : 0;
845 ++nb; nbok += DummyTbl::nbMoved==1 ? 1 : 0;
846 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
847 <<
" nbCreated=" << DummyTbl::nbCreated
848 <<
" nbDeleted=" << DummyTbl::nbDeleted
849 <<
" nbMoved=" << DummyTbl::nbMoved
853 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to CowPtr<DummyTbl> member. Duplication by move (+2/+1/+1)" );
854 CloneToCowMember c42( DummyTbl( 50, -9 ) );
855 trace.
info() <<
"D: d1.value() = " << c42.value() << std::endl;
856 ++nb; nbok += DummyTbl::nbCreated==17 ? 1 : 0;
857 ++nb; nbok += DummyTbl::nbDeleted==3 ? 1 : 0;
858 ++nb; nbok += DummyTbl::nbMoved==2 ? 1 : 0;
859 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
860 <<
" nbCreated=" << DummyTbl::nbCreated
861 <<
" nbDeleted=" << DummyTbl::nbDeleted
862 <<
" nbMoved=" << DummyTbl::nbMoved
866 trace.
beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to DummyTbl* member. Duplication by move (+2/+1/+1)" );
867 CloneToCowMember c41( DummyTbl( 50, -12 ) );
868 trace.
info() <<
"D: d1.value() = " << c41.value() << std::endl;
869 ++nb; nbok += DummyTbl::nbCreated==19 ? 1 : 0;
870 ++nb; nbok += DummyTbl::nbDeleted==4 ? 1 : 0;
871 ++nb; nbok += DummyTbl::nbMoved==3 ? 1 : 0;
872 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
873 <<
" nbCreated=" << DummyTbl::nbCreated
874 <<
" nbDeleted=" << DummyTbl::nbDeleted
875 <<
" nbMoved=" << DummyTbl::nbMoved
887 unsigned int nbok = 0;
891 trace.
beginBlock (
"Total perimeter of triangles with by-value parameter passing." );
892 double t1 = computeTriangles<TriangleByValue>( size );
893 trace.
info() <<
"Perimeter is " << t1 << std::endl;
894 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
895 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
896 <<
" Point nbCreated=" << Point::nbCreated
897 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
898 int nbC = Point::nbCreated;
901 trace.
beginBlock (
"Total perimeter of triangles with by-const reference parameter passing." );
902 double t2 = computeTriangles<TriangleByConstReference>( size );
903 trace.
info() <<
"Perimeter is " << t2 << std::endl;
904 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
905 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
906 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
907 <<
" Point nbCreated=" << Point::nbCreated
908 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
911 trace.
beginBlock (
"Total perimeter of triangles with by Clone parameter passing." );
912 double t4 = computeTriangles<TriangleByClone>( size );
913 trace.
info() <<
"Perimeter is " << t4 << std::endl;
914 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
915 ++nb; nbok += Point::nbCreated <= nbC ? 1 : 0;
916 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
917 <<
" Point nbCreated=" << Point::nbCreated
918 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
921 trace.
beginBlock (
"Total perimeter of triangles with by CloneAndCow parameter passing." );
922 double t5 = computeTriangles<TriangleByCloneAndCow>( size );
923 trace.
info() <<
"Perimeter is " << t5 << std::endl;
924 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
925 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
926 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
927 <<
" Point nbCreated=" << Point::nbCreated
928 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
931 trace.
beginBlock (
"Total perimeter of triangles with CowPtr by CloneAndCow parameter passing." );
932 double t6 = computeTrianglesByCowPtr<TriangleByCloneAndCow>( size );
933 trace.
info() <<
"Perimeter is " << t6 << std::endl;
934 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
935 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
936 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
937 <<
" Point nbCreated=" << Point::nbCreated
938 <<
" nbDeleted=" << Point::nbDeleted << std::endl;
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: Smart pointer based on reference counts.
Aim: Copy on write shared pointer.
bool unique() const noexcept
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
KForm< Calculus, order, duality > operator-(const KForm< Calculus, order, duality > &form_a, const KForm< Calculus, order, duality > &form_b)
Represents an unoriented triangle as three vertices.
double computeTriangles(int size)
bool testConstAliasCases()
double computeTrianglesByCowPtr(int size)