Added methods index() to find index of objects in a list.
git-svn-id: http://yate.null.ro/svn/yate/trunk@2206 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
eba177f500
commit
2a36be841a
|
@ -148,6 +148,26 @@ ObjList* ObjList::find(const String& str) const
|
|||
return const_cast<ObjList*>(n);
|
||||
}
|
||||
|
||||
int ObjList::index(const GenObject* obj) const
|
||||
{
|
||||
if (!obj)
|
||||
return -1;
|
||||
int idx = 0;
|
||||
for (const ObjList* n = this; n; n = n->next(), idx++)
|
||||
if (n->get() == obj)
|
||||
return idx;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ObjList::index(const String& str) const
|
||||
{
|
||||
int idx = 0;
|
||||
for (const ObjList* n = this; n; n = n->next(), idx++)
|
||||
if (n->get() && str.matches(n->get()->toString()))
|
||||
return idx;
|
||||
return -1;
|
||||
}
|
||||
|
||||
GenObject* ObjList::set(const GenObject* obj, bool delold)
|
||||
{
|
||||
if (m_obj == obj)
|
||||
|
|
14
yateclass.h
14
yateclass.h
|
@ -1049,6 +1049,20 @@ public:
|
|||
*/
|
||||
ObjList* find(const String& str) const;
|
||||
|
||||
/**
|
||||
* Get the position in list of a GenObject by a pointer to it
|
||||
* @param obj Pointer to the object to search for
|
||||
* @return Index of object in list, -1 if not found
|
||||
*/
|
||||
int index(const GenObject* obj) const;
|
||||
|
||||
/**
|
||||
* Get the position in list of the first GenObject with a given value
|
||||
* @param str String value (toString) of the object to search for
|
||||
* @return Index of object in list, -1 if not found
|
||||
*/
|
||||
int index(const String& str) const;
|
||||
|
||||
/**
|
||||
* Insert an object at this point
|
||||
* @param obj Pointer to the object to insert
|
||||
|
|
Loading…
Reference in New Issue