DGtal 1.3.0
Loading...
Searching...
No Matches
Typedefs | Functions
testCloneAndAliases.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.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.

Typedefs

typedef MyPoint Point
 

Functions

template<typename Triangle >
double computeTriangles (int size)
 
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 testCloneAndAliases.cpp.

Typedef Documentation

◆ Point

typedef MyPoint Point

Definition at line 185 of file testCloneAndAliases.cpp.

Function Documentation

◆ computeTriangles()

template<typename Triangle >
double computeTriangles ( int  size)

Definition at line 219 of file testCloneAndAliases.cpp.

220{
221 double total = 0.0;
222 Point A( 0, 0 );
223 for ( int yb = 0; yb < size; ++yb )
224 for ( int xb = 0; xb < size; ++xb )
225 {
226 Point B( xb, yb );
227 for ( int yc = 0; yc < size; ++yc )
228 for ( int xc = 0; xc < size; ++xc )
229 {
230 Point C( xc, yc );
231 Triangle T( A, B, C );
232 total += T.perimeter();
233 }
234 }
235 return total;
236}
Represents an unoriented triangle as three vertices.
MyPointD Point
Definition: testClone2.cpp:383

◆ main()

int main ( void  )

Definition at line 272 of file testCloneAndAliases.cpp.

273{
274 unsigned int nb = 0;
275 unsigned int nbok = 0;
276 trace.beginBlock ( "Number of A1 instances with standard by-value parameter passing." );
277 A1 a1( 10 ); // +1/ 0
278 DByValue d1( a1 ); // +2/+1
279 trace.info() << "D: d1.value() = " << d1.value() << std::endl;
280 ++nb; nbok += A1::nbCreated==3 ? 1 : 0;
281 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
282 trace.info() << "(" << nbok << "/" << nb << ")"
283 << " nbCreated=" << A1::nbCreated
284 << " nbDeleted=" << A1::nbDeleted << std::endl;
285 trace.endBlock();
286 trace.beginBlock ( "Number of A1 instances with explicit by-value parameter passing (Clone)." );
287 DByClone dd1( a1 ); // +1/0
288 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
289 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
290 trace.info() << "(" << nbok << "/" << nb << ")"
291 << " nbCreated=" << A1::nbCreated
292 << " nbDeleted=" << A1::nbDeleted << std::endl;
293 trace.endBlock();
294 trace.beginBlock ( "Number of A1 instances with explicit by-reference parameter passing (Alias)." );
295 EByAlias e1( a1 ); // +0/0
296 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
297 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
298 trace.info() << "(" << nbok << "/" << nb << ")"
299 << " nbCreated=" << A1::nbCreated
300 << " nbDeleted=" << A1::nbDeleted << std::endl;
301 trace.endBlock();
302 trace.beginBlock ( "Number of A1 instances with explicit by-const reference parameter passing (Alias)." );
303 EByConstAlias ee1( a1 ); // +0/0
304 ++nb; nbok += A1::nbCreated==4 ? 1 : 0;
305 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
306 trace.info() << "(" << nbok << "/" << nb << ")"
307 << " nbCreated=" << A1::nbCreated
308 << " nbDeleted=" << A1::nbDeleted << std::endl;
309 trace.endBlock();
310 trace.beginBlock ( "Number of A1 instances with explicit by-value parameter passing into heap (Clone)." );
311 FByCloneHeap fe1( a1 ); // +1/0
312 ++nb; nbok += A1::nbCreated==5 ? 1 : 0;
313 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
314 trace.info() << "(" << nbok << "/" << nb << ")"
315 << " nbCreated=" << A1::nbCreated
316 << " nbDeleted=" << A1::nbDeleted << std::endl;
317 trace.endBlock();
318 trace.beginBlock ( "Number of A1 instances with explicit by-value parameter passing into CowPtr (Clone)." );
319 FByCloneCowPtr fe3( a1 ); // +1/0
320 ++nb; nbok += A1::nbCreated==6 ? 1 : 0;
321 ++nb; nbok += A1::nbDeleted==1 ? 1 : 0;
322 trace.info() << "(" << nbok << "/" << nb << ")"
323 << " nbCreated=" << A1::nbCreated
324 << " nbDeleted=" << A1::nbDeleted << std::endl;
325 trace.endBlock();
326
327 int size = 20;
328 trace.beginBlock ( "Total perimeter of triangles with by-value parameter passing." );
329 double t1 = computeTriangles<TriangleByValue>( size );
330 trace.info() << "Perimeter is " << t1 << std::endl;
331 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
332 trace.info() << "(" << nbok << "/" << nb << ")"
333 << " Point nbCreated=" << Point::nbCreated
334 << " nbDeleted=" << Point::nbDeleted << std::endl;
335 int nbC = Point::nbCreated;
336 Point::reset();
337 trace.endBlock();
338 trace.beginBlock ( "Total perimeter of triangles with by-const reference parameter passing." );
339 double t2 = computeTriangles<TriangleByConstReference>( size );
340 trace.info() << "Perimeter is " << t2 << std::endl;
341 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
342 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
343 trace.info() << "(" << nbok << "/" << nb << ")"
344 << " Point nbCreated=" << Point::nbCreated
345 << " nbDeleted=" << Point::nbDeleted << std::endl;
346 Point::reset();
347 trace.endBlock();
348 trace.beginBlock ( "Total perimeter of triangles with by Clone parameter passing." );
349 double t3 = computeTriangles<TriangleByClone>( size );
350 trace.info() << "Perimeter is " << t3 << std::endl;
351 ++nb; nbok += Point::nbCreated == Point::nbDeleted ? 1 : 0;
352 ++nb; nbok += Point::nbCreated < nbC ? 1 : 0;
353 trace.info() << "(" << nbok << "/" << nb << ")"
354 << " Point nbCreated=" << Point::nbCreated
355 << " nbDeleted=" << Point::nbDeleted << std::endl;
356 Point::reset();
357 trace.endBlock();
358
359 // These two lines should not compile.
360 // Clone<A1> clone1( a1 );
361 // Clone<A1> clone2( clone2 );
362
363 return ( nb == nbok ) ? 0 : 1;
364}
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.