<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Creating our own predicates]]></title><description><![CDATA[<p dir="auto">Dear all,</p>
<p dir="auto">I have created a bunch of classes deriving from SAMSON's. I would like now to implement something similar to:</p>
<pre><code>SBMStructuralModelNodeRoot* root = getStructuralRoot();
SBNodeIndexer nodeIndexer;
root-&gt;getNodes(nodeIndexer, SBNode::IsType(SBNode::Atom));
</code></pre>
<p dir="auto">But using my own types instead of <em>SBNode::Types</em>. I have been taking a look at how is this implemented for samson classes, but I could not get it to work. I guess I'm missing something and I appreciate if someone points me in the right direction.</p>
<p dir="auto">Best regards,</p>
<p dir="auto">Elisa</p>
]]></description><link>https://forum.samson-connect.net/topic/56/creating-our-own-predicates</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 11:55:16 GMT</lastBuildDate><atom:link href="https://forum.samson-connect.net/topic/56.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Jun 2018 16:48:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Creating our own predicates on Mon, 18 Jun 2018 21:38:28 GMT]]></title><description><![CDATA[<p dir="auto">Thank you!  Using the GetClass and GetElementUUID methods is enough for my purposes :)</p>
]]></description><link>https://forum.samson-connect.net/post/184</link><guid isPermaLink="true">https://forum.samson-connect.net/post/184</guid><dc:creator><![CDATA[Elisa]]></dc:creator><pubDate>Mon, 18 Jun 2018 21:38:28 GMT</pubDate></item><item><title><![CDATA[Reply to Creating our own predicates on Sun, 17 Jun 2018 16:45:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi Elisa,</p>
<p dir="auto">The <code>SBNode::IsType</code> class is a node predicate (i.e. a class with a member function <code>bool operator()(SBNode*)</code>) that checks the enum returned by the <code>SBNode::getType()</code> function and compares it to the type passed to the constructor of <code>SBNode::IsType</code>. The list of node types is predefined and you cannot change it at the moment (since <code>SBNode::Type</code> is an enum).</p>
<p dir="auto">One possibility might be to hack the system: you can try to overload the <code>getType</code> function of your node to write something like</p>
<pre><code>SBNode::Type MyNode::getType() const { return (SBNode::Type)3216546; // return a unique identifier for this node type }
</code></pre>
<p dir="auto">I'm not sure this is gonna work on all compilers (will the cast convert the number to another one?). Moreover, you don't know what other developers are going to do, and if your SAMSON Element is used in conjunction with one that also adopts this hack and, unfortunately, because of bad luck you use the same identifier, then this might create issues.</p>
<p dir="auto">Normally, it seems you should be able to use other existing node predicates. For example, a SAMSON Element UUID is supposed to be unique (this is imposed on SAMSON Connect), and the name of an exposed class inside a SAMSON Element is unique as well. So the pair (class name, element UUID) should be unique. Thus, you should be able to find your nodes with something like this:</p>
<pre><code>SBMStructuralModelNodeRoot* root = getStructuralRoot();
SBNodeIndexer nodeIndexer;
root-&gt;getNodes(nodeIndexer, (SBNode::GetClass() == std::string("MyNode")) &amp;&amp; (SBNode::GetElementUUID() == SBUUID("F03D2ED2-C93B-C86E-C66E-01A776229839")));
</code></pre>
<p dir="auto">Hope this helps. If you indeed need to write new predicates let me know and I'll give some details.</p>
<p dir="auto">Stephane</p>
]]></description><link>https://forum.samson-connect.net/post/183</link><guid isPermaLink="true">https://forum.samson-connect.net/post/183</guid><dc:creator><![CDATA[Stephane]]></dc:creator><pubDate>Sun, 17 Jun 2018 16:45:44 GMT</pubDate></item></channel></rss>