Mercurial > code
changeset 234:99f8b9aedfb3
TreeNode: add child index to search a children
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 25 Jun 2014 12:58:29 +0200 |
parents | 29eb8748b686 |
children | 0e3ccc204bc2 |
files | C++/TreeNode.h |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/TreeNode.h Tue Jun 24 17:19:03 2014 +0200 +++ b/C++/TreeNode.h Wed Jun 25 12:58:29 2014 +0200 @@ -213,6 +213,21 @@ } /** + * Find a children in this. The type must have operator==. + * + * @param child the child + * @return the index or -1 if not found + */ + int childIndex(const T &child) + { + for (int i = 0; i < (int)m_children.size(); ++i) + if (m_children[i] == child) + return i; + + return -1; + } + + /** * Access a children. * * @param index the index