Added new method index()

This commit is contained in:
Pål Hagen 2015-08-10 16:57:16 +02:00
parent 6941db21af
commit 319d9a1aa7
2 changed files with 13 additions and 0 deletions

View File

@ -76,6 +76,7 @@ public:
size_t count(const DataType* pointer) const;
void erase(size_t index);
size_t index(DataType* pointer);
// Child objects

View File

@ -141,6 +141,18 @@ void PdmChildArrayField<DataType*>::erase(size_t index)
}
}
//--------------------------------------------------------------------------------------------------
/// Get the index of the given object pointer
//--------------------------------------------------------------------------------------------------
template<typename DataType>
size_t PdmChildArrayField<DataType*>::index(DataType* pointer)
{
typename std::vector< PdmPointer<DataType> >::iterator it = std::find(m_pointers.begin(), m_pointers.end(), pointer);
return it - m_pointers.begin();
}
//--------------------------------------------------------------------------------------------------
/// Removes all instances of object pointer from the container without deleting the object.
//--------------------------------------------------------------------------------------------------