File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
testClone2.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/base/CountedPtr.h"
#include "DGtal/base/CountedPtrOrPtr.h"
#include "DGtal/base/CountedConstPtrOrConstPtr.h"
#include "DGtal/base/CowPtr.h"
#include "DGtal/base/Clone.h"
#include "DGtal/base/Alias.h"
#include "DGtal/base/ConstAlias.h"
#include "DGtal/helpers/StdDefs.h"
Include dependency graph for testClone2.cpp:

Go to the source code of this file.

Data Structures

class  DGtal::NClone< T >
struct  DummyTbl
struct  CloneToValueMember
struct  CloneToCountedMember
struct  CloneToCowMember
struct  CloneToPtrMember
struct  AliasToRefMember
struct  AliasToPtrMember
struct  AliasToCountedPtrOrPtrMember
struct  AliasToConstRefMember
struct  ConstAliasToConstRefMember
struct  ConstAliasToConstPtrMember
struct  ConstAliasToCountedConstPtrOrConstPtrMember
class  MyPoint
class  MyPointD
struct  TriangleByConstReference
struct  TriangleByValue
struct  TriangleByClone
struct  TriangleByCloneAndCow

Namespaces

namespace  DGtal
 DGtal is the top-level namespace which contains all DGtal functions and types.

Typedefs

typedef MyPointD Point

Functions

template<typename Triangle>
double computeTriangles (int size)
template<typename Triangle>
double computeTrianglesByCowPtr (int size)
bool testAliasCases ()
bool testConstAliasCases ()
bool testCloneCases ()
bool testCloneTimings ()
int main ()

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2012/07/02

This file is part of the DGtal library

Definition in file testClone2.cpp.

Typedef Documentation

◆ Point

typedef MyPointD Point
Examples
arithmetic/lower-integer-convex-hull.cpp, dec/exampleDECSurface.cpp, dec/exampleHeatLaplace.cpp, dec/examplePropagation.cpp, doc-examples/exampleCatch.cpp, examples/tutorial-examples/polyhedralizer.cpp, geometry/curves/convex-and-concave-parts.cpp, geometry/curves/estimation/exampleLMST2D.cpp, geometry/curves/estimation/exampleLMST3D.cpp, geometry/curves/estimation/exampleLMST3DBy2D.cpp, geometry/curves/exampleArithDSS3d.cpp, geometry/curves/exampleArithmeticalDSL.cpp, geometry/curves/exampleArithmeticalDSS.cpp, geometry/curves/exampleDSLSubsegment.cpp, geometry/curves/exampleDigitalConvexity.cpp, geometry/curves/exampleGridCurve2d.cpp, geometry/curves/exampleGridCurve3d.cpp, geometry/curves/exampleRationalConvexity.cpp, geometry/curves/greedy-dss-decomposition.cpp, geometry/surfaces/dvcm-2d-curvature.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, geometry/tools/checkLatticeBallQuickHull.cpp, geometry/tools/determinant/exampleInHalfPlane.cpp, geometry/tools/exampleAlphaShape.cpp, geometry/tools/exampleConvexHull2D.cpp, geometry/tools/exampleLatticeBallDelaunay2D.cpp, geometry/tools/exampleLatticeBallDelaunay3D.cpp, geometry/tools/exampleLatticeBallQuickHull3D.cpp, geometry/volumes/checkFullConvexityTheorems.cpp, geometry/volumes/digitalPolyhedronBuilder3D.cpp, geometry/volumes/distance/exampleFMM2D.cpp, geometry/volumes/distance/exampleFMM3D.cpp, geometry/volumes/distance/toricdomainvolumetric.cpp, geometry/volumes/dvcm-2d.cpp, geometry/volumes/exampleBoundedLatticePolytopeCount2D.cpp, geometry/volumes/exampleBoundedLatticePolytopeCount3D.cpp, geometry/volumes/exampleBoundedLatticePolytopeCount4D.cpp, geometry/volumes/fullConvexityAnalysis3D.cpp, geometry/volumes/fullConvexityLUT2D.cpp, geometry/volumes/fullConvexityShortestPaths3D.cpp, geometry/volumes/fullConvexitySphereGeodesics.cpp, geometry/volumes/fullConvexityThinning3D.cpp, geometry/volumes/pConvexity-benchmark.cpp, geometry/volumes/standardDigitalPolyhedronBuilder3D.cpp, graph/graphTraversal.cpp, images/exampleConstImageAdapter.cpp, images/exampleRigidtransformation3d.cpp, io/boards/dgtalBoard2D-1-points.cpp, io/boards/dgtalBoard2D-2-sets.cpp, io/boards/dgtalBoard2D-3-custom-classes.cpp, io/boards/dgtalBoard2D-3-custom-points.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, io/boards/exampleBezierCurve.cpp, io/boards/logoDGtal.cpp, io/viewDualSurface.cpp, io/viewers/viewer3D-1-points.cpp, io/viewers/viewer3D-10-interaction.cpp, io/viewers/viewer3D-2-sets.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-4-modes.cpp, io/viewers/viewer3D-5-colors.cpp, io/viewers/viewer3D-6-clipping.cpp, io/viewers/viewer3D-7-planes.cpp, io/viewers/viewer3D-7-stdplane.cpp, shapes/exampleMeshVoxelizer.cpp, shapes/mesh3DConstructionAndVisualisation.cpp, topology/3dBorderExtraction.cpp, topology/3dKSSurfaceExtraction.cpp, topology/area-estimation-with-digital-surface.cpp, topology/area-estimation-with-indexed-digital-surface.cpp, topology/ctopo-1-3d.cpp, topology/ctopo-1.cpp, topology/ctopo-1s-3d.cpp, topology/cubical-complex-collapse.cpp, topology/cubical-complex-illustrations.cpp, topology/frontierAndBoundary.cpp, topology/generateSimplicityTables2D.cpp, topology/homotopicThinning3D.cpp, and tutorial-examples/polyhedralizer.cpp.

Definition at line 381 of file testClone2.cpp.

Function Documentation

◆ computeTriangles()

template<typename Triangle>
double computeTriangles ( int size)

Definition at line 426 of file testClone2.cpp.

427{
428 double total = 0.0;
429 Point A( 0, 0 );
430 for ( int yb = 0; yb < size; ++yb )
431 for ( int xb = 0; xb < size; ++xb )
432 {
433 Point B( xb, yb );
434 for ( int yc = 0; yc < size; ++yc )
435 for ( int xc = 0; xc < size; ++xc )
436 {
437 Point C( xc, yc );
438 Triangle T( A, B, C );
439 total += T.perimeter();
440 }
441 }
442 return total;
443}
HalfEdgeDataStructure::Triangle Triangle

Referenced by testCloneTimings().

◆ computeTrianglesByCowPtr()

template<typename Triangle>
double computeTrianglesByCowPtr ( int size)

Definition at line 447 of file testClone2.cpp.

448{
449 double total = 0.0;
450 CowPtr<Point> A( new Point( 0, 0 ) );
451 for ( int yb = 0; yb < size; ++yb )
452 for ( int xb = 0; xb < size; ++xb )
453 {
454 CowPtr<Point> B( new Point( xb, yb ) );
455 for ( int yc = 0; yc < size; ++yc )
456 for ( int xc = 0; xc < size; ++xc )
457 {
458 CowPtr<Point> C( new Point( xc, yc ) );
459 Triangle T( A, B, C );
460 total += T.perimeter();
461 }
462 }
463 return total;
464}
Aim: Copy on write shared pointer.
Definition CowPtr.h:68
MyPointD Point

Referenced by testCloneTimings().

◆ main()

int main ( void )

Definition at line 945 of file testClone2.cpp.

946{
947 bool ok = true
948 && testCloneCases()
950 && testAliasCases()
952
953 return ok ? 0 : 1;
954}
bool testAliasCases()
bool testCloneTimings()
bool testCloneCases()
bool testConstAliasCases()

References testAliasCases(), testCloneCases(), testCloneTimings(), and testConstAliasCases().

◆ testAliasCases()

bool testAliasCases ( )

Alias: Performs without unnecessary duplicates "parameter -> member data"

  • A& -> A& // no duplication (checked)
  • A* -> A& // no duplication, exception if null (checked)
  • A& -> A* // no duplication (checked)
  • A* -> A* // no duplication (checked)
  • CountedPtr -> CountedPtr // shared (checked)
  • CountedPtr -> CowPtr // shared (not logical, but not preventable). (checked)

Definition at line 475 of file testClone2.cpp.

476{
477 unsigned int nb = 0;
478 unsigned int nbok = 0;
479 DummyTbl a1( 100, 10 ); // +1/0
480 DummyTbl* ptr_a2 = new DummyTbl( 100, 18 ); // +1/0
481 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 100, 12 ) ); // +1/0
483 trace.beginBlock ( "Testing class Alias." );
484
485 /*
486 - A& -> A& // no duplication
487 - A* -> A& // no duplication, exception if null
488 - A& -> A* // no duplication
489 - A* -> A* // no duplication
490 - CountedPtr<A> -> CountedPtr<A> // shared
491 */
492 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to DummyTbl& member. no duplication (0/0)" );
493 AliasToRefMember c00( a1 ); // 0/0
494 trace.info() << "D: d1.value() = " << c00.value() << std::endl;
495 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
496 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
497 trace.info() << "(" << nbok << "/" << nb << ")"
498 << " nbCreated=" << DummyTbl::nbCreated
499 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
500 trace.endBlock();
501
502 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to DummyTbl& member. no duplication (0/0)" );
503 AliasToRefMember c10( ptr_a2 ); // 0/0
504 trace.info() << "D: d1.value() = " << c10.value() << std::endl;
505 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
506 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
507 trace.info() << "(" << nbok << "/" << nb << ")"
508 << " nbCreated=" << DummyTbl::nbCreated
509 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
510 trace.endBlock();
511
512 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to DummyTbl* member. no duplication (0/0)" );
513 AliasToPtrMember c01( a1 ); // 0/0
514 trace.info() << "D: d1.value() = " << c01.value() << std::endl;
515 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
516 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
517 trace.info() << "(" << nbok << "/" << nb << ")"
518 << " nbCreated=" << DummyTbl::nbCreated
519 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
520 trace.endBlock();
521
522 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to DummyTbl* member. no duplication (0/0)" );
523 AliasToPtrMember c11( ptr_a2 ); // 0/0
524 trace.info() << "D: d1.value() = " << c11.value() << std::endl;
525 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
526 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
527 trace.info() << "(" << nbok << "/" << nb << ")"
528 << " nbCreated=" << DummyTbl::nbCreated
529 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
530 trace.endBlock();
531
532 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
533 AliasToCountedPtrOrPtrMember c06( a1 ); // 0/0
534 trace.info() << "D: d1.value() = " << c06.value() << std::endl;
535 trace.info() << c06.myDummyTbl << std::endl;
536 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
537 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
538 trace.info() << "(" << nbok << "/" << nb << ")"
539 << " nbCreated=" << DummyTbl::nbCreated
540 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
541 trace.endBlock();
542
543 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
544 AliasToCountedPtrOrPtrMember c16( a1 ); // 0/0
545 trace.info() << "D: d1.value() = " << c16.value() << std::endl;
546 trace.info() << c16.myDummyTbl << std::endl;
547 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
548 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
549 trace.info() << "(" << nbok << "/" << nb << ")"
550 << " nbCreated=" << DummyTbl::nbCreated
551 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
552 trace.endBlock();
553
554 // const DummyTbl& const_a1 = a1;
555 // AliasToRefMember c02( const_a1 ); // does not execute.
556 // const DummyTbl* const_ptr_a1 = &a1;
557 // AliasToRefMember c05( const_ptr_a1 ); // does not execute.
558
559 trace.endBlock();
560
561 delete ptr_a2;
562 return nbok == nb;
563}
Aim: Smart pointer based on reference counts.
Definition CountedPtr.h:80
Trace trace
static int nbDeleted
static void reset()
static int nbCreated

References AliasToCountedPtrOrPtrMember::myDummyTbl, DummyTbl::nbCreated, DummyTbl::nbDeleted, DummyTbl::reset(), DGtal::trace, AliasToCountedPtrOrPtrMember::value(), AliasToPtrMember::value(), and AliasToRefMember::value().

Referenced by main().

◆ testCloneCases()

bool testCloneCases ( )

Clone: Performs without unnecessary duplicates "parameter -> member data"

  • const A & -> A // immediate duplication (checked)
  • A* -> A // immediate duplication, acquired and deleted. (checked)
  • CountedPtr -> A // immediate duplication (checked)
  • CowPtr -> A // immediate duplication (checked)
  • A&& -> A // move into member (checked)
  • const A & -> CowPtr // immediate duplication (checked)
  • A* -> CowPtr // acquired (checked)
  • CountedPtr -> CowPtr // lazy duplication (checked)
  • CowPtr -> CowPtr // lazy duplication (checked)
  • A&& -> CowPtr // move into member (checked)
  • const A & -> A* // immediate duplication, should be deleted at the end. (checked)
  • A* -> A* // acquired, should be deleted at the end. (checked)
  • CountedPtr -> A* // immediate duplication, should be deleted at the end. (checked)
  • CowPtr -> A* // immediate duplication, should be deleted at the end. (checked)
  • A&& -> A* // move into member, should be deleted at the end. (checked)

Definition at line 691 of file testClone2.cpp.

692{
693 unsigned int nb = 0;
694 unsigned int nbok = 0;
695 DummyTbl a1( 50, 10 ); // +1/0
696 CowPtr<DummyTbl> cow_a1( new DummyTbl( 50, 5 ) ); // +1/0
697 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 50, 12 ) ); // +1/0
699 trace.beginBlock ( "Testing class Clone." );
700
701
702 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to DummyTbl member. Duplication (+1/0)" );
703 CloneToValueMember c00( a1 ); // +1/0
704 trace.info() << "D: d1.value() = " << c00.value() << std::endl;
705 ++nb; nbok += DummyTbl::nbCreated==1 ? 1 : 0;
706 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
707 trace.info() << "(" << nbok << "/" << nb << ")"
708 << " nbCreated=" << DummyTbl::nbCreated
709 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
710 trace.endBlock();
711
712 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl member. Duplication (+1/0)" );
713 CloneToValueMember c30( a1 ); // +1/0
714 trace.info() << "D: d1.value() = " << c30.value() << std::endl;
715 ++nb; nbok += DummyTbl::nbCreated==2 ? 1 : 0;
716 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
717 trace.info() << "(" << nbok << "/" << nb << ")"
718 << " nbCreated=" << DummyTbl::nbCreated
719 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
720 trace.endBlock();
721
722 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to CountedPtr<DummyTbl> member. Duplication (+1/0)" );
723 CloneToCountedMember c03( a1 ); // +1/0
724 trace.info() << "D: d1.value() = " << c03.value() << std::endl;
725 ++nb; nbok += DummyTbl::nbCreated==3 ? 1 : 0;
726 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
727 trace.info() << "(" << nbok << "/" << nb << ")"
728 << " nbCreated=" << DummyTbl::nbCreated
729 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
730 trace.endBlock();
731
732 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to CowPtr<DummyTbl> member. Duplication (+1/0)" );
733 CloneToCowMember c02( a1 ); // +1/0
734 trace.info() << "D: d1.value() = " << c02.value() << std::endl;
735 ++nb; nbok += DummyTbl::nbCreated==4 ? 1 : 0;
736 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
737 trace.info() << "(" << nbok << "/" << nb << ")"
738 << " nbCreated=" << DummyTbl::nbCreated
739 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
740 trace.endBlock();
741
742 trace.beginBlock ( "Clone: #DummyTbl with (CowPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
743 CloneToCowMember c22( cow_a1 ); // +0/0
744 trace.info() << "D: d1.value() = " << c22.value() << std::endl;
745 ++nb; nbok += DummyTbl::nbCreated==4 ? 1 : 0;
746 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
747 trace.info() << "(" << nbok << "/" << nb << ")"
748 << " nbCreated=" << DummyTbl::nbCreated
749 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
750 c22.setValue( 17 );
751 trace.info() << "D: d1.setValue( 17 ) -> now duplicating " << std::endl;
752 trace.info() << "D: d1.value() = " << c22.value() << std::endl;
753 ++nb; nbok += DummyTbl::nbCreated==5 ? 1 : 0;
754 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
755 trace.info() << "(" << nbok << "/" << nb << ")"
756 << " nbCreated=" << DummyTbl::nbCreated
757 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
758 trace.endBlock();
759
760 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
761 CloneToCowMember c32( counted_a1 ); // +0/0
762 trace.info() << "D: d1.value() = " << c32.value() << std::endl;
763 ++nb; nbok += DummyTbl::nbCreated==5 ? 1 : 0;
764 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
765 trace.info() << "(" << nbok << "/" << nb << ")"
766 << " nbCreated=" << DummyTbl::nbCreated
767 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
768 c32.setValue( 21 );
769 trace.info() << "D: d1.setValue( 21 ) -> now duplicating " << std::endl;
770 trace.info() << "D: d1.value() = " << c32.value() << std::endl;
771 ++nb; nbok += DummyTbl::nbCreated==6 ? 1 : 0;
772 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
773 trace.info() << "(" << nbok << "/" << nb << ")"
774 << " nbCreated=" << DummyTbl::nbCreated
775 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
776 trace.endBlock();
777
778 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to DummyTbl member. Acquisition, duplication, delete (+2/+1)" );
779 CloneToValueMember c10( new DummyTbl( 50, 2 ) ); // +2/+1
780 trace.info() << "D: d1.value() = " << c10.value() << std::endl;
781 ++nb; nbok += DummyTbl::nbCreated==8 ? 1 : 0;
782 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
783 trace.info() << "(" << nbok << "/" << nb << ")"
784 << " nbCreated=" << DummyTbl::nbCreated
785 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
786 trace.endBlock();
787
788 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to CowPtr<DummyTbl> member. Acquisition, no duplication (+1/0)" );
789 CloneToCowMember c12( new DummyTbl( 50, 15 ) ); // +1/0
790 trace.info() << "D: d1.value() = " << c12.value() << std::endl;
791 ++nb; nbok += DummyTbl::nbCreated==9 ? 1 : 0;
792 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
793 trace.info() << "(" << nbok << "/" << nb << ")"
794 << " nbCreated=" << DummyTbl::nbCreated
795 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
796 trace.endBlock();
797
798 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl&) to DummyTbl* member. Duplication (+1/0)" );
799 CloneToPtrMember c01( a1 ); // +1/0
800 trace.info() << "D: d1.value() = " << c01.value() << std::endl;
801 ++nb; nbok += DummyTbl::nbCreated==10 ? 1 : 0;
802 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
803 trace.info() << "(" << nbok << "/" << nb << ")"
804 << " nbCreated=" << DummyTbl::nbCreated
805 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
806 trace.endBlock();
807
808 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to DummyTbl* member. Acquisition (+1/0)" );
809 CloneToPtrMember c11( new DummyTbl( 50, 42 ) ); // +1/0
810 trace.info() << "D: d1.value() = " << c11.value() << std::endl;
811 ++nb; nbok += DummyTbl::nbCreated==11 ? 1 : 0;
812 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
813 trace.info() << "(" << nbok << "/" << nb << ")"
814 << " nbCreated=" << DummyTbl::nbCreated
815 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
816 trace.endBlock();
817
818 trace.beginBlock ( "Clone: #DummyTbl with (CowPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
819 CloneToPtrMember c21( cow_a1 ); // +1/0
820 trace.info() << "D: d1.value() = " << c21.value() << std::endl;
821 ++nb; nbok += DummyTbl::nbCreated==12 ? 1 : 0;
822 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
823 trace.info() << "(" << nbok << "/" << nb << ")"
824 << " nbCreated=" << DummyTbl::nbCreated
825 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
826 trace.endBlock();
827
828 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
829 CloneToPtrMember c31( counted_a1 ); // +1/0
830 trace.info() << "D: d1.value() = " << c31.value() << std::endl;
831 ++nb; nbok += DummyTbl::nbCreated==13 ? 1 : 0;
832 ++nb; nbok += DummyTbl::nbDeleted==1 ? 1 : 0;
833 trace.info() << "(" << nbok << "/" << nb << ")"
834 << " nbCreated=" << DummyTbl::nbCreated
835 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
836 trace.endBlock();
837
838 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to DummyTbl member. Duplication by move (+2/+1/+1)" );
839 CloneToValueMember c40( DummyTbl( 50, -4 ) ); // +2/+1/+1
840 trace.info() << "D: d1.value() = " << c40.value() << std::endl;
841 ++nb; nbok += DummyTbl::nbCreated==15 ? 1 : 0;
842 ++nb; nbok += DummyTbl::nbDeleted==2 ? 1 : 0;
843 ++nb; nbok += DummyTbl::nbMoved==1 ? 1 : 0;
844 trace.info() << "(" << nbok << "/" << nb << ")"
845 << " nbCreated=" << DummyTbl::nbCreated
846 << " nbDeleted=" << DummyTbl::nbDeleted
847 << " nbMoved=" << DummyTbl::nbMoved
848 << std::endl;
849 trace.endBlock();
850
851 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to CowPtr<DummyTbl> member. Duplication by move (+2/+1/+1)" );
852 CloneToCowMember c42( DummyTbl( 50, -9 ) ); // +2/+1/+1
853 trace.info() << "D: d1.value() = " << c42.value() << std::endl;
854 ++nb; nbok += DummyTbl::nbCreated==17 ? 1 : 0;
855 ++nb; nbok += DummyTbl::nbDeleted==3 ? 1 : 0;
856 ++nb; nbok += DummyTbl::nbMoved==2 ? 1 : 0;
857 trace.info() << "(" << nbok << "/" << nb << ")"
858 << " nbCreated=" << DummyTbl::nbCreated
859 << " nbDeleted=" << DummyTbl::nbDeleted
860 << " nbMoved=" << DummyTbl::nbMoved
861 << std::endl;
862 trace.endBlock();
863
864 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to DummyTbl* member. Duplication by move (+2/+1/+1)" );
865 CloneToCowMember c41( DummyTbl( 50, -12 ) ); // +2/+1/+1
866 trace.info() << "D: d1.value() = " << c41.value() << std::endl;
867 ++nb; nbok += DummyTbl::nbCreated==19 ? 1 : 0;
868 ++nb; nbok += DummyTbl::nbDeleted==4 ? 1 : 0;
869 ++nb; nbok += DummyTbl::nbMoved==3 ? 1 : 0;
870 trace.info() << "(" << nbok << "/" << nb << ")"
871 << " nbCreated=" << DummyTbl::nbCreated
872 << " nbDeleted=" << DummyTbl::nbDeleted
873 << " nbMoved=" << DummyTbl::nbMoved
874 << std::endl;
875 trace.endBlock();
876
877 trace.endBlock();
878
879 return nbok == nb;
880}
static int nbMoved

References DummyTbl::nbCreated, DummyTbl::nbDeleted, DummyTbl::nbMoved, DummyTbl::reset(), CloneToCowMember::setValue(), DGtal::trace, CloneToCountedMember::value(), CloneToCowMember::value(), CloneToPtrMember::value(), and CloneToValueMember::value().

Referenced by main().

◆ testCloneTimings()

bool testCloneTimings ( )

Definition at line 882 of file testClone2.cpp.

883{
884 unsigned int nb = 0;
885 unsigned int nbok = 0;
886 int size = 10;
887 trace.beginBlock ( "Testing Clone timings." );
888
889 trace.beginBlock ( "Total perimeter of triangles with by-value parameter passing." );
890 double t1 = computeTriangles<TriangleByValue>( size );
891 trace.info() << "Perimeter is " << t1 << std::endl;
892 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
893 trace.info() << "(" << nbok << "/" << nb << ")"
894 << " Point nbCreated=" << Point::nbCreated
895 << " nbDeleted=" << Point::nbDeleted << std::endl;
896 int nbC = Point::nbCreated;
897 Point::reset();
898 trace.endBlock();
899 trace.beginBlock ( "Total perimeter of triangles with by-const reference parameter passing." );
901 trace.info() << "Perimeter is " << t2 << std::endl;
902 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
903 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
904 trace.info() << "(" << nbok << "/" << nb << ")"
905 << " Point nbCreated=" << Point::nbCreated
906 << " nbDeleted=" << Point::nbDeleted << std::endl;
907 Point::reset();
908 trace.endBlock();
909 trace.beginBlock ( "Total perimeter of triangles with by Clone parameter passing." );
910 double t4 = computeTriangles<TriangleByClone>( size );
911 trace.info() << "Perimeter is " << t4 << std::endl;
912 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
913 ++nb; nbok += Point::nbCreated <= nbC ? 1 : 0;
914 trace.info() << "(" << nbok << "/" << nb << ")"
915 << " Point nbCreated=" << Point::nbCreated
916 << " nbDeleted=" << Point::nbDeleted << std::endl;
917 Point::reset();
918 trace.endBlock();
919 trace.beginBlock ( "Total perimeter of triangles with by CloneAndCow parameter passing." );
920 double t5 = computeTriangles<TriangleByCloneAndCow>( size );
921 trace.info() << "Perimeter is " << t5 << std::endl;
922 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
923 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
924 trace.info() << "(" << nbok << "/" << nb << ")"
925 << " Point nbCreated=" << Point::nbCreated
926 << " nbDeleted=" << Point::nbDeleted << std::endl;
927 Point::reset();
928 trace.endBlock();
929 trace.beginBlock ( "Total perimeter of triangles with CowPtr by CloneAndCow parameter passing." );
931 trace.info() << "Perimeter is " << t6 << std::endl;
932 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
933 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
934 trace.info() << "(" << nbok << "/" << nb << ")"
935 << " Point nbCreated=" << Point::nbCreated
936 << " nbDeleted=" << Point::nbDeleted << std::endl;
937 Point::reset();
938 trace.endBlock();
939
940 trace.endBlock();
941
942 return nb == nbok;
943}
static int nbCreated
static void reset()
static int nbDeleted
double computeTriangles(int size)
double computeTrianglesByCowPtr(int size)

References computeTriangles(), computeTrianglesByCowPtr(), MyPointD::nbCreated, MyPointD::nbDeleted, MyPointD::reset(), and DGtal::trace.

Referenced by main().

◆ testConstAliasCases()

bool testConstAliasCases ( )

ConstAlias: Performs without unnecessary duplicates "parameter -> member data"

  • const A & -> const A & // no duplication (checked)
  • const A* -> const A & // no duplication, exception if null (checked)
  • const A & -> const A* // no duplication (checked)
  • const A* -> const A* // no duplication (checked)
  • CountedPtr -> CowPtr // potential lazy duplication (checked)
  • CowPtr -> CowPtr // potential lazy duplication (checked)

Definition at line 574 of file testClone2.cpp.

575{
576 unsigned int nb = 0;
577 unsigned int nbok = 0;
578 DummyTbl a1( 100, 10 ); // +1/0
579 DummyTbl* ptr_a2 = new DummyTbl( 100, 18 ); // +1/0
580 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 100, 12 ) ); // +1/0
581 CowPtr<DummyTbl> cow_a1( new DummyTbl( 100, 16 ) ); // +1/0
583 trace.beginBlock ( "Testing class ConstAlias." );
584
585 /*
586 - const A & -> const A & // no duplication
587 - const A* -> const A & // no duplication, exception if null
588 - const A & -> const A* // no duplication
589 - const A* -> const A* // no duplication
590 - CountedPtr<A> -> CowPtr<A> // potential lazy duplication
591 - CowPtr<A> -> CowPtr<A> // potential lazy duplication
592 */
593 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl& member. no duplication (0/0)" );
594 ConstAliasToConstRefMember c00( a1 ); // 0/0
595 trace.info() << "D: d1.value() = " << c00.value() << std::endl;
596 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
597 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
598 trace.info() << "(" << nbok << "/" << nb << ")"
599 << " nbCreated=" << DummyTbl::nbCreated
600 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
601 trace.endBlock();
602
603 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl& member. no duplication (0/0)" );
604 ConstAliasToConstRefMember c10( ptr_a2 ); // 0/0
605 trace.info() << "D: d1.value() = " << c10.value() << std::endl;
606 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
607 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
608 trace.info() << "(" << nbok << "/" << nb << ")"
609 << " nbCreated=" << DummyTbl::nbCreated
610 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
611 trace.endBlock();
612
613 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl* member. no duplication (0/0)" );
614 ConstAliasToConstPtrMember c01( a1 ); // 0/0
615 trace.info() << "D: d1.value() = " << c01.value() << std::endl;
616 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
617 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
618 trace.info() << "(" << nbok << "/" << nb << ")"
619 << " nbCreated=" << DummyTbl::nbCreated
620 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
621 trace.endBlock();
622
623 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl* member. no duplication (0/0)" );
624 ConstAliasToConstPtrMember c11( ptr_a2 ); // 0/0
625 trace.info() << "D: d1.value() = " << c11.value() << std::endl;
626 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
627 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
628 trace.info() << "(" << nbok << "/" << nb << ")"
629 << " nbCreated=" << DummyTbl::nbCreated
630 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
631 trace.endBlock();
632
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;
636 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
637 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
638 trace.info() << "(" << nbok << "/" << nb << ")"
639 << " nbCreated=" << DummyTbl::nbCreated
640 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
641 trace.endBlock();
642
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;
646 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
647 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
648 trace.info() << "(" << nbok << "/" << nb << ")"
649 << " nbCreated=" << DummyTbl::nbCreated
650 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
651 trace.endBlock();
652
653 trace.beginBlock ( "ConstAlias: #DummyTbl with CountedPtr<DummyTbl> to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
654 ConstAliasToCountedConstPtrOrConstPtrMember c37( counted_a1 ); // 0/0
655 trace.info() << "D: d1.value() = " << c37.value() << std::endl;
656 ++nb; nbok += DummyTbl::nbCreated==0 ? 1 : 0;
657 ++nb; nbok += DummyTbl::nbDeleted==0 ? 1 : 0;
658 trace.info() << "(" << nbok << "/" << nb << ")"
659 << " nbCreated=" << DummyTbl::nbCreated
660 << " nbDeleted=" << DummyTbl::nbDeleted << std::endl;
661 trace.endBlock();
662
663 // These lines do not compile.
664 // DummyTbl& ref_a1 = ConstAlias<DummyTbl>( a1 );
665 // DummyTbl* ptr_a1( & ConstAlias<DummyTbl>( a1 ) );
666
667 trace.endBlock();
668
669 delete ptr_a2;
670 return nbok == nb;
671}

References DummyTbl::nbCreated, DummyTbl::nbDeleted, DummyTbl::reset(), DGtal::trace, ConstAliasToConstPtrMember::value(), ConstAliasToConstRefMember::value(), and ConstAliasToCountedConstPtrOrConstPtrMember::value().

Referenced by main().