summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2002-09-05 20:44:36 +0000
committerMatthias Melcher <fltk@matthiasm.com>2002-09-05 20:44:36 +0000
commit6698be1be81a2c98707b4842022f1075e9b082a0 (patch)
treecb93b0d56124169d294dbb64ea2ff1b893fb4923
parent32b9640e1ca9ce14f802309ad7818c23910dc62c (diff)
Mac OS X: modified Fl_Preferences::Node::search to correctly handle groups
inside the root group and to allow for relative and absolute path names. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2619 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Preferences.H6
-rw-r--r--documentation/Fl_Preferences.html3
-rw-r--r--src/Fl_Preferences.cxx43
-rw-r--r--test/preferences.fl25
4 files changed, 64 insertions, 13 deletions
diff --git a/FL/Fl_Preferences.H b/FL/Fl_Preferences.H
index 5897a736a..228c21bb0 100644
--- a/FL/Fl_Preferences.H
+++ b/FL/Fl_Preferences.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Preferences.H,v 1.1.2.10 2002/08/27 03:03:34 easysw Exp $"
+// "$Id: Fl_Preferences.H,v 1.1.2.11 2002/09/05 20:44:35 matthiaswm Exp $"
//
// Preferences definitions for the Fast Light Tool Kit (FLTK).
//
@@ -112,7 +112,7 @@ private:
// node methods
int write( FILE *f );
Node *find( const char *path );
- Node *search( const char *path );
+ Node *search( const char *path, int offset=0 );
Node *addChild( const char *path );
void setParent( Node *parent );
char remove();
@@ -157,5 +157,5 @@ private:
#endif // !Fl_Preferences_H
//
-// End of "$Id: Fl_Preferences.H,v 1.1.2.10 2002/08/27 03:03:34 easysw Exp $".
+// End of "$Id: Fl_Preferences.H,v 1.1.2.11 2002/09/05 20:44:35 matthiaswm Exp $".
//
diff --git a/documentation/Fl_Preferences.html b/documentation/Fl_Preferences.html
index 88dd21ace..b5ce6a4b0 100644
--- a/documentation/Fl_Preferences.html
+++ b/documentation/Fl_Preferences.html
@@ -161,6 +161,9 @@ by <tt>groups()</tt>.
<H4><a name="Fl_Preferences.groupExists">int Fl_Preferences::groupExists(const char *groupname)</a></H4>
<P>Returns non-zero if a group with this name exists.
+Groupnames are relative to the Preferences node and can contain a path.
+<tt>"."</tt> describes the current node, <tt>"./"</tt> describes the topmost node.
+By preceding a groupname with a <tt>"./"</tt>, its path becomes relative to the topmost node.
<H4><a name="Fl_Preferences.groups">int Fl_Preferences::groups()</a></H4>
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 0eb03d083..afe433762 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Preferences.cxx,v 1.1.2.19 2002/08/27 03:03:37 easysw Exp $"
+// "$Id: Fl_Preferences.cxx,v 1.1.2.20 2002/09/05 20:44:36 matthiaswm Exp $"
//
// Preferences methods for the Fast Light Tool Kit (FLTK).
//
@@ -1013,19 +1013,48 @@ Fl_Preferences::Node *Fl_Preferences::Node::find( const char *path )
}
// find a group somewhere in the tree starting here
+// caller must not set 'offset' argument
// - if the node does not exist, 'search' returns NULL
-Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path )
+// - if the pathname is "." (current node) return this node
+// - if the pathname is "./" (root node) return the topmost node
+// - if the pathname starts with "./", start the search at the root node instead
+Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path, int offset )
{
+
+ if ( offset == 0 )
+ {
+ if ( path[0] == '.' )
+ {
+ if ( path[1] == 0 )
+ {
+ return this; // user was searching for current node
+ }
+ else if ( path[1] == '/' )
+ {
+ Node *nn = this;
+ while ( nn->parent_ ) nn = nn->parent_;
+ if ( path[2]==0 )
+ { // user is searching for root ( "./" )
+ return nn;
+ }
+ return nn->search( path+2, 2 ); // do a relative search on the root node
+ }
+ }
+ offset = strlen( path_ ) + 1;
+ }
+
int len = strlen( path_ );
- if ( strncmp( path, path_, len ) == 0 )
+ if ( len < offset-1 ) return 0;
+ len -= offset;
+ if ( ( len <= 0 ) || ( strncmp( path, path_+offset, len ) == 0 ) )
{
- if ( path[ len ] == 0 )
+ if ( len > 0 && path[ len ] == 0 )
return this;
- if ( path[ len ] == '/' )
+ if ( len <= 0 || path[ len ] == '/' )
{
for ( Node *nd = child_; nd; nd = nd->next_ )
{
- Node *nn = nd->find( path );
+ Node *nn = nd->search( path, offset );
if ( nn ) return nn;
}
return 0;
@@ -1084,5 +1113,5 @@ char Fl_Preferences::Node::remove()
//
-// End of "$Id: Fl_Preferences.cxx,v 1.1.2.19 2002/08/27 03:03:37 easysw Exp $".
+// End of "$Id: Fl_Preferences.cxx,v 1.1.2.20 2002/09/05 20:44:36 matthiaswm Exp $".
//
diff --git a/test/preferences.fl b/test/preferences.fl
index 443684c2c..06f6b25c1 100644
--- a/test/preferences.fl
+++ b/test/preferences.fl
@@ -12,6 +12,8 @@ decl {\#include <stdlib.h>} {}
decl {\#include <FL/filename.H>} {}
+decl {\#include <FL/fl_ask.H>} {}
+
decl {void readPrefs();} {public
}
@@ -294,9 +296,26 @@ Function {writePrefs()} {open return_type void
eat.set( Fl_Preferences::Name( 3 ), "Test3" );
- /** sample code only:
+ /* sample: create a sub-sub-group */
+ Fl_Preferences eatMore( eat, "More" );
+
+ eatMore.set( "more", "stuff" );
+
+ /* all the following searches should return 1 */
+ int sum = 0;
+ sum += app.groupExists( "Breakfast" ); /* find 'eat' relative to 'app' */
+ sum += app.groupExists( "Breakfast/More" ); /* find 'eat.eatMore' relative to 'app' */
+ sum += app.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
+ sum += eat.groupExists( "More" ); /* find 'eatMore' relative to 'eat' */
+ sum += eat.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
+ sum += eat.groupExists( "." ); /* find myself ('eat') */
+ sum += eat.groupExists( "./" ); /* find the topmost group ('app') */
+ if ( sum != 7 )
+ fl_message( "Assertion failed:\\nNot all group entries were found!" );
+
+ /* sample code only: */
unsigned int hex = 0x2387efcd;
eat.set( "binFoo", (void*)&hex, sizeof( unsigned int ) );
- eat.set( "binFoo2", (void*)&writePrefs, 1024 );
- **/} {}
+ eat.set( "binFoo2", (void*)&writePrefs, 256 );
+ } {}
}