[DEV] add API to remove attribute
This commit is contained in:
parent
410df0f81e
commit
f8d9fe305e
@ -72,7 +72,7 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
|
|||||||
if (_name.size() == 0) {
|
if (_name.size() == 0) {
|
||||||
return false;
|
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
|
if( m_listAttribute[iii] != nullptr
|
||||||
&& m_listAttribute[iii]->getName() == _name) {
|
&& m_listAttribute[iii]->getName() == _name) {
|
||||||
return true;
|
return true;
|
||||||
@ -81,9 +81,28 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
|
|||||||
return false;
|
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) {
|
void exml::AttributeList::setAttribute(const std::string& _name, const std::string& _value) {
|
||||||
// check if attribute already det :
|
// 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
|
if( m_listAttribute[iii] != nullptr
|
||||||
&& m_listAttribute[iii]->getName() == _name) {
|
&& m_listAttribute[iii]->getName() == _name) {
|
||||||
// update the value :
|
// update the value :
|
||||||
|
@ -70,11 +70,18 @@ namespace exml {
|
|||||||
*/
|
*/
|
||||||
bool existAttribute(const std::string& _name) const;
|
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] _name Name of the attribute
|
||||||
* @param[in] _value Value of the attribute
|
* @param[in] _value Value of the attribute
|
||||||
*/
|
*/
|
||||||
void setAttribute(const std::string& _name, const std::string& _value);
|
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:
|
public: // herited function:
|
||||||
bool iGenerate(std::string& _data, int32_t _indent) const;
|
bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user