Make AddGroup() unique.

Refs #6105
This commit is contained in:
Michael Friedrich 2014-05-02 00:38:46 +02:00
parent e04d200d36
commit 7e164291a0
4 changed files with 21 additions and 0 deletions

View File

@ -108,6 +108,20 @@ size_t Array::GetLength(void) const
return m_Data.size();
}
/**
* Checks whether the array contains the specified value.
*
* @param value The value.
* @returns true if the array contains the value, false otherwise.
*/
bool Array::Contains(const String& value) const
{
ASSERT(!OwnsLock());
ObjectLock olock(this);
return (std::find(m_Data.begin(), m_Data.end(), value) != m_Data.end());
}
/**
* Insert the given value at the specified index
*

View File

@ -50,6 +50,7 @@ public:
Iterator End(void);
size_t GetLength(void) const;
bool Contains(const String& value) const;
void Insert(unsigned int index, const Value& value);
void Remove(unsigned int index);

View File

@ -94,6 +94,9 @@ void Checkable::AddGroup(const String& name)
Array::Ptr groups = GetGroups();
if (groups && groups->Contains(name))
return;
if (!groups)
groups = make_shared<Array>();

View File

@ -75,6 +75,9 @@ void User::AddGroup(const String& name)
Array::Ptr groups = GetGroups();
if (groups && groups->Contains(name))
return;
if (!groups)
groups = make_shared<Array>();