DGtal 1.3.0
Loading...
Searching...
No Matches
Namespaces | Typedefs | Functions
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"

Go to the source code of this file.

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

Initial value:
{
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Examples
arithmetic/lower-integer-convex-hull.cpp, dec/exampleHeatLaplace.cpp, dec/examplePropagation.cpp, doc-examples/exampleCatch.cpp, geometry/curves/convex-and-concave-parts.cpp, geometry/curves/estimation/exampleLMST2D.cpp, geometry/curves/estimation/exampleLMST3D.cpp, geometry/curves/exampleArithDSS3d.cpp, geometry/curves/exampleArithmeticalDSL.cpp, geometry/curves/exampleArithmeticalDSS.cpp, geometry/curves/exampleDSLSubsegment.cpp, geometry/curves/exampleRationalConvexity.cpp, geometry/surfaces/dvcm-2d-curvature.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/tools/checkLatticeBallQuickHull.cpp, geometry/tools/determinant/exampleInHalfPlane.cpp, geometry/tools/exampleAlphaShape.cpp, geometry/tools/exampleConvexHull2D.cpp, geometry/volumes/checkFullConvexityTheorems.cpp, geometry/volumes/digitalPolyhedronBuilder3D.cpp, geometry/volumes/distance/exampleFMM2D.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/fullConvexityShortestPaths3D.cpp, geometry/volumes/fullConvexitySphereGeodesics.cpp, geometry/volumes/standardDigitalPolyhedronBuilder3D.cpp, graph/graphTraversal.cpp, images/exampleConstImageAdapter.cpp, io/boards/dgtalBoard2D-2-sets.cpp, io/boards/dgtalBoard3D-2-ks.cpp, io/boards/dgtalBoard3D-6-clipping.cpp, io/boards/dgtalBoard3DTo2D-2-sets.cpp, io/boards/dgtalBoard3DTo2D-2bis-sets.cpp, io/boards/dgtalBoard3DTo2D-3-objects.cpp, io/boards/dgtalBoard3DTo2D-6.cpp, io/boards/dgtalBoard3DTo2D-KSCell.cpp, io/boards/exampleBezierCurve.cpp, io/boards/logoDGtal.cpp, io/viewers/viewer3D-10-interaction.cpp, io/viewers/viewer3D-2-sets.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-4bis-illustrationMode.cpp, io/viewers/viewer3D-6-clipping.cpp, io/viewers/viewer3D-7-planes.cpp, io/viewers/viewer3D-7-stdplane.cpp, io/viewers/viewer3D-7bis-planes.cpp, io/viewers/viewer3D-7bis-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, and topology/generateSimplicityTables2D.cpp.

Definition at line 383 of file testClone2.cpp.

Function Documentation

◆ computeTriangles()

template<typename Triangle >
double computeTriangles ( int  size)

Definition at line 428 of file testClone2.cpp.

429{
430 double total = 0.0;
431 Point A( 0, 0 );
432 for ( int yb = 0; yb < size; ++yb )
433 for ( int xb = 0; xb < size; ++xb )
434 {
435 Point B( xb, yb );
436 for ( int yc = 0; yc < size; ++yc )
437 for ( int xc = 0; xc < size; ++xc )
438 {
439 Point C( xc, yc );
440 Triangle T( A, B, C );
441 total += T.perimeter();
442 }
443 }
444 return total;
445}
Represents an unoriented triangle as three vertices.
MyPointD Point
Definition: testClone2.cpp:383

◆ computeTrianglesByCowPtr()

template<typename Triangle >
double computeTrianglesByCowPtr ( int  size)

Definition at line 449 of file testClone2.cpp.

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

◆ main()

int main ( void  )

Definition at line 947 of file testClone2.cpp.

948{
949 bool ok = true
950 && testCloneCases()
952 && testAliasCases()
954
955 return ok ? 0 : 1;
956}
bool testAliasCases()
Definition: testClone2.cpp:477
bool testCloneTimings()
Definition: testClone2.cpp:884
bool testCloneCases()
Definition: testClone2.cpp:693
bool testConstAliasCases()
Definition: testClone2.cpp:576

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 477 of file testClone2.cpp.

478{
479 unsigned int nb = 0;
480 unsigned int nbok = 0;
481 DummyTbl a1( 100, 10 ); // +1/0
482 DummyTbl* ptr_a2 = new DummyTbl( 100, 18 ); // +1/0
483 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 100, 12 ) ); // +1/0
484 DummyTbl::reset();
485 trace.beginBlock ( "Testing class Alias." );
486
487 /*
488 - A& -> A& // no duplication
489 - A* -> A& // no duplication, exception if null
490 - A& -> A* // no duplication
491 - A* -> A* // no duplication
492 - CountedPtr<A> -> CountedPtr<A> // shared
493 */
494 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to DummyTbl& member. no duplication (0/0)" );
495 AliasToRefMember c00( a1 ); // 0/0
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;
502 trace.endBlock();
503
504 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to DummyTbl& member. no duplication (0/0)" );
505 AliasToRefMember c10( ptr_a2 ); // 0/0
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;
512 trace.endBlock();
513
514 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to DummyTbl* member. no duplication (0/0)" );
515 AliasToPtrMember c01( a1 ); // 0/0
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;
522 trace.endBlock();
523
524 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to DummyTbl* member. no duplication (0/0)" );
525 AliasToPtrMember c11( ptr_a2 ); // 0/0
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;
532 trace.endBlock();
533
534 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl& to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
535 AliasToCountedPtrOrPtrMember c06( a1 ); // 0/0
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;
543 trace.endBlock();
544
545 trace.beginBlock ( "Alias: #DummyTbl with DummyTbl* to CountedPtrOrPtr<DummyTbl> member. no duplication (0/0)" );
546 AliasToCountedPtrOrPtrMember c16( a1 ); // 0/0
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;
554 trace.endBlock();
555
556 // const DummyTbl& const_a1 = a1;
557 // AliasToRefMember c02( const_a1 ); // does not execute.
558 // const DummyTbl* const_ptr_a1 = &a1;
559 // AliasToRefMember c05( const_ptr_a1 ); // does not execute.
560
561 trace.endBlock();
562
563 delete ptr_a2;
564 return nbok == nb;
565}
Aim: Smart pointer based on reference counts.
Definition: CountedPtr.h:80
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

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 693 of file testClone2.cpp.

694{
695 unsigned int nb = 0;
696 unsigned int nbok = 0;
697 DummyTbl a1( 50, 10 ); // +1/0
698 CowPtr<DummyTbl> cow_a1( new DummyTbl( 50, 5 ) ); // +1/0
699 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 50, 12 ) ); // +1/0
700 DummyTbl::reset();
701 trace.beginBlock ( "Testing class Clone." );
702
703
704 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to DummyTbl member. Duplication (+1/0)" );
705 CloneToValueMember c00( a1 ); // +1/0
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;
712 trace.endBlock();
713
714 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl member. Duplication (+1/0)" );
715 CloneToValueMember c30( a1 ); // +1/0
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;
722 trace.endBlock();
723
724 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to CountedPtr<DummyTbl> member. Duplication (+1/0)" );
725 CloneToCountedMember c03( a1 ); // +1/0
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;
732 trace.endBlock();
733
734 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl &) to CowPtr<DummyTbl> member. Duplication (+1/0)" );
735 CloneToCowMember c02( a1 ); // +1/0
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;
742 trace.endBlock();
743
744 trace.beginBlock ( "Clone: #DummyTbl with (CowPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
745 CloneToCowMember c22( cow_a1 ); // +0/0
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;
752 c22.setValue( 17 );
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;
760 trace.endBlock();
761
762 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl> &) to CowPtr<DummyTbl> member. Lazy duplication (0/0)" );
763 CloneToCowMember c32( counted_a1 ); // +0/0
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;
770 c32.setValue( 21 );
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;
778 trace.endBlock();
779
780 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to DummyTbl member. Acquisition, duplication, delete (+2/+1)" );
781 CloneToValueMember c10( new DummyTbl( 50, 2 ) ); // +2/+1
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;
788 trace.endBlock();
789
790 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to CowPtr<DummyTbl> member. Acquisition, no duplication (+1/0)" );
791 CloneToCowMember c12( new DummyTbl( 50, 15 ) ); // +1/0
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;
798 trace.endBlock();
799
800 trace.beginBlock ( "Clone: #DummyTbl with (const DummyTbl&) to DummyTbl* member. Duplication (+1/0)" );
801 CloneToPtrMember c01( a1 ); // +1/0
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;
808 trace.endBlock();
809
810 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl*) to DummyTbl* member. Acquisition (+1/0)" );
811 CloneToPtrMember c11( new DummyTbl( 50, 42 ) ); // +1/0
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;
818 trace.endBlock();
819
820 trace.beginBlock ( "Clone: #DummyTbl with (CowPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
821 CloneToPtrMember c21( cow_a1 ); // +1/0
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;
828 trace.endBlock();
829
830 trace.beginBlock ( "Clone: #DummyTbl with (CountedPtr<DummyTbl>) to DummyTbl* member. Duplication (+1/0)" );
831 CloneToPtrMember c31( counted_a1 ); // +1/0
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;
838 trace.endBlock();
839
840 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to DummyTbl member. Duplication by move (+2/+1/+1)" );
841 CloneToValueMember c40( DummyTbl( 50, -4 ) ); // +2/+1/+1
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
850 << std::endl;
851 trace.endBlock();
852
853 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to CowPtr<DummyTbl> member. Duplication by move (+2/+1/+1)" );
854 CloneToCowMember c42( DummyTbl( 50, -9 ) ); // +2/+1/+1
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
863 << std::endl;
864 trace.endBlock();
865
866 trace.beginBlock ( "Clone: #DummyTbl with (DummyTbl &&) to DummyTbl* member. Duplication by move (+2/+1/+1)" );
867 CloneToCowMember c41( DummyTbl( 50, -12 ) ); // +2/+1/+1
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
876 << std::endl;
877 trace.endBlock();
878
879 trace.endBlock();
880
881 return nbok == nb;
882}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testCloneTimings()

bool testCloneTimings ( )

Definition at line 884 of file testClone2.cpp.

885{
886 unsigned int nb = 0;
887 unsigned int nbok = 0;
888 int size = 10;
889 trace.beginBlock ( "Testing Clone timings." );
890
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;
899 Point::reset();
900 trace.endBlock();
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;
909 Point::reset();
910 trace.endBlock();
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;
919 Point::reset();
920 trace.endBlock();
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;
929 Point::reset();
930 trace.endBlock();
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;
939 Point::reset();
940 trace.endBlock();
941
942 trace.endBlock();
943
944 return nb == nbok;
945}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), 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 576 of file testClone2.cpp.

577{
578 unsigned int nb = 0;
579 unsigned int nbok = 0;
580 DummyTbl a1( 100, 10 ); // +1/0
581 DummyTbl* ptr_a2 = new DummyTbl( 100, 18 ); // +1/0
582 CountedPtr<DummyTbl> counted_a1( new DummyTbl( 100, 12 ) ); // +1/0
583 CowPtr<DummyTbl> cow_a1( new DummyTbl( 100, 16 ) ); // +1/0
584 DummyTbl::reset();
585 trace.beginBlock ( "Testing class ConstAlias." );
586
587 /*
588 - const A & -> const A & // no duplication
589 - const A* -> const A & // no duplication, exception if null
590 - const A & -> const A* // no duplication
591 - const A* -> const A* // no duplication
592 - CountedPtr<A> -> CowPtr<A> // potential lazy duplication
593 - CowPtr<A> -> CowPtr<A> // potential lazy duplication
594 */
595 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl& member. no duplication (0/0)" );
596 ConstAliasToConstRefMember c00( a1 ); // 0/0
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;
603 trace.endBlock();
604
605 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl& member. no duplication (0/0)" );
606 ConstAliasToConstRefMember c10( ptr_a2 ); // 0/0
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;
613 trace.endBlock();
614
615 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl& to const DummyTbl* member. no duplication (0/0)" );
616 ConstAliasToConstPtrMember c01( a1 ); // 0/0
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;
623 trace.endBlock();
624
625 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl* to const DummyTbl* member. no duplication (0/0)" );
626 ConstAliasToConstPtrMember c11( ptr_a2 ); // 0/0
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;
633 trace.endBlock();
634
635 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl* to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
636 ConstAliasToCountedConstPtrOrConstPtrMember c17( ptr_a2 ); // 0/0
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;
643 trace.endBlock();
644
645 trace.beginBlock ( "ConstAlias: #DummyTbl with const DummyTbl& to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
646 ConstAliasToCountedConstPtrOrConstPtrMember c07( a1 ); // 0/0
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;
653 trace.endBlock();
654
655 trace.beginBlock ( "ConstAlias: #DummyTbl with CountedPtr<DummyTbl> to CountedConstPtrOrConstPtr<DummyTbl> member. No duplication (0/0)" );
656 ConstAliasToCountedConstPtrOrConstPtrMember c37( counted_a1 ); // 0/0
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;
663 trace.endBlock();
664
665 // These lines do not compile.
666 // DummyTbl& ref_a1 = ConstAlias<DummyTbl>( a1 );
667 // DummyTbl* ptr_a1( & ConstAlias<DummyTbl>( a1 ) );
668
669 trace.endBlock();
670
671 delete ptr_a2;
672 return nbok == nb;
673}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().