[Clam-devel] TypedControls: asking for advice and opinions

Hernán Ordiales h at ordia.com.ar
Thu Jun 26 20:18:47 PDT 2008


Hi gang,

First, some context, Francisco was working in a new typedcontrols
patch and an issue arose that I would like to share and ask for
opinions.
Since the last work regarding to get a common interface for
registering controls with the same interface (i.e.BaseTypedControls)
this ended up requiring a dynamic_cast in every DoControl() call in
the processing code because now the signature of GetInControl (at
Processing class) is like:
  BaseTypedInControl & GetInControl( const std::string & name )

for example, now is required:
		dynamic_cast<TypedInControl<float>*>(&(mPitchShift.GetInControl("PitchSteps")))->DoControl(amount);
instead of
		mPitchShift.GetInControl("PitchSteps").DoControl(amount);

(btw, DoControl() is not defined in BaseTypedControl since should be
templatized too)

Well, so now I'm asking for opinions on the best way to avoid this
(since i think is to much overhead for a framework code), I have some
ideas, but let me know if you have new/better ones or what you think
is best.

What i thought:

* Make the Processing class templatized and do the dynamic cast inside
the get function and returning a TypednControl

* Make templatized the TypedInControlRegistry and do something like:
mPitchShift.GetInControls().Get("PitchSteps").DoControl(amount);
(with Get() returning a TypednControl)

* Add a virtual DoControl in BaseTypedInControl and in TypedInControl
something like:
template<class TypedControlData>
void TypedInControl<TypedControlData>::DoControl(void* val)
{
	try {
		TypedControlData* data = reinterpret_cast<TypedControlData*>(val);
		this->DoControl(*data);
	}
	catch(...)
	{
		CLAM_ASSERT( false, "DoControl could not cast to TypedControlData*" );
	}
}
(or directly mLastValue = *data instead of this->DoControl(*data) to
avoid another function call)

* Some macro (#define ...)?

* Put your idea here :-D

note: I'm not sending the current francisco's patch because is a
little big (the idea is to reduce it, but is not so simple) and is not
ready for commitment either (has some minor problems and is full of
needed dynamic castings related with DoControl() which i'd like to
avoid as i previously told)

Cheers!
-- 
Hernán
http://h.ordia.com.ar
GnuPG: 0xEE8A3FE9




More information about the clam-devel mailing list