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"
100 inline operator T()
const
100 inline operator T()
const {
…}
165 std::cout <<
" ~DummyTbl() this=" <<
this <<
" data=" <<
data << std::endl;
167 std::cout <<
" - freed =" <<
allocated << std::endl;
171 std::cout <<
" - nothing to do (already moved)" << std::endl;
177 std::cout <<
" DummyTbl( " << i <<
" ) this=" <<
this << std::endl;
180 std::cout <<
" - allocated=" <<
allocated << std::endl;
181 std::cout <<
" - copied =" <<
size << std::endl;
186 std::cout <<
" DummyTbl( const DummyTbl & a ) this=" <<
this <<
" a=" << &a << std::endl;
188 for (
int i = 0; i <
size; ++i )
data[ i ] = a.
data[ i ];
189 std::cout <<
" - allocated=" <<
allocated << std::endl;
190 std::cout <<
" - copied =" <<
size << std::endl;
195 :
size( std::move( a.size ) ),
allocated( std::move( a.allocated ) )
197 data = a.data; a.data = 0;
198 std::cout <<
" DummyTbl( DummyTbl && a ) this=" <<
this <<
" a=" << &a << std::endl;
199 std::cout <<
" - check data: a=" <<
allocated <<
" s=" <<
size << std::endl;
211 std::cout <<
" DummyTbl::operator=( const DummyTbl & a ) " << std::endl;
329 double dx = (double)
_x;
330 double dy = (double)
_y;
331 return sqrt( dx * dx + dy * dy );
363 double dx = (double)
_x;
364 double dy = (double)
_y;
365 return sqrt( dx * dx + dy * dy );
386 :
_a( a ),
_b( b ),
_c( c ) {}
389 return (
_a -
_b).norm() + (
_b -
_c).norm() + (
_c -
_a).norm();
396 :
_a( a ),
_b( b ),
_c( c ) {}
399 return (
_a -
_b).norm() + (
_b -
_c).norm() + (
_c -
_a).norm();
406 :
_a( a ),
_b( b ),
_c( c ) {}
409 return (
_a -
_b).norm() + (
_b -
_c).norm() + (
_c -
_a).norm();
416 :
_a( a ),
_b( b ),
_c( c ) {}
419 return (*
_a - *
_b).norm() + (*
_b - *
_c).norm() + (*
_c - *
_a).norm();
424template <
typename Triangle>
430 for (
int yb = 0; yb < size; ++yb )
431 for (
int xb = 0; xb < size; ++xb )
434 for (
int yc = 0; yc < size; ++yc )
435 for (
int xc = 0; xc < size; ++xc )
439 total += T.perimeter();
445template <
typename Triangle>
451 for (
int yb = 0; yb < size; ++yb )
452 for (
int xb = 0; xb < size; ++xb )
455 for (
int yc = 0; yc < size; ++yc )
456 for (
int xc = 0; xc < size; ++xc )
460 total += T.perimeter();
478 unsigned int nbok = 0;
483 trace.beginBlock (
"Testing class Alias." );
492 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl& to DummyTbl& member. no duplication (0/0)" );
494 trace.info() <<
"D: d1.value() = " << c00.
value() << std::endl;
497 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
502 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl* to DummyTbl& member. no duplication (0/0)" );
504 trace.info() <<
"D: d1.value() = " << c10.
value() << std::endl;
507 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
512 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl& to DummyTbl* member. no duplication (0/0)" );
514 trace.info() <<
"D: d1.value() = " << c01.
value() << std::endl;
517 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
522 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl* to DummyTbl* member. no duplication (0/0)" );
524 trace.info() <<
"D: d1.value() = " << c11.
value() << std::endl;
527 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
532 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl& to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
534 trace.info() <<
"D: d1.value() = " << c06.
value() << std::endl;
538 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
543 trace.beginBlock (
"Alias: #DummyTbl with DummyTbl* to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
545 trace.info() <<
"D: d1.value() = " << c16.
value() << std::endl;
549 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
577 unsigned int nbok = 0;
583 trace.beginBlock (
"Testing class ConstAlias." );
593 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl& member. no duplication (0/0)" );
595 trace.info() <<
"D: d1.value() = " << c00.
value() << std::endl;
598 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
603 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl& member. no duplication (0/0)" );
605 trace.info() <<
"D: d1.value() = " << c10.
value() << std::endl;
608 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
613 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl* member. no duplication (0/0)" );
615 trace.info() <<
"D: d1.value() = " << c01.
value() << std::endl;
618 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
623 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl* member. no duplication (0/0)" );
625 trace.info() <<
"D: d1.value() = " << c11.
value() << std::endl;
628 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
633 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl* to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
635 trace.info() <<
"D: d1.value() = " << c17.
value() << std::endl;
638 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
643 trace.beginBlock (
"ConstAlias: #DummyTbl with const DummyTbl& to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
645 trace.info() <<
"D: d1.value() = " << c07.
value() << std::endl;
648 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
653 trace.beginBlock (
"ConstAlias: #DummyTbl with CountedPtr<DummyTbl> to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
655 trace.info() <<
"D: d1.value() = " << c37.
value() << std::endl;
658 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
694 unsigned int nbok = 0;
699 trace.beginBlock (
"Testing class Clone." );
702 trace.beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to DummyTbl member. Duplication (+1/0)" );
704 trace.info() <<
"D: d1.value() = " << c00.
value() << std::endl;
707 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
712 trace.beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl member. Duplication (+1/0)" );
714 trace.info() <<
"D: d1.value() = " << c30.
value() << std::endl;
717 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
722 trace.beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to CountedPtr<DummyTbl> member. Duplication (+1/0)" );
724 trace.info() <<
"D: d1.value() = " << c03.
value() << std::endl;
727 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
732 trace.beginBlock (
"Clone: #DummyTbl with (const DummyTbl &) to CowPtr<DummyTbl> member. Duplication (+1/0)" );
734 trace.info() <<
"D: d1.value() = " << c02.
value() << std::endl;
737 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
742 trace.beginBlock (
"Clone: #DummyTbl with (CowPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
744 trace.info() <<
"D: d1.value() = " << c22.
value() << std::endl;
747 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
751 trace.info() <<
"D: d1.setValue( 17 ) -> now duplicating " << std::endl;
752 trace.info() <<
"D: d1.value() = " << c22.
value() << std::endl;
755 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
760 trace.beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
762 trace.info() <<
"D: d1.value() = " << c32.
value() << std::endl;
765 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
769 trace.info() <<
"D: d1.setValue( 21 ) -> now duplicating " << std::endl;
770 trace.info() <<
"D: d1.value() = " << c32.
value() << std::endl;
773 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
778 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to DummyTbl member. Acquisition, duplication, delete (+2/+1)" );
780 trace.info() <<
"D: d1.value() = " << c10.
value() << std::endl;
783 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
788 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to CowPtr<DummyTbl> member. Acquisition, no duplication (+1/0)" );
790 trace.info() <<
"D: d1.value() = " << c12.
value() << std::endl;
793 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
798 trace.beginBlock (
"Clone: #DummyTbl with (const DummyTbl&) to DummyTbl* member. Duplication (+1/0)" );
800 trace.info() <<
"D: d1.value() = " << c01.
value() << std::endl;
803 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
808 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl*) to DummyTbl* member. Acquisition (+1/0)" );
810 trace.info() <<
"D: d1.value() = " << c11.
value() << std::endl;
813 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
818 trace.beginBlock (
"Clone: #DummyTbl with (CowPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
820 trace.info() <<
"D: d1.value() = " << c21.
value() << std::endl;
823 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
828 trace.beginBlock (
"Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
830 trace.info() <<
"D: d1.value() = " << c31.
value() << std::endl;
833 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
838 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to DummyTbl member. Duplication by move (+2/+1/+1)" );
840 trace.info() <<
"D: d1.value() = " << c40.
value() << std::endl;
844 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
851 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to CowPtr<DummyTbl> member. Duplication by move (+2/+1/+1)" );
853 trace.info() <<
"D: d1.value() = " << c42.
value() << std::endl;
857 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
864 trace.beginBlock (
"Clone: #DummyTbl with (DummyTbl &&) to DummyTbl* member. Duplication by move (+2/+1/+1)" );
866 trace.info() <<
"D: d1.value() = " << c41.
value() << std::endl;
870 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
885 unsigned int nbok = 0;
887 trace.beginBlock (
"Testing Clone timings." );
889 trace.beginBlock (
"Total perimeter of triangles with by-value parameter passing." );
891 trace.info() <<
"Perimeter is " << t1 << std::endl;
893 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
899 trace.beginBlock (
"Total perimeter of triangles with by-const reference parameter passing." );
901 trace.info() <<
"Perimeter is " << t2 << std::endl;
904 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
909 trace.beginBlock (
"Total perimeter of triangles with by Clone parameter passing." );
911 trace.info() <<
"Perimeter is " << t4 << std::endl;
914 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
919 trace.beginBlock (
"Total perimeter of triangles with by CloneAndCow parameter passing." );
921 trace.info() <<
"Perimeter is " << t5 << std::endl;
924 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
929 trace.beginBlock (
"Total perimeter of triangles with CowPtr by CloneAndCow parameter passing." );
931 trace.info() <<
"Perimeter is " << t6 << std::endl;
934 trace.info() <<
"(" << nbok <<
"/" << nb <<
")"
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 or simple const pointer on T. It can be a smart pointer based on reference counts or a sim...
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple po...
Aim: Smart pointer based on reference counts.
Aim: Copy on write shared pointer.
NClone(CountedPtr< T > ptr)
CowPtr< T > myCowPtr
The copy-on-write pointer to the T object that is to be duplicated.
NClone & operator=(const NClone &other)
MyPointD(const MyPointD &other)
MyPointD operator-(const MyPointD &other) const
MyPointD(double x, double y)
MyPoint operator-(const MyPoint &other) const
MyPoint(const MyPoint &other)
DGtal is the top-level namespace which contains all DGtal functions and types.
const DummyTbl & myDummyTbl
AliasToConstRefMember(Alias< DummyTbl > a1)
CountedPtrOrPtr< DummyTbl > myDummyTbl
AliasToCountedPtrOrPtrMember(Alias< DummyTbl > a1)
AliasToPtrMember(Alias< DummyTbl > a1)
AliasToRefMember(Alias< DummyTbl > a1)
CloneToCountedMember(Clone< DummyTbl > a1)
CountedPtr< DummyTbl > myDummyTbl
CloneToCowMember(Clone< DummyTbl > a1)
CowPtr< DummyTbl > myDummyTbl
CloneToPtrMember(Clone< DummyTbl > a1)
CloneToValueMember(Clone< DummyTbl > a1)
const DummyTbl * myDummyTbl
ConstAliasToConstPtrMember(ConstAlias< DummyTbl > a1)
const DummyTbl & myDummyTbl
ConstAliasToConstRefMember(ConstAlias< DummyTbl > a1)
ConstAliasToCountedConstPtrOrConstPtrMember(ConstAlias< DummyTbl > a1)
CountedConstPtrOrConstPtr< DummyTbl > myDummyTbl
DummyTbl(const DummyTbl &a)
void setValue(int v) const
DummyTbl & operator=(const DummyTbl &a)
DummyTbl(DummyTbl &&a) noexcept
TriangleByCloneAndCow(Clone< Point > a, Clone< Point > b, Clone< Point > c)
TriangleByClone(Clone< Point > a, Clone< Point > b, Clone< Point > c)
TriangleByConstReference(const Point &a, const Point &b, const Point &c)
TriangleByValue(Point a, Point b, Point c)
double computeTriangles(int size)
bool testConstAliasCases()
double computeTrianglesByCowPtr(int size)
HalfEdgeDataStructure::Triangle Triangle