On ds, 2008-05-10 at 13:29 -0300, Francisco Tufró wrote:
> If you pass them by reference you can't do a SendControl(1) because
> that is passed by copy.
> So, i got confused with your mail.
> Read:
> > out.SendControl(1); won't work because the signature wants reference
> > to a non-constant var! And we need it to work, for backwards
> > compatibility among other reasons.

Yes, and keep reading :-)

> > So change the test passing a constant, and pass the test by changing
> > SendControl and DoControl arguments to be const references.
        
> So, i think what pau meant is that the class is passed by copy.
> If you pass it by reference you can't do a SendControl(1).
> So please talk with each other and tell me what to do :(

No, we both are saying the same.
Ok, i guess the confusion lies in "passing tokens by copy (opposed to
passing a reference)" vs "passing method arguments by copy". We want the
first but not the second. that is, we want to do a copy of the sent
token but only one copy, at the receiving point.

To make it crystal clear see this patch. This keeps the tests green.
(the patch has been commited).
Makes sense now?

Pau

Index: CLAM/test/UnitTests/TypedControlsTests/TypedControlsTests.cxx
===================================================================
--- CLAM/test/UnitTests/TypedControlsTests/TypedControlsTests.cxx	(revision 11379)
+++ CLAM/test/UnitTests/TypedControlsTests/TypedControlsTests.cxx	(working copy)
@@ -19,8 +19,7 @@
 		void testTypedInControl_DoControl_ChangesInternalState()
 		{
 			CLAM::TypedInControl<int> in("IntInControl");
-			int number=1;
-			in.DoControl(number);
+			in.DoControl(1);
 			CPPUNIT_ASSERT_EQUAL( 1, in.GetLastValue() );
 		}
 
@@ -29,8 +28,7 @@
 			CLAM::TypedInControl<int> in("IntInControl");
 			CLAM::TypedOutControl<int> out("IntOutControl");
 			out.AddLink(in);
-			int number=1;
-			out.SendControl(number);
+			out.SendControl(1);
 			CPPUNIT_ASSERT_EQUAL( 1 , in.GetLastValue() );
 		}
 
Index: CLAM/src/Flow/Controls/TypedInControl.hxx
===================================================================
--- CLAM/src/Flow/Controls/TypedInControl.hxx	(revision 11379)
+++ CLAM/src/Flow/Controls/TypedInControl.hxx	(working copy)
@@ -10,22 +10,21 @@
 	{
 	protected:
 		std::string mName;
-		TypedControlData* mLastValue;
+		TypedControlData mLastValue;
 		
 	public:
 		TypedInControl(const std::string &name);
 		~TypedInControl();
 		
-		void DoControl(TypedControlData& val);
+		void DoControl(const TypedControlData& val);
 		const std::string& GetName() const { return mName; }
-		TypedControlData& GetLastValue();
+		const TypedControlData& GetLastValue();
 	}; // End TypedInControl Class
 	
 	// TypedInControl Class Implementation
 	template<class TypedControlData>
 	TypedInControl<TypedControlData>::TypedInControl(const std::string &name)
 		: mName(name)
-		, mLastValue(0)
 	{
 	}
 	
@@ -35,15 +34,15 @@
 	}
 
 	template<class TypedControlData>
-	void TypedInControl<TypedControlData>::DoControl(TypedControlData& val)
+	void TypedInControl<TypedControlData>::DoControl(const TypedControlData& val)
 	{
-		mLastValue = &val;
+		mLastValue = val;
 	}
 
 	template<class TypedControlData>
-	TypedControlData& TypedInControl<TypedControlData>::GetLastValue()
+	const TypedControlData& TypedInControl<TypedControlData>::GetLastValue()
 	{
-		return *mLastValue;
+		return mLastValue;
 	}
 	
 	
Index: CLAM/src/Flow/Controls/TypedOutControl.hxx
===================================================================
--- CLAM/src/Flow/Controls/TypedOutControl.hxx	(revision 11379)
+++ CLAM/src/Flow/Controls/TypedOutControl.hxx	(working copy)
@@ -23,7 +23,7 @@
 
 		void AddLink(TypedInControl<TypedControlData>& in);
 		void RemoveLink(TypedInControl<TypedControlData>& in);
-		void SendControl(TypedControlData& val);
+		void SendControl(const TypedControlData& val);
 	};
 	
 	template<class TypedControlData>
@@ -53,7 +53,7 @@
 	}
 
 	template<class TypedControlData>
-	void TypedOutControl<TypedControlData>::SendControl(TypedControlData& val)
+	void TypedOutControl<TypedControlData>::SendControl(const TypedControlData& val)
 	{
 		typename ProperTypedInControlList::iterator it;
 		
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel

Reply via email to