<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Prvni dotaz - proc to neni tak, ze IDev
je predek a ma membery virtual, takze pak neni treba to saseni s
tim castovanim?</div>
<div class="moz-cite-prefix">Druhy dotaz - proc jsou tam pointery v
tom poli a ne reference? A proc se to castuje 2x?<br>
<br>
Tj. pak se to zkrati na neco jako<br>
rc = devs[deviceIndex].setSomeParam( param );<br>
if( rc )<br>
g_lastError = devs[deviceIndex].lastError();<br>
<br>
A setSomeParam bud udelat s promennym poctem argumentu, nebo
radeji asi s default argumenty a tak, aby pro vsechna zarizeni
byla stejna.<br>
J.<br>
<br>
</div>
<div class="moz-cite-prefix">On 25.09.2023 13:03, Pavel Hudeček
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:d3caeb56-12fd-2d52-965f-c11c9fd3b716@seznam.cz">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Dobrý den všem,<br>
mějme funkci jako<br>
<br>
<font face="Courier New, Courier, monospace">int
doSomeWithDev(unsigned deviceIndex, int param)<br>
{<br>
std::vector<IDev*> devs = gDevs->devices();<br>
IDev* dev = devs[deviceIndex];<br>
IDevTyp* devt = dynamic_cast<IDevTyp*>(dev);<br>
if (!devt)<br>
return </font><font face="Courier New, Courier,
monospace">UNEXPECTED_ERROR;<br>
int rc;<br>
IDevTyp2* devT2;<br>
IDevTyp3* devT3;<br>
#ifdef IDevTyp4<br>
IDevTyp4* devT4;<br>
#endif<br>
<br>
switch(devt->deviceType()) {<br>
case DEVTYPE2:<br>
tevT2 = dynamic_cast<IDevTyp2*>(dev);<br>
if (!tevT2)<br>
return </font><font face="Courier New, Courier,
monospace">UNEXPECTED_ERROR;<br>
rc = tevT2->setSomeParam(</font><font
face="Courier New, Courier, monospace"><font face="Courier New,
Courier, monospace">param</font>);<br>
if (rc){<br>
gLastError = tevT2->lastError();<br>
}<br>
break;<br>
case DEVTYPE3:<br>
tevT3 = dynamic_cast<IDevTyp3*>(dev);<br>
if (!tevT3)<br>
return UNEXPECTED_ERROR;<br>
rc = tevT3-></font><font face="Courier New,
Courier, monospace"><font face="Courier New, Courier, monospace">setSomeParam(</font><font
face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace">param</font>);</font><br>
if (rc){<br>
gLastError = tevT3->lastError();<br>
}<br>
break;<br>
#ifdef IDevTyp4<br>
case DEVTYPE4:<br>
tevT4 = dynamic_cast<IDevTyp4*>(dev);<br>
if (!tevT4)<br>
return UNEXPECTED_ERROR;<br>
rc = tevT4-></font><font face="Courier New,
Courier, monospace"><font face="Courier New, Courier, monospace"><font
face="Courier New, Courier, monospace">setSomeParam(</font><font
face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace">param</font>);<br>
</font></font> if (rc<0) {<br>
gLastError = tevT4->lastError();<br>
}<br>
break;<br>
#endif<br>
default:<br>
gLastError = "Unexpected device type";<br>
rc = UNEXPECTED_ERROR;<br>
break;<br>
}<br>
return rc;<br>
}<br>
</font><br>
A takových má být mnoho, s odlišnostmi jen v tom, co bude místo<br>
<font face="Courier New, Courier, monospace">-></font><font
face="Courier New, Courier, monospace"><font face="Courier New,
Courier, monospace">setSomeParam(</font><font face="Courier
New, Courier, monospace"><font face="Courier New, Courier,
monospace">param</font>);</font></font><br>
a kolik to bude mít parametrů.<br>
<br>
Chtěl bych to nějak zjednodušit, aby ty funkce nebyly tak dlouhý.<br>
Nějaké nápady?<br>
<br>
Díky,<br>
PH<br>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
HW-list mailing list - sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz">www.HW.cz</a>
<a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
Jindroush <a class="moz-txt-link-rfc2396E" href="mailto:jindroush@seznam.cz"><jindroush@seznam.cz></a></pre>
</body>
</html>