Creating our own predicates



  • Dear all,

    I have created a bunch of classes deriving from SAMSON's. I would like now to implement something similar to:

    SBMStructuralModelNodeRoot* root = getStructuralRoot();
    SBNodeIndexer nodeIndexer;
    root->getNodes(nodeIndexer, SBNode::IsType(SBNode::Atom));
    

    But using my own types instead of SBNode::Types. 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.

    Best regards,

    Elisa



  • Hi Elisa,

    The SBNode::IsType class is a node predicate (i.e. a class with a member function bool operator()(SBNode*)) that checks the enum returned by the SBNode::getType() function and compares it to the type passed to the constructor of SBNode::IsType. The list of node types is predefined and you cannot change it at the moment (since SBNode::Type is an enum).

    One possibility might be to hack the system: you can try to overload the getType function of your node to write something like

    SBNode::Type MyNode::getType() const { return (SBNode::Type)3216546; // return a unique identifier for this node type }
    

    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.

    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:

    SBMStructuralModelNodeRoot* root = getStructuralRoot();
    SBNodeIndexer nodeIndexer;
    root->getNodes(nodeIndexer, (SBNode::GetClass() == std::string("MyNode")) && (SBNode::GetElementUUID() == SBUUID("F03D2ED2-C93B-C86E-C66E-01A776229839")));
    

    Hope this helps. If you indeed need to write new predicates let me know and I'll give some details.

    Stephane



  • Thank you! Using the GetClass and GetElementUUID methods is enough for my purposes :)


Log in to reply
 

Looks like your connection to SAMSON Connect - Forum was lost, please wait while we try to reconnect.