diff options
| author | Greg Ercolano <erco@seriss.com> | 2013-12-28 22:26:22 +0000 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2013-12-28 22:26:22 +0000 |
| commit | a4550ade999c43b2a64481323f241842b33c50cc (patch) | |
| tree | daabd3c9ff76751b8fcd4b1a0af4608a026525a2 /src/Fl_Tree_Item.cxx | |
| parent | c90f1904fa6a04cecb4df23c5f28313d4f6306f6 (diff) | |
* Fixes STR#3024 issue with Fl_Tree::find_item()
* Removes redundant const vs. non-const code
using technique from Scott Meyers' book "Effective C++", 3rd Ed.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10038 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tree_Item.cxx')
| -rw-r--r-- | src/Fl_Tree_Item.cxx | 32 |
1 files changed, 8 insertions, 24 deletions
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' |
