Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am having trouble understanding your requirements. But Ill state - in my own words as it were - what I understand the situation to be:</p> <ul> <li><p>You have abstract Parameter class, which is subclassed eventually to some concrete classes (eg: ParameterLimitedInt).</p></li> <li><p>You have a seperate GUI system which will be passed these parameters in a generic fashion, but the catch is that it needs to present the GUI component specific to the concrete type of the parameter class.</p></li> <li><p>The restrictions are that you dont want to do RTTID, and dont want to write code to handle every possible type of concrete parameter.</p></li> <li><p>You are open to using the visitor pattern.</p></li> </ul> <p>With those being your requirements, here is how I would handle such a situation:</p> <p>I would implement the visitor pattern where the accept() returns a boolean value. The base Parameter class would implement a virtual accept() function and return false.</p> <p>Concrete implementations of the Parameter class would then contain accept() functions which will call the visitor's visit(). They would return true.</p> <p>The visitor class would make use of a templated visit() function so you would only override for the concrete Parameter types you care to support:</p> <pre><code>class Visitor { public: template&lt; class T &gt; void visit( const T&amp; param ) const { assert( false &amp;&amp; "this parameter type not specialised in the visitor" ); } void visit( const ParameterLimitedInt&amp; ) const; // specialised implementations... } </code></pre> <p>Thus if accept() returns false, you know the concrete type for the Parameter has not implemented the visitor pattern yet (in case there is additional logic you would prefer to handle on a case by case basis). If the assert() in the visitor pattern triggers, its because its not visiting a Parameter type which you've implemented a specialisation for.</p> <p>One downside to all of this is that unsupported visits are only caught at runtime.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload