Skip to content

Commit

Permalink
9 ➡️ 10 (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennuine authored Apr 29, 2021
2 parents f310d75 + 9ca2153 commit 1b49119
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
7 changes: 7 additions & 0 deletions include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ namespace sdf
/// \return True if the attribute is set, false otherwise.
public: bool GetAttributeSet(const std::string &_key) const;

/// \brief Remove an attribute.
/// \param[in] _key the key of the attribute.
public: void RemoveAttribute(const std::string &_key);

/// \brief Removes all attributes.
public: void RemoveAllAttributes();

/// \brief Get the param of the elements value
/// return A Param pointer to the value of this element.
public: ParamPtr GetValue() const;
Expand Down
2 changes: 1 addition & 1 deletion sdf/1.4/surface.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</element>

<element name="collide_bitmask" type="unsigned int" default="1" required="0">
<description>Bitmask for collision filtering. This will override collide_without_contact</description>
<description>Bitmask for collision filtering. This will override collide_without_contact. Parsed as 16-bit unsigned integer.</description>
</element>

<element name="ode" required="0">
Expand Down
2 changes: 1 addition & 1 deletion sdf/1.5/surface.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</element>

<element name="collide_bitmask" type="unsigned int" default="65535" required="0">
<description>Bitmask for collision filtering. This will override collide_without_contact</description>
<description>Bitmask for collision filtering. This will override collide_without_contact. Parsed as 16-bit unsigned integer.</description>
</element>

<element name="poissons_ratio" type="double" default="0.3" required="0">
Expand Down
4 changes: 2 additions & 2 deletions sdf/1.6/surface.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@
</element>

<element name="collide_bitmask" type="unsigned int" default="65535" required="0">
<description>Bitmask for collision filtering. This will override collide_without_contact</description>
<description>Bitmask for collision filtering. This will override collide_without_contact. Parsed as 16-bit unsigned integer.</description>
</element>

<element name="category_bitmask" type="unsigned int" default="65535" required="0">
<description><![CDATA[Bitmask for category of collision filtering. Collision happens if ((category1 & collision2) | (category2 & collision1)) is not zero. If not specified, the category_bitmask should be interpreted as being the same as collide_bitmask.]]></description>
<description><![CDATA[Bitmask for category of collision filtering. Collision happens if ((category1 & collision2) | (category2 & collision1)) is not zero. If not specified, the category_bitmask should be interpreted as being the same as collide_bitmask. Parsed as 16-bit unsigned integer.]]></description>
</element>

<element name="poissons_ratio" type="double" default="0.3" required="0">
Expand Down
4 changes: 2 additions & 2 deletions sdf/1.7/surface.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@
</element>

<element name="collide_bitmask" type="unsigned int" default="65535" required="0">
<description>Bitmask for collision filtering. This will override collide_without_contact</description>
<description>Bitmask for collision filtering. This will override collide_without_contact. Parsed as 16-bit unsigned integer.</description>
</element>

<element name="category_bitmask" type="unsigned int" default="65535" required="0">
<description><![CDATA[Bitmask for category of collision filtering. Collision happens if ((category1 & collision2) | (category2 & collision1)) is not zero. If not specified, the category_bitmask should be interpreted as being the same as collide_bitmask.]]></description>
<description><![CDATA[Bitmask for category of collision filtering. Collision happens if ((category1 & collision2) | (category2 & collision1)) is not zero. If not specified, the category_bitmask should be interpreted as being the same as collide_bitmask. Parsed as 16-bit unsigned integer.]]></description>
</element>

<element name="poissons_ratio" type="double" default="0.3" required="0">
Expand Down
21 changes: 21 additions & 0 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,27 @@ bool Element::GetAttributeSet(const std::string &_key) const
return result;
}

/////////////////////////////////////////////////
void Element::RemoveAttribute(const std::string &_key)
{
Param_V::const_iterator iter;
for (iter = this->dataPtr->attributes.begin();
iter != this->dataPtr->attributes.end(); ++iter)
{
if ((*iter)->GetKey() == _key)
{
this->dataPtr->attributes.erase(iter);
break;
}
}
}

/////////////////////////////////////////////////
void Element::RemoveAllAttributes()
{
this->dataPtr->attributes.clear();
}

/////////////////////////////////////////////////
ParamPtr Element::GetAttribute(const std::string &_key) const
{
Expand Down
34 changes: 34 additions & 0 deletions src/Element_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,40 @@ TEST(Element, GetAttributeSet)
EXPECT_TRUE(elem.GetAttributeSet("test"));
}

/////////////////////////////////////////////////
TEST(Element, RemoveAttribute)
{
sdf::Element elem;
ASSERT_EQ(elem.GetAttributeCount(), 0UL);

elem.AddAttribute("test", "string", "foo", false, "foo description");
elem.AddAttribute("attr", "float", "0.0", false, "float description");
ASSERT_EQ(elem.GetAttributeCount(), 2UL);

elem.RemoveAttribute("test");
EXPECT_EQ(elem.GetAttributeCount(), 1UL);
EXPECT_EQ(elem.GetAttribute("test"), nullptr);
EXPECT_NE(elem.GetAttribute("attr"), nullptr);
}

/////////////////////////////////////////////////
TEST(Element, RemoveAllAttributes)
{
sdf::Element elem;
ASSERT_EQ(elem.GetAttributeCount(), 0UL);

elem.AddAttribute("test", "string", "foo", false, "foo description");
elem.AddAttribute("test2", "string", "foo", false, "foo description");
elem.AddAttribute("attr", "float", "0.0", false, "float description");
ASSERT_EQ(elem.GetAttributeCount(), 3UL);

elem.RemoveAllAttributes();
EXPECT_EQ(elem.GetAttributeCount(), 0UL);
EXPECT_EQ(elem.GetAttribute("test"), nullptr);
EXPECT_EQ(elem.GetAttribute("test2"), nullptr);
EXPECT_EQ(elem.GetAttribute("attr"), nullptr);
}

/////////////////////////////////////////////////
TEST(Element, Include)
{
Expand Down

0 comments on commit 1b49119

Please sign in to comment.