[PATCH] Add IDebugger::Variable::operator==



While hacking on something else, I felt the need to have an equality
operator on IDebugger::Variable.  That operator would consider
two variables having the same GDB variable object ID as being equal.
Otherwise, if they don't have GDB variable object ID (in case they are
not backed up by a GDB variable object) the operator would recursively
compare the values of each member (sub-variable).

Fixed thus, tested and applied to master.  Note that this new operator
is used by subsequent patches to come.

commit 934d9eb7481033a6e98aa5cb9bb4ceff66208a2d
Author: Dodji Seketeli <dodji seketeli org>
Date:   Tue Feb 14 00:16:28 2012 +0100

    Add IDebugger::Variable::operator==
    
    	* src/dbgengine/nmv-i-debugger.h
    	(IDebugger::Variable::operator==): Make this public and implement
    	it.
    	(IDebugger::Variable::equals): New function.

diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 39dc248..3bfcbd1 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -372,9 +372,6 @@ public:
         Variable (const Variable &);
         Variable& operator= (const Variable &);
 
-        bool operator == (Variable &a_other) const;
-        bool operator == (Variable &a_other);
-
         VariableList m_members;
         // If this variable was created with a backend counterpart
         // (e.g: backend side variable objects in GDB), then this
@@ -548,6 +545,23 @@ public:
             THROW ("fatal: should not be reached");
         }
 
+        bool operator == (const Variable &a_other) const
+        {
+            return equals (a_other);
+        }
+
+        // Tests if this variable equals another one, by first
+        // considering the variables' internal names, if they have
+        // any.  Otherwise, tests if they are equal by value, i.e,
+        // compare them memberwise.
+        bool equals (const Variable &a_other) const
+        {
+            if (!internal_name ().empty ()
+                && !a_other.internal_name ().empty ())
+                return internal_name () == a_other.internal_name ();
+            return equals_by_value (a_other);
+        }
+
         /// Tests value equality between two variables.
         /// Two variables are considered equal by value if their
         /// respective memebers have the same values and same type.

-- 
		Dodji


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]