mirror of https://github.com/Icinga/icinga2.git
Merge branch 'feature/Array-insert-functionality' into next
resolves #5320
This commit is contained in:
parent
1119c2f17b
commit
9229aa4948
|
@ -108,6 +108,22 @@ size_t Array::GetLength(void) const
|
|||
return m_Data.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the given value at the specified index
|
||||
*
|
||||
* @param index The index
|
||||
* @param value The value to add
|
||||
*/
|
||||
void Array::Insert(unsigned int index, const Value& value)
|
||||
{
|
||||
ASSERT(!OwnsLock());
|
||||
ObjectLock olock(this);
|
||||
|
||||
ASSERT(index <= m_Data.size());
|
||||
|
||||
m_Data.insert(m_Data.begin() + index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified index from the array.
|
||||
*
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
|
||||
size_t GetLength(void) const;
|
||||
|
||||
void Insert(unsigned int index, const Value& value);
|
||||
void Remove(unsigned int index);
|
||||
void Remove(Iterator it);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ add_boost_test(base
|
|||
LIBRARIES base config icinga
|
||||
TESTS base_array/construct
|
||||
base_array/getset
|
||||
base_array/insert
|
||||
base_array/remove
|
||||
base_array/foreach
|
||||
base_array/clone
|
||||
|
|
|
@ -53,6 +53,27 @@ BOOST_AUTO_TEST_CASE(getset)
|
|||
BOOST_CHECK(array->Get(1) == 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(insert)
|
||||
{
|
||||
Array::Ptr array = make_shared<Array>();
|
||||
|
||||
array->Insert(0, 11);
|
||||
array->Insert(1, 22);
|
||||
BOOST_CHECK(array->GetLength() == 2);
|
||||
BOOST_CHECK(array->Get(1) == 22);
|
||||
|
||||
array->Insert(0, 33);
|
||||
BOOST_CHECK(array->GetLength() == 3);
|
||||
BOOST_CHECK(array->Get(0) == 33);
|
||||
BOOST_CHECK(array->Get(1) == 11);
|
||||
|
||||
array->Insert(1, 44);
|
||||
BOOST_CHECK(array->GetLength() == 4);
|
||||
BOOST_CHECK(array->Get(0) == 33);
|
||||
BOOST_CHECK(array->Get(1) == 44);
|
||||
BOOST_CHECK(array->Get(2) == 11);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(remove)
|
||||
{
|
||||
Array::Ptr array = make_shared<Array>();
|
||||
|
|
Loading…
Reference in New Issue