diff options
| -rw-r--r-- | src/Fl_Tree.cxx | 8 | ||||
| -rw-r--r-- | src/Fl_Tree_Item.cxx | 32 |
2 files changed, 11 insertions, 29 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index 0cd69904d..53dcbe515 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -997,11 +997,9 @@ void Fl_Tree::clear_children(Fl_Tree_Item *item) { /// \see item_pathname() /// Fl_Tree_Item *Fl_Tree::find_item(const char *path) { - if ( ! _root ) return(NULL); - char **arr = parse_path(path); - Fl_Tree_Item *item = _root->find_item(arr); - free_path(arr); - return(item); + // I evoke "Effective C++, 3rd Ed", p.23. Sola fide, Amen. + return(const_cast<Fl_Tree_Item*>( + static_cast<const Fl_Tree&>(*this).find_item(path))); } /// A const version of Fl_Tree::find_item(const char *path) diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx index 9c9c24678..127b531da 100644 --- a/src/Fl_Tree_Item.cxx +++ b/src/Fl_Tree_Item.cxx @@ -243,18 +243,9 @@ const Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) const { /// \returns item, or 0 if not found /// Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) { - for ( int t=0; t<children(); t++ ) { - if ( child(t)->label() ) { - if ( strcmp(child(t)->label(), *arr) == 0 ) { // match? - if ( *(arr+1) ) { // more in arr? descend - return(_children[t]->find_item(arr+1)); - } else { // end of arr? done - return(_children[t]); - } - } - } - } - return(0); + // I evoke "Effective C++, 3rd Ed", p.23. Sola fide, Amen. + return(const_cast<Fl_Tree_Item*>( + static_cast<const Fl_Tree_Item &>(*this).find_child_item(arr))); } /// Find item by descending array of \p 'names'. @@ -265,9 +256,8 @@ Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) { /// const Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) const { if ( label() && strcmp(label(), *names) == 0 ) { // match self? - if ( *(names+1) == 0 ) { // end of names, - return(this); // found ourself. - } + ++names; // skip self + if ( *names == 0 ) return(this); // end of names, found ourself } if ( children() ) { // check children.. return(find_child_item(names)); @@ -282,15 +272,9 @@ const Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) const { /// \returns item, or 0 if not found /// Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) { - if ( label() && strcmp(label(), *names) == 0 ) { // match self? - if ( *(names+1) == 0 ) { // end of names, - return(this); // found ourself. - } - } - if ( children() ) { // check children.. - return(find_child_item(names)); - } - return(0); + // I evoke "Effective C++, 3rd Ed", p.23. Sola fide, Amen. + return(const_cast<Fl_Tree_Item*>( + static_cast<const Fl_Tree_Item &>(*this).find_item(names))); } /// Find the index number for the specified \p 'item' |
