mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
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();
|
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.
|
* Removes the specified index from the array.
|
||||||
*
|
*
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
|
|
||||||
size_t GetLength(void) const;
|
size_t GetLength(void) const;
|
||||||
|
|
||||||
|
void Insert(unsigned int index, const Value& value);
|
||||||
void Remove(unsigned int index);
|
void Remove(unsigned int index);
|
||||||
void Remove(Iterator it);
|
void Remove(Iterator it);
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ add_boost_test(base
|
|||||||
LIBRARIES base config icinga
|
LIBRARIES base config icinga
|
||||||
TESTS base_array/construct
|
TESTS base_array/construct
|
||||||
base_array/getset
|
base_array/getset
|
||||||
|
base_array/insert
|
||||||
base_array/remove
|
base_array/remove
|
||||||
base_array/foreach
|
base_array/foreach
|
||||||
base_array/clone
|
base_array/clone
|
||||||
|
@ -53,6 +53,27 @@ BOOST_AUTO_TEST_CASE(getset)
|
|||||||
BOOST_CHECK(array->Get(1) == 5);
|
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)
|
BOOST_AUTO_TEST_CASE(remove)
|
||||||
{
|
{
|
||||||
Array::Ptr array = make_shared<Array>();
|
Array::Ptr array = make_shared<Array>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user