<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to CtorParameters</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>Recent changes to CtorParameters</description><atom:link href="https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 01 Apr 2015 14:57:35 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/feed" rel="self" type="application/rss+xml"/><item><title>Discussion for CtorParameters page</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Originally posted by: &lt;a class="" href="http://code.google.com/u/105171042695370489777" rel="nofollow"&gt;fabien.c...@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;1- You are right about the Init function. &lt;/p&gt;
&lt;p&gt;2- I am playing right now with wallaroo and I dont have enough perspective for #1 or #2 solution. &lt;/p&gt;
&lt;p&gt;The input ParameterSet&lt;a class="" href="/p/wallaroo/w/edit/ParameterSet"&gt;?&lt;/a&gt; as argument is good because it is very easy to manipulate and changing its content. This can be also a trap : weak-typing is the beginning of the end ... &lt;/p&gt;
&lt;p&gt;Attribute injection is heavy but the AtttributeOk&lt;a class="" href="/p/wallaroo/w/edit/AtttributeOk"&gt;?&lt;/a&gt;() check is a good structural check. I have a little preference for this one but you're the leader, your call :) &lt;/p&gt;
&lt;p&gt;Thanks anyway &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.net7056c459f5634afc5de23bf85bcf8ba342a2bb40</guid></item><item><title>Discussion for CtorParameters page</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Originally posted by: &lt;a class="" href="http://code.google.com/u/116451853037125231743" rel="nofollow"&gt;daniele....@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I expanded a bit the explanation of Device::Init. Hope it's more clear, now. &lt;/p&gt;
&lt;p&gt;If we go for solution #1 I'll develop a wallaroo version of any, thanks. &lt;/p&gt;
&lt;p&gt;Yes: I guess Plug and Attribute are different concepts... I really wouldn't like to create confusion (read: bugs :-) in the mind of the user. Anyway: the syntax is important but now I'd prefer to focus on the choice of the best solution, whether they're feasible, whether there is any problem in the implementation (e.g. with shared libraries usage) and so on... &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.netf57a7ba8f3aad83f0678d14dedb6432e1578e4e2</guid></item><item><title>Discussion for CtorParameters page</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Originally posted by: &lt;a class="" href="http://code.google.com/u/105171042695370489777" rel="nofollow"&gt;fabien.c...@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;"I am wondering if there is a good reason to adopt the pair Attribute/set...of...to instead of extending the Plug concept ... ". &lt;/p&gt;
&lt;p&gt;I really think the Plug and Attribute concepts are different : Attribute belongs to the instance while Plug belongs to the usage of the instance. &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.net4ecd8bdcc8dbec331846f55fdb39e933cc8907b3</guid></item><item><title>Discussion for CtorParameters page</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Originally posted by: &lt;a class="" href="http://code.google.com/u/105171042695370489777" rel="nofollow"&gt;fabien.c...@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;last thing : I dont understand the Device::Init usage ... Could you be more specific? &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.net4fc73144f2257f54e8a41545d742197bfb4b7d5b</guid></item><item><title>Discussion for CtorParameters page</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Originally posted by: &lt;a class="" href="http://code.google.com/u/105171042695370489777" rel="nofollow"&gt;fabien.c...@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Good start :) &lt;/p&gt;
&lt;p&gt;Remark 1: &lt;/p&gt;
&lt;p&gt;If you dont want a dependancy to boost, may be you could use a minimal "any" class like that : &lt;a href="http://stackoverflow.com/questions/4988939/how-do-boostvariant-and-boostany-work" rel="nofollow"&gt;http://stackoverflow.com/questions/4988939/how-do-boostvariant-and-boostany-work&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Remark 2: &lt;/p&gt;
&lt;p&gt;The other solution could be to wrap all basic types (int, long, double, string, etc.) as a Plug itself, or keeping the Attribute concept. So instead of &lt;/p&gt;
&lt;p&gt;use( "bar" ).as( "b" ).of( "foo" ); &lt;/p&gt;
&lt;p&gt;one could write : &lt;/p&gt;
&lt;p&gt;use( "red" ).as( "color" ).of( "foo" ); or use( 42 ).as( "number" ).of( "foo" ); &lt;/p&gt;
&lt;p&gt;This implied to modify a bit the use func. &lt;/p&gt;
&lt;p&gt;I am wondering if there is a good reason to adopt the pair Attribute/set...of...to instead of extending the Plug concept ... &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.neted521169763b039796cb9be4683177dca44b2674</guid></item><item><title>CtorParameters modified by Anonymous</title><link>https://sourceforge.net/p/wallaroolib/wiki/CtorParameters/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="notes-on-ctor-parameters-of-wallaroo-managed-classes"&gt;Notes on ctor parameters of wallaroo managed classes&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt; This page is obsolete: &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attributes have been added to wallaroo. &lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Currently (v. 0.5 - april 2014), the main limit of &lt;strong&gt;wallaroo&lt;/strong&gt; is the maximum number of constructor parameters a managed class can have (i.e. two). Besides, a class defined in a dynamic library must have a constructor without parameters. &lt;/p&gt;
&lt;p&gt;Removing this limit could be the last activity before finally bring the release number to 1.0 &lt;/p&gt;
&lt;p&gt;This wiki page contains some notes about this topic. &lt;/p&gt;
&lt;h2 id="the-problem"&gt;The problem&lt;/h2&gt;
&lt;p&gt;Currently, wallaroo only manages classes (&lt;code&gt;part&lt;/code&gt;s) having constructors with 0, 1 or 2 parameters. Besides, the limit for classes defined in shared libraries is stricter: they must have a default constructor. &lt;/p&gt;
&lt;p&gt;This limit is due to the following problems: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;some wallaroo classes are parametrized on the two constructor parameters, with specialization for the &lt;code&gt;void&lt;/code&gt; case; &lt;/li&gt;
&lt;li&gt;the creation mechanism of wallaroo is based on template: in particular, it needs the class name (&lt;code&gt;string&lt;/code&gt;) and the type of the two constructor parameters (template parameters, possibly &lt;code&gt;void&lt;/code&gt;). In a configuration file you need to specify all these three piece of information. No problem for the class name (it's a string!), but the parameters must be converted from strings to types, providing all the possible permutations (see file &lt;code&gt;ptreebasedcfg.h&lt;/code&gt;). Incrementing the parameters number would produce an exponential increment of the combinations. &lt;/li&gt;
&lt;li&gt;shared libraries export a list of descriptors of all the classes defined inside. The descriptors have a pointer to the class factory function: one must decide one single function signature for all classes. I choosed to fix it to have no parameters. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The current code has also some advantages: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you can declare class constructors in the traditional way (no extra verbosity) &lt;/li&gt;
&lt;li&gt;you can invoke &lt;code&gt;Catalog::Create&lt;/code&gt; directly with the parameters of the object you want to create (no extra verbosity) &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="solution-requirements"&gt;Solution requirements&lt;/h2&gt;
&lt;p&gt;Wallaroo needs a mechanism to pass an arbitrary number of parameters when constructing an object (a &lt;code&gt;part&lt;/code&gt; in wallaroo parlance). The solution should have the following properties: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it must work with both the construction methods (by code and by configuration file), &lt;/li&gt;
&lt;li&gt;it must work with both the class declaration methods (single executable and shared libraries), &lt;/li&gt;
&lt;li&gt;it should be compatible with the current code, &lt;/li&gt;
&lt;li&gt;it should not require &lt;code&gt;boost&lt;/code&gt; libraries in those cases where now are not needed &lt;br /&gt;
(the last two points are just preferences). &lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="solutions"&gt;Solutions&lt;/h2&gt;
&lt;p&gt;Here are explained a list of candidate solutions. &lt;/p&gt;
&lt;h3 id="parameters-table"&gt;Parameters table&lt;/h3&gt;
&lt;p&gt;We can pass a table of named parameters to the ctor (e.g.: &lt;code&gt;std::map&amp;lt; std::string, boost::any &amp;gt;&lt;/code&gt; ). This means: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;we should do more work to fill the map and to extract the parameters &lt;/li&gt;
&lt;li&gt;we give up the requirement #4 (we need to use &lt;code&gt;boost::any&lt;/code&gt; everywhere), unless we develop our own version of &lt;code&gt;any&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To simplify the usage, we could provide a &lt;code&gt;ParameterSet&lt;/code&gt; class that incapsulate the &lt;code&gt;map&lt;/code&gt;, hiding the use of &lt;code&gt;any&lt;/code&gt;: &lt;/p&gt;
&lt;p&gt;E.g. (class definition) &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Part&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ParameterSet&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nl"&gt;private:&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;WALLAROO_REGISTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// register this class&lt;/span&gt;

&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ParameterSet&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"color"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"number"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;E.g. (usage) &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;Catalog&lt;/span&gt; &lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;ParameterSet&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"color"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pars&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When using a configuration file (xml, json), we have two options: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;specify in the configuration file the type of each parameter (so that we can insert the right type in the &lt;code&gt;any&lt;/code&gt; object) &lt;/li&gt;
&lt;li&gt;don't specify the type of the parameters: in this way, we have to store strings inside the parameter table, and then convert it to the right type inside the constructor (who else know the type of the parameters?!) &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="const-attributes-injection"&gt;Const attributes injection&lt;/h3&gt;
&lt;p&gt;We can use a mechanism similar to &lt;code&gt;wallaroo::Collaborator&lt;/code&gt; to add &lt;code&gt;const&lt;/code&gt; attributes to the class. &lt;/p&gt;
&lt;p&gt;This way, an object would be created without parameters, then its const attributes filled using an injection mechanism imilar to the one used for dependencies. &lt;/p&gt;
&lt;p&gt;E.g. (class definition) &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Part&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;virtual&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nl"&gt;private:&lt;/span&gt;
    &lt;span class="n"&gt;Collaborator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;Bar&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;Attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;Attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;WALLAROO_REGISTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// register this class&lt;/span&gt;

&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;RegistrationToken&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;RegistrationToken&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"number"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;RegistrationToken&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;E.g. (usage) &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;Catalog&lt;/span&gt; &lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Foo"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"bar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bar"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// option #1&lt;/span&gt;
&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt; &lt;span class="p"&gt;][&lt;/span&gt; &lt;span class="s"&gt;"color"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt; &lt;span class="p"&gt;][&lt;/span&gt; &lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;wallaroo_within&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;catalog&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"bar"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"b"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// option #2&lt;/span&gt;
    &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"color"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"foo"&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// check if all collaborators are wired&lt;/span&gt;
&lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsWiringOk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// check if all attributes are set&lt;/span&gt;
&lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AreAttributesOk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// calls the method Init of each parts&lt;/span&gt;
&lt;span class="c1"&gt;// maybe it would be better to call IsWiringOk &lt;/span&gt;
&lt;span class="c1"&gt;// and AreAttributesOk inside Catalog::Init() ?&lt;/span&gt;
&lt;span class="n"&gt;catalog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Is this feasible in the first place? &lt;/p&gt;
&lt;p&gt;Please note that in traditional programming the constructor parameters are possibly used inside the body of the constructor; with this approach, instead, the attributes are not yet set during the parts constructor execution. A possible workaround for this issue is to provide some kind of &lt;code&gt;Part::Init&lt;/code&gt; method where doing the actual part setup work that require the attributes. A &lt;code&gt;Catalog::Init&lt;/code&gt; method could call &lt;code&gt;Part::Init&lt;/code&gt; for each part contained. &lt;/p&gt;
&lt;p&gt;When using a configuration file (xml, json), we still have two options: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;specify in the configuration file the type of each parameter (so that we can insert the right type in the statement &lt;code&gt;set( "attribute_name" ).of( "part_name" ).to( object );&lt;/code&gt;); &lt;/li&gt;
&lt;li&gt;don't specify the type of the parameters: the function &lt;code&gt;to&lt;/code&gt; can take a string and the conversion to the right type can be operated inside the &lt;code&gt;Attribute&amp;lt;T&amp;gt;&lt;/code&gt; class (that knows the actual type - T). &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="other-solutions"&gt;Other solutions?&lt;/h3&gt;
&lt;p&gt;Suggestions are welcome :-) &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 01 Apr 2015 14:57:35 -0000</pubDate><guid>https://sourceforge.net627390784819f3f16d62055ac5ab4c82fd6cc4c5</guid></item></channel></rss>