[Ktechlab-devel] clarification about GenericElementFactory

Julian Bäume julian at svg4all.de
Tue Jul 27 14:31:22 UTC 2010


On Tuesday 27 July 2010 15:29:37 Zoltan Padrah wrote:
>  Hello,
> 
> In the
current implementation, the template shouldn't be instantiated
> directly.
For an example, see the basic_ec plugin:
> 
> <
>
http://ktechlab.git.sourceforge.net/git/gitweb.cgi?p=ktechlab/ktl-zoltan_p
>
;a=commitdiff;h=f4e1cb13333cbcd0f802183fe44a52df970c9a75
> 
> 
> The
DECLARE_ELEMENT_FACTORY_MEMBER macro can be used to declare a
> variable of
the template type, usually in a class.
> 
> REGISTER_ELEMENT_FACTORY creates
an instance of the above declared
> member and registers it in the
simulation manager.
> 
> UNREGISTER_ELEMENT_FACTORY unregisters the
instance.
> 
> All 3 macros take as parameter only the type of the new
element.
> 
> The template class has the parameter <class ElementType> the
new
> element type, and its constructor takes as argument the ID of the
>
element type. It's not necessary to instantiate the template manually.
> 
>
This implementation could be used from any plugin, so it should be
> moved
somewhere else, I guess in the interfaces folder.
Ahh, okay. I got it :) 

>
Other implementation, that would scale even better, could be used as
>
following:
> 
> outside of any class:
> 
> DECLARE_ELEMENT_FACTORY(
>  
FactoryName,
>   SUPPORT_ELEMENT( Element1 )
>   SUPPORT_ELEMENT( Element2
)
>   // and so on...
> );
> 
> And the plugin can look like:
> 
> class
MyPlugin : public IPlugin {
>   FactoryName *m_factory;
> 
>  MyPlugin() {
>
  m_factory = new FactoryName();
>  
ISimulationManager::self()->registerElementFactory(m_factory);
>  }
>  void
unload(){
>  
ISimulationManager::self()->unregisterElementFactory(m_factory);
>  }
> };
>

> This way, adding 1 new component takes 2 new lines in the source: one
>
for including its header, and the other to call a macro.
> 
> The
implementation of the macros could be done by using many if-s
> internally,
but that shouldn't be visible to the programmer.
> 
> Opinions about this?
I
think, I'd support that one. Looks pretty similar to what I had in mind,
some hours ago. The macro might be a little more complex, but once done, it
would be easy to add new elements. I can also imagine, that this can be
easily extended to work with scripted plugins, too.

> 2010/7/27, Julian
Bäume <julian at svg4all.de>:
> > This could look like:
> > 
> > // my cool
> >
resistor
> > implementation
> >
DECLARE_ELEMENT_FACTORY(KTechLab::Element::Resistor);
> > 
> > REGIST
> >
ER_ELEMENT_FACTORY(ElementFactory<KTechLab::Element::Resistor>);
> > 
> >
class
> > KTechLab::Element::Resistor: public IElement {
> > 
> >
	//implementation
> > 
> > };

bye then
julian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/ktechlab-devel/attachments/20100727/6fa54860/attachment.sig>


More information about the Ktechlab-devel mailing list