From bbb88e330c2ef6af6decaeb78fd697043038fd09 Mon Sep 17 00:00:00 2001 From: graham Date: Wed, 7 Apr 2010 17:23:17 +0100 Subject: [PATCH] ENH: Adding operator== and operator!= to Particle. Basing equality on the origProc and origId or the particle only. --- src/lagrangian/basic/Particle/Particle.C | 28 ++++++++++++++++++++++++ src/lagrangian/basic/Particle/Particle.H | 21 +++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/lagrangian/basic/Particle/Particle.C b/src/lagrangian/basic/Particle/Particle.C index 101f653d0f..ae0b46361d 100644 --- a/src/lagrangian/basic/Particle/Particle.C +++ b/src/lagrangian/basic/Particle/Particle.C @@ -873,6 +873,34 @@ void Foam::Particle::hitPatch {} +// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // + +template +bool Foam::operator== +( + const Particle& pA, + const Particle& pB +) +{ + return + ( + pA.origProc() == pB.origProc() + && pA.origId() == pB.origId() + ); +} + + +template +bool Foam::operator!= +( + const Particle& pA, + const Particle& pB +) +{ + return !(pA == pB); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "ParticleIO.C" diff --git a/src/lagrangian/basic/Particle/Particle.H b/src/lagrangian/basic/Particle/Particle.H index c4e4e24e53..bc0385e3b8 100644 --- a/src/lagrangian/basic/Particle/Particle.H +++ b/src/lagrangian/basic/Particle/Particle.H @@ -59,6 +59,8 @@ class polyPatch; template class Particle; +// Friend Operators + template Ostream& operator<< ( @@ -66,6 +68,11 @@ Ostream& operator<< const Particle& ); +template +bool operator==(const Particle&, const Particle&); + +template +bool operator!=(const Particle&, const Particle&); /*---------------------------------------------------------------------------*\ Class Particle Declaration @@ -505,13 +512,25 @@ public: //- Write the particle data void write(Ostream& os, bool writeFields) const; - // Ostream Operator + // Friend Operators friend Ostream& operator<< ( Ostream&, const Particle& ); + + friend bool operator== + ( + const Particle& pA, + const Particle& pB + ); + + friend bool operator!= + ( + const Particle& pA, + const Particle& pB + ); };