[DEV] add API to remove attribute

This commit is contained in:
Edouard DUPIN 2015-12-17 22:15:49 +01:00
parent 410df0f81e
commit f8d9fe305e
2 changed files with 29 additions and 3 deletions

View File

@ -72,7 +72,7 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
if (_name.size() == 0) {
return false;
}
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
for (size_t iii=0; iii<m_listAttribute.size(); ++iii) {
if( m_listAttribute[iii] != nullptr
&& m_listAttribute[iii]->getName() == _name) {
return true;
@ -81,9 +81,28 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
return false;
}
bool exml::AttributeList::removeAttribute(const std::string& _name) {
if (_name.size() == 0) {
return false;
}
auto it = m_listAttribute.begin();
while (it != m_listAttribute.end()) {
if (*it == nullptr) {
it = m_listAttribute.erase(it);
continue;
}
if((*it)->getName() == _name) {
it = m_listAttribute.erase(it);
return true;
}
it++;
}
return false;
}
void exml::AttributeList::setAttribute(const std::string& _name, const std::string& _value) {
// check if attribute already det :
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
for (size_t iii=0; iii<m_listAttribute.size(); ++iii) {
if( m_listAttribute[iii] != nullptr
&& m_listAttribute[iii]->getName() == _name) {
// update the value :

View File

@ -70,11 +70,18 @@ namespace exml {
*/
bool existAttribute(const std::string& _name) const;
/**
* @brief Sen A new attribute or replace data of the previous one
* @brief Set A new attribute or replace data of the previous one
* @param[in] _name Name of the attribute
* @param[in] _value Value of the attribute
*/
void setAttribute(const std::string& _name, const std::string& _value);
/**
* @brief Remove an attribute form the list
* @param[in] _name Name of the attribute
* @return true The attribute has been removed
* @return false An error occured.
*/
bool removeAttribute(const std::string& _name);
public: // herited function:
bool iGenerate(std::string& _data, int32_t _indent) const;
virtual void clear();