"indexListOf" (vector::indexListOf / dyn_*::indexListOf)
Returns a list of indexes at which the given value was found.
Synopsis
vector int vector.indexListOf(T value);
vector int vector.indexListOf(string memberName, T value);
vector int vector.indexListOf(function_ptr memberFunc, T value);
Parameters
Parameter | Description |
---|---|
value | Value that is searched for |
memberName | class member used for comparison |
memberFunc | class member function used for comparison |
Description
Returns a list of indexes at which the given value was found.
If the vector holds class instances or shared_ptr to class instances, the given memberName is used inside the class and compared to the given value. The function returns a list of indexes where a match was found. The checked member can be public, private or protected.
When the vector holds class-instances (or shared_ptr to class instances), the given memberFunc is called with every instance in the vector, passing the given value, and when the class member function returns true, the index of this object in the vector will be added to the result list.
With this flexible way, the class author can implement whatever check he likes to have. Note that this member function must not contain any function call of a waiting function (e.g. dpGet(), delay(), etc.).
The member function therefore should be as short as possible since it will be executed in a non-interuptable way - the whole manager will block when the function contains code which lasts too long (e.g. endless loop).
The member function must be public and non-static.
class TestClass
{
public TestClass(string str = "") { s = str; }
public string getValue() { return s; }
public bool match(string str) { return s == str; }
private string s;
}
main()
{
vector<TestClass> vec;
... fill vec with data ...
vector<int> list = vec.indexListOf(TestClass::match, "test value");
DebugN(list);
}
Assignment
Vector / dyn_*