* 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
This commit is contained in:
parent
c90f1904fa
commit
a4550ade99
@ -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)
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user