Commit 01cf528d authored by Sylvain Thery's avatar Sylvain Thery

add checkAttribute function (get/test/add: see the doc)

parent 0da84625
......@@ -72,6 +72,14 @@ public:
template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT> getAttribute(const std::string& nameAttr) ;
/**
* check if an attribute exist ( get, test if valid and add if necessary)
* @param nameAttr attribute name
* @return an AttributeHandler
*/
template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT> checkAttribute(const std::string& nameAttr) ;
/**
* swap the content of two attributes (efficient, only swap pointers)
*/
......
......@@ -57,6 +57,17 @@ inline AttributeHandler<T ,ORBIT> AttribMap::getAttribute(const std::string& nam
return AttributeHandler<T, ORBIT>(this, amv) ;
}
template <typename T, unsigned int ORBIT>
inline AttributeHandler<T ,ORBIT> AttribMap::checkAttribute(const std::string& nameAttr)
{
AttributeHandler<T,ORBIT> att = this->getAttribute<T,ORBIT>(nameAttr);
if (!att.isValid())
att = this->addAttribute<T,ORBIT>("position");
return att;
}
template <typename T, unsigned int ORBIT>
inline bool AttribMap::swapAttributes(AttributeHandler<T, ORBIT>& attr1, AttributeHandler<T, ORBIT>& attr2)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment