From 93cfa2ea4f55dbdde68b0c77e7836127cc3072fc Mon Sep 17 00:00:00 2001
From: graham <g.macpherson@opencfd.co.uk>
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 9f142e710bb..2d94b9c29d4 100644
--- a/src/lagrangian/basic/Particle/Particle.C
+++ b/src/lagrangian/basic/Particle/Particle.C
@@ -528,6 +528,34 @@ void Foam::Particle<ParticleType>::hitPatch
 {}
 
 
+// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
+
+template<class ParticleType>
+bool Foam::operator==
+(
+    const Particle<ParticleType>& pA,
+    const Particle<ParticleType>& pB
+)
+{
+    return
+    (
+        pA.origProc() == pB.origProc()
+        && pA.origId() == pB.origId()
+    );
+}
+
+
+template<class ParticleType>
+bool Foam::operator!=
+(
+    const Particle<ParticleType>& pA,
+    const Particle<ParticleType>& pB
+)
+{
+    return !(pA == pB);
+}
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #include "ParticleIO.C"
diff --git a/src/lagrangian/basic/Particle/Particle.H b/src/lagrangian/basic/Particle/Particle.H
index 95a4b8e338f..e91a4885d37 100644
--- a/src/lagrangian/basic/Particle/Particle.H
+++ b/src/lagrangian/basic/Particle/Particle.H
@@ -59,6 +59,8 @@ class polyPatch;
 template<class ParticleType>
 class Particle;
 
+// Friend Operators
+
 template<class ParticleType>
 Ostream& operator<<
 (
@@ -66,6 +68,11 @@ Ostream& operator<<
     const Particle<ParticleType>&
 );
 
+template<class ParticleType>
+bool operator==(const Particle<ParticleType>&, const Particle<ParticleType>&);
+
+template<class ParticleType>
+bool operator!=(const Particle<ParticleType>&, const Particle<ParticleType>&);
 
 /*---------------------------------------------------------------------------*\
                            Class Particle Declaration
@@ -467,13 +474,25 @@ public:
         //- Write the particle data
         void write(Ostream& os, bool writeFields) const;
 
-    // Ostream Operator
+    // Friend Operators
 
         friend Ostream& operator<< <ParticleType>
         (
             Ostream&,
             const Particle<ParticleType>&
         );
+
+        friend bool operator== <ParticleType>
+        (
+            const Particle<ParticleType>& pA,
+            const Particle<ParticleType>& pB
+        );
+
+        friend bool operator!= <ParticleType>
+        (
+            const Particle<ParticleType>& pA,
+            const Particle<ParticleType>& pB
+        );
 };
 
 
-- 
GitLab