[Smtk-developers] Q: Either-or combinations of attribute items
David Thompson
david.thompson at kitware.com
Fri Nov 14 12:33:00 EST 2014
Hi all,
>> I wonder if we need a find method that is template based - like the addItemDefinition method in Definition.h ?
>
> I would have preferred to do things that way but my shiboken-fu was not up to getting the templated method wrapped (last year). I'm happy to switch the API now.
The Attribute class has changed like so:
* The find(const std::string& name) method now takes an extra argument to indicate whether items with children should have their children searched.
ItemPtr find(const std::string& name, SearchStyle style = ACTIVE_CHILDREN);
ConstItemPtr find(const std::string& name, SearchStyle style = ACTIVE_CHILDREN) const;
* There now a templated variant of the call:
template<typename T>
typename T::Ptr findAs(
const std::string& name, SearchStyle style = ACTIVE_CHILDREN);
The existing findInt(), findDouble(), ... have **not** been removed.
They are wrapped by shiboken and greatly reduce the amount of typing
required in both C++ and Python. In C++, you can use
att->findInt("outcome")
instead of
using smtk::attribute::IntItem;
att->findAs<IntItem>("outcome");
In Python, you can use
att.findInt('outcome')
instead of
smtk.attribute.to_concrete(att.find('outcome'))
* The shiboken bindings provide additional methods named find()
that do not require the second argument (shiboken does not
handle default parameters properly).
We can make further changes as needed, but this gets things working for the CreateBrickOperator so I am happy to let sleeping dogs lie.
David
More information about the Smtk-developers
mailing list