Author: AlbrechtS
Date: 2012-01-18 07:30:50 -0800 (Wed, 18 Jan 2012)
New Revision: 9230
Log:
Ported recent FLTK 1.3 (Fl_)Preferences changes:
- documentation fixes
- string constants (project, application) in test/preferences
Modified:
branches/branch-3.0/include/fltk3/Preferences.h
branches/branch-3.0/src/fltk3/Preferences.cxx
branches/branch-3.0/test/preferences.fl
Modified: branches/branch-3.0/include/fltk3/Preferences.h
===================================================================
--- branches/branch-3.0/include/fltk3/Preferences.h 2012-01-18 15:15:04 UTC
(rev 9229)
+++ branches/branch-3.0/include/fltk3/Preferences.h 2012-01-18 15:30:50 UTC
(rev 9230)
@@ -32,22 +32,22 @@
# define Fltk3_Preferences_H
# include <stdio.h>
-# include "Export.h"
+# include "Export.h"
namespace fltk3 {
-
+
/**
\brief fltk3::Preferences provides methods to store user
- settings between application starts.
-
+ settings between application starts.
+
It is similar to the
Registry on WIN32 and Preferences on MacOS, and provides a
simple configuration mechanism for UNIX.
-
+
fltk3::Preferences uses a hierarchy to store data. It
bundles similar data into groups and manages entries into those
groups as name/value pairs.
-
+
Preferences are stored in text files that can be edited
manually. The file format is easy to read and relatively
forgiving. Preferences files are the same on all platforms. User
@@ -56,40 +56,40 @@
scheme. The user must provide default values for all entries to
ensure proper operation should preferences be corrupted or not
yet exist.
-
+
Entries can be of any length. However, the size of each
preferences file should be kept small for performance
reasons. One application can have multiple preferences files.
Extensive binary data however should be stored in separate
files: see getUserdataPath().
-
- \note Starting with FLTK 1.3, preference databases are expected to
- be in utf8 encoding. Previous databases were stored in the
+
+ \note Starting with FLTK 1.3, preference databases are expected to
+ be in UTF-8 encoding. Previous databases were stored in the
current chracter set or code page which renders them incompatible
for text entries using international characters.
*/
class FLTK3_EXPORT Preferences {
-
- public:
+
+ public:
/**
Define the scope of the preferences.
*/
- enum Root {
+ enum Root {
SYSTEM=0, ///< Preferences are used system-wide
USER ///< Preferences apply only to the current user
};
-
+
/**
Every fltk3::Preferences-Group has a uniqe ID.
-
+
ID's can be retrieved from an fltk3::Preferences-Group and can then be
used
- to create more fltk3::Preferences references to the same data set, as
long as the
+ to create more fltk3::Preferences references to the same data set, as
long as the
database remains open.
*/
typedef void *ID;
-
+
static const char *newUUID();
-
+
Preferences( Root root, const char *vendor, const char *application );
Preferences( const char *path, const char *vendor, const char *application
);
Preferences( Preferences &parent, const char *group );
@@ -99,45 +99,45 @@
Preferences(const Preferences&);
Preferences( ID id );
virtual ~Preferences();
-
+
/** Return an ID that can later be reused to open more references to this
dataset.
*/
ID id() { return (ID)node; }
-
+
/** Remove the group with this ID from a database.
*/
static char remove(ID id_) { return ((Node*)id_)->remove(); }
-
+
/** Return the name of this entry.
*/
const char *name() { return node->name(); }
-
- /** Return the the full path to this entry.
+
+ /** Return the full path to this entry.
*/
const char *path() { return node->path(); }
-
+
int groups();
const char *group( int num_group );
char groupExists( const char *key );
char deleteGroup( const char *group );
char deleteAllGroups();
-
+
int entries();
const char *entry( int index );
char entryExists( const char *key );
char deleteEntry( const char *entry );
char deleteAllEntries();
-
+
char clear();
-
+
char set( const char *entry, int value );
char set( const char *entry, float value );
char set( const char *entry, float value, int precision );
char set( const char *entry, double value );
char set( const char *entry, double value, int precision );
char set( const char *entry, const char *value );
- char set( const char *entry, const void *value, int size );
-
+ char set( const char *entry, const void *value, int size );
+
char get( const char *entry, int &value, int defaultValue );
char get( const char *entry, float &value, float defaultValue );
char get( const char *entry, double &value, double defaultValue );
@@ -145,35 +145,36 @@
char get( const char *entry, char *value, const char *defaultValue, int
maxSize );
char get( const char *entry, void *&value, const void *defaultValue, int
defaultSize );
char get( const char *entry, void *value, const void *defaultValue, int
defaultSize, int maxSize );
-
+
int size( const char *entry );
-
+
char getUserdataPath( char *path, int pathlen );
-
+
void flush();
-
+
// char export( const char *filename, Type fileFormat );
// char import( const char *filename );
-
+
/**
- 'Name' provides a simple method to create numerical or more complex
+ 'Name' provides a simple method to create numerical or more complex
procedural names for entries and groups on the fly.
-
- Example: prefs.set(fltk3::Preferences::Name("File%d",i),file[i]);.
-
- See test/preferences.cxx as a sample for writing arrays into
preferences.<p>
+
+ Example: prefs.set(fltk3::Preferences::Name("File%d",i),file[i]);.
+
+ See test/preferences.cxx as a sample for writing arrays into preferences.
+
'Name' is actually implemented as a class inside fltk3::Preferences. It
casts
into const char* and gets automatically destroyed after the enclosing call
ends.
*/
class FLTK3_EXPORT Name {
-
+
char *data_;
-
- public:
+
+ public:
Name( unsigned int n );
Name( const char *format, ... );
-
+
/**
Return the Name as a "C" string.
\internal
@@ -181,23 +182,23 @@
operator const char *() { return data_; }
~Name();
};
-
+
/** \internal An entry associates a preference name to its corresponding
value */
struct Entry {
char *name, *value;
};
-
- private:
+
+ private:
Preferences() : node(0), rootNode(0) { }
Preferences &operator=(const Preferences&);
-
+
static char nameBuffer[128];
static char uuidBuffer[40];
static Preferences *runtimePrefs;
-
+
class RootNode;
-
- class FLTK3_EXPORT Node { // a node contains a list to all its entries
+
+ class FLTK3_EXPORT Node { // a node contains a list to all its entries
// and all means to manage the tree structure
Node *child_, *next_;
union { // these two are mutually exclusive
@@ -250,7 +251,7 @@
Entry &entry(int i) { return entry_[i]; }
};
friend class Node;
-
+
class FLTK3_EXPORT RootNode { // the root node manages file
paths and basic reading and writing
Preferences *prefs_;
char *filename_;
@@ -265,12 +266,12 @@
char getPath( char *path, int pathlen );
};
friend class RootNode;
-
+
protected:
Node *node;
RootNode *rootNode;
};
-
+
}
#endif // !Fltk3_Preferences_H
Modified: branches/branch-3.0/src/fltk3/Preferences.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Preferences.cxx 2012-01-18 15:15:04 UTC
(rev 9229)
+++ branches/branch-3.0/src/fltk3/Preferences.cxx 2012-01-18 15:30:50 UTC
(rev 9230)
@@ -339,7 +339,7 @@
An ID can be retrieved from any fltk3::Preferences dataset, and can then be
used
to create multiple new references to the same dataset.
- ID's can be put very helpful when put into the <tt>user_data()</tt> field of
+ ID's can be very helpful when put into the <tt>user_data()</tt> field of
widget callbacks.
*/
fltk3::Preferences::Preferences( fltk3::Preferences::ID id ) {
@@ -379,7 +379,7 @@
if (node && !node->parent()) delete rootNode;
// DO NOT delete nodes! The root node will do that after writing the
preferences
// zero all pointer to avoid memory errors, even though
- // Valgrind does not complain (Cygwind does though)
+ // Valgrind does not complain (Cygwin does though)
node = 0L;
rootNode = 0L;
}
@@ -666,7 +666,7 @@
supplied. The return value indicates if the value was available
(non-zero) or the default was used (0).
'maxSize' is the maximum length of text that will be read.
- The text buffer must allow for one additional byte for a trailling zero.
+ The text buffer must allow for one additional byte for a trailing zero.
\param[in] key name of entry
\param[out] text returned from preferences or default value if none was set
Modified: branches/branch-3.0/test/preferences.fl
===================================================================
--- branches/branch-3.0/test/preferences.fl 2012-01-18 15:15:04 UTC (rev
9229)
+++ branches/branch-3.0/test/preferences.fl 2012-01-18 15:30:50 UTC (rev
9230)
@@ -23,6 +23,12 @@
decl {void writePrefs();} {public local
}
+decl {const char *project = "fltk.org";} {private local
+}
+
+decl {const char *application = "test/preferences";} {private local
+}
+
Function {closeWindowCB( fltk3::Widget*, void* )} {open private return_type
void
} {
code {fltk3::delete_widget(myWindow);} {}
@@ -195,7 +201,7 @@
char buffer[80];
double doubleValue;
-fltk3::Preferences app( fltk3::Preferences::USER, "fltk.org",
"test/preferences" );
+fltk3::Preferences app( fltk3::Preferences::USER, project, application );
char path[ FLTK3_PATH_MAX ];
app.getUserdataPath( path, sizeof(path) );
@@ -268,7 +274,7 @@
Function {writePrefs()} {open return_type void
} {
- code {fltk3::Preferences app( fltk3::Preferences::USER, "fltk.org",
"test/preferences" );
+ code {fltk3::Preferences app( fltk3::Preferences::USER, project, application
);
fltk3::Preferences bed( app, "Bed" );
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit