2002-04-30 00:57:31 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
2008-09-16 11:26:22 +04:00
|
|
|
// Preferences .
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 2002-2005 by Matthias Melcher.
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/** \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Preferences class . */
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2002-04-30 00:57:31 +04:00
|
|
|
#ifndef Fl_Preferences_H
|
|
|
|
# define Fl_Preferences_H
|
|
|
|
|
|
|
|
# ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
# endif // WIN32
|
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
# include <stdio.h>
|
|
|
|
# include "Fl_Export.H"
|
2002-04-30 00:57:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-09-15 23:21:20 +04:00
|
|
|
Fl_Preferences provides methods to store user
|
2008-09-15 00:00:03 +04:00
|
|
|
settings between application starts. It is similar to the
|
|
|
|
Registry on WIN32 and Preferences on MacOS, and provides a
|
|
|
|
simple configuration mechanism for UNIX.
|
|
|
|
|
2008-09-15 23:21:20 +04:00
|
|
|
Fl_Preferences uses a hierarchy to store data. It
|
2008-09-15 00:00:03 +04:00
|
|
|
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
|
|
|
|
comments in preference files are preserved. Filenames are unique
|
|
|
|
for each application by using a vendor/application naming
|
|
|
|
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 under 100k for performance
|
|
|
|
reasons. One application can have multiple preferences files.
|
|
|
|
Extensive binary data however should be stored in separate
|
|
|
|
files; see getUserdataPath().
|
2002-04-30 00:57:31 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
class FL_EXPORT Fl_Preferences
|
2002-04-30 00:57:31 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Define the scope of the preferences.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
|
|
|
enum Root {
|
2008-09-03 00:25:52 +04:00
|
|
|
SYSTEM=0, ///< Preferences are used system-wide
|
2008-04-08 04:09:16 +04:00
|
|
|
USER ///< Preferences apply only to the current user
|
|
|
|
};
|
2002-05-07 04:43:20 +04:00
|
|
|
// enum Type { win32, macos, fltk };
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
The constructor creates a group that manages name/value pairs and
|
|
|
|
child groups. Groups are ready for reading and writing at any time.
|
2008-09-15 23:21:20 +04:00
|
|
|
The root argument is either Fl_Preferences::USER
|
|
|
|
or Fl_Preferences::SYSTEM.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
This constructor creates the <i>base</i> instance for all
|
|
|
|
following entries and reads existing databases into memory. The
|
2008-09-15 23:21:20 +04:00
|
|
|
vendor argument is a unique text string identifying the
|
2008-09-15 00:00:03 +04:00
|
|
|
development team or vendor of an application. A domain name or
|
|
|
|
an EMail address are great unique names, e.g.
|
|
|
|
"researchATmatthiasm.com" or "fltk.org". The
|
2008-09-15 23:21:20 +04:00
|
|
|
application argument can be the working title or final
|
|
|
|
name of your application. Both vendor and
|
|
|
|
application must be valid relative UNIX pathnames and
|
2008-09-15 00:00:03 +04:00
|
|
|
may contain '/'s to create deeper file structures.
|
|
|
|
|
|
|
|
\param[in] root can be USER or SYSTEM for user specific or system wide preferences
|
|
|
|
\param[in] vendor unique text describing the company or author of this file
|
|
|
|
\param[in] application unique text describing the application
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Preferences( Root root, const char *vendor, const char *application );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
This constructor is used to create or read a preferences file at an
|
|
|
|
arbitrary position in the file system. The file name is generated
|
2008-09-15 23:21:20 +04:00
|
|
|
as <i>path</i>/<i>application</i>.prefs. If <i>application</i>
|
2008-09-15 00:00:03 +04:00
|
|
|
is 0, <i>path</i> must contain the full file name.
|
|
|
|
|
|
|
|
\param[in] path path to the directory that contains the preferences file
|
|
|
|
\param[in] vendor unique text describing the company or author of this file
|
|
|
|
\param[in] application unique text describing the application
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-27 07:03:37 +04:00
|
|
|
Fl_Preferences( const char *path, const char *vendor, const char *application );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
This constructor generates a new group of preference entries
|
2008-09-15 23:21:20 +04:00
|
|
|
inside the group or file <i>parent</i>. The group argument
|
2008-09-15 00:00:03 +04:00
|
|
|
identifies a group of entries. It can contain '/'s to get quick
|
|
|
|
access to individual elements inside the hierarchy.
|
|
|
|
|
|
|
|
\param[in] parent reference object for the new group
|
|
|
|
\param[in] group name of the group to access (may contain '/'s)
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
|
|
|
Fl_Preferences( Fl_Preferences &parent, const char *group );
|
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
\see Fl_Preferences( Fl_Preferences&, const char *group )
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Preferences( Fl_Preferences*, const char *group );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
The destructor removes allocated resources. When used on the
|
|
|
|
<i>base</i> preferences group, the destructor flushes all
|
|
|
|
changes to the preferences file and deletes all internal
|
|
|
|
databases.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
~Fl_Preferences();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns the number of groups that are contained within a
|
|
|
|
group.
|
|
|
|
|
|
|
|
\return 0 for no groups at all
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
int groups();
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns the name of the Nth group. There is no guaranteed
|
|
|
|
order of group names. The index must be within the range given
|
2008-09-15 23:21:20 +04:00
|
|
|
by groups().
|
2008-09-15 00:00:03 +04:00
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
\param[in] num_group number indexing the requested group
|
2008-09-15 00:00:03 +04:00
|
|
|
\return cstring pointer to the group name
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2008-09-18 02:25:45 +04:00
|
|
|
const char *group( int num_group );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns non-zero if a group with this name exists.
|
|
|
|
Groupnames are relative to the Preferences node and can contain a path.
|
2008-09-15 23:21:20 +04:00
|
|
|
"." describes the current node, "./" describes the topmost node.
|
|
|
|
By preceding a groupname with a "./", its path becomes relative to the topmost node.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
\param[in] key name of group that is searched for
|
2008-09-15 00:00:03 +04:00
|
|
|
\return 0 if group was not found
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2008-09-18 02:25:45 +04:00
|
|
|
char groupExists( const char *key );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Deletes a group.
|
|
|
|
|
|
|
|
\param[in] group name of the group to delete
|
|
|
|
\return 0 if call failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char deleteGroup( const char *group );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns the number of entries (name/value pairs) in a group.
|
|
|
|
|
|
|
|
\return number of entries
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
int entries();
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns the name of an entry. There is no guaranteed order of
|
|
|
|
entry names. The index must be within the range given by
|
2008-09-15 23:21:20 +04:00
|
|
|
entries().
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
\param[in] index number indexing the requested entry
|
|
|
|
\return pointer to value cstring
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
|
|
|
const char *entry( int index );
|
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns non-zero if an entry with this name exists.
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
\param[in] key name of entry that is searched for
|
2008-09-15 00:00:03 +04:00
|
|
|
\return 0 if entry was not found
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2008-09-18 02:25:45 +04:00
|
|
|
char entryExists( const char *key );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Removes a single entry (name/value pair).
|
|
|
|
|
|
|
|
\param[in] entry name of entry to delete
|
|
|
|
\return 0 if deleting the entry failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char deleteEntry( const char *entry );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, int value );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, float value );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\param[in] precision number of decimal digits to represent value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2006-08-18 11:29:09 +04:00
|
|
|
char set( const char *entry, float value, int precision );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, double value );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\param[in] precision number of decimal digits to represent value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2006-08-18 11:29:09 +04:00
|
|
|
char set( const char *entry, double value, int precision );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, const char *value );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Sets an entry (name/value pair). The return value indicates if there
|
|
|
|
was a problem storing the data in memory. However it does not
|
|
|
|
reflect if the value was actually stored in the preferences
|
|
|
|
file.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[in] value set this entry to \a value
|
|
|
|
\param[in] size of data array
|
|
|
|
\return 0 if setting the value failed
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, const void *value, int size );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0).
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, int &value, int defaultValue );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0).
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, float &value, float defaultValue );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0).
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, double &value, double defaultValue );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0). get() allocates memory of
|
|
|
|
sufficient size to hold the value. The buffer must be free'd by
|
2008-09-15 23:21:20 +04:00
|
|
|
the developer using 'free(value)'.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, char *&value, const char *defaultValue );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0).
|
2008-09-15 23:21:20 +04:00
|
|
|
'maxSize' is the maximum length of text that will be read.
|
2008-09-15 00:00:03 +04:00
|
|
|
The text buffer must allow for one additional byte for a trailling zero.
|
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\param[in] maxSize maximum length of value plus one byte for a trailing zero
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, char *value, const char *defaultValue, int maxSize );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0). get() allocates memory of
|
|
|
|
sufficient size to hold the value. The buffer must be free'd by
|
2008-09-15 23:21:20 +04:00
|
|
|
the developer using 'free(value)'.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\param[in] defaultSize size of default value array
|
|
|
|
\return 0 if the default value was used
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, void *&value, const void *defaultValue, int defaultSize );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Reads an entry from the group. A default value must be
|
|
|
|
supplied. The return value indicates if the value was available
|
|
|
|
(non-zero) or the default was used (0).
|
2008-09-15 23:21:20 +04:00
|
|
|
'maxSize' is the maximum length of text that will be read.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
\param[in] entry name of entry
|
|
|
|
\param[out] value returned from preferences or default value if none was set
|
|
|
|
\param[in] defaultValue default value to be used if no preference was set
|
|
|
|
\param[in] defaultSize size of default value array
|
|
|
|
\param[in] maxSize maximum length of value
|
|
|
|
\return 0 if the default value was used
|
|
|
|
|
|
|
|
\todo maxSize should receive the number of bytes that were read.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Returns the size of the value part of an entry.
|
|
|
|
|
|
|
|
\return size of value
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
int size( const char *entry );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Creates a path that is related to the preferences file and
|
|
|
|
that is usable for application data beyond what is covered by
|
|
|
|
Fl_Preferences.
|
|
|
|
|
|
|
|
\param[out] path buffer for user data path
|
|
|
|
\param[in] pathlen size of path buffer
|
|
|
|
\return 0 if path was not created or pathname can't fit into buffer
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
char getUserdataPath( char *path, int pathlen );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Write all preferences to disk. This function works only with
|
|
|
|
the base preference group. This function is rarely used as
|
|
|
|
deleting the base preferences flushes automatically.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
void flush();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
// char export( const char *filename, Type fileFormat );
|
|
|
|
// char import( const char *filename );
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
'Name' provides a simple method to create numerical or more complex
|
|
|
|
procedural names for entries and groups on the fly.
|
|
|
|
|
2008-09-15 23:21:20 +04:00
|
|
|
Example: prefs.set(Fl_Preferences::Name("File%d",i),file[i]);.
|
2008-09-15 00:00:03 +04:00
|
|
|
|
2008-09-15 23:21:20 +04:00
|
|
|
See test/preferences.cxx as a sample for writing arrays into preferences.<p>
|
2008-09-15 00:00:03 +04:00
|
|
|
'Name' is actually implemented as a class inside Fl_Preferences. It casts
|
2008-09-15 23:21:20 +04:00
|
|
|
into const char* and gets automatically destroyed after the enclosing call
|
2008-09-15 00:00:03 +04:00
|
|
|
ends.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT Name {
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2002-05-01 02:25:18 +04:00
|
|
|
char *data_;
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2002-05-01 02:25:18 +04:00
|
|
|
public:
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Create a numerical name.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
Name( unsigned int n );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Create a name using 'printf' style formatting.
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
Name( const char *format, ... );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-09-15 00:00:03 +04:00
|
|
|
Return the Name as a c-string.
|
|
|
|
\internal
|
2008-04-08 04:09:16 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
operator const char *() { return data_; }
|
|
|
|
~Name();
|
2002-05-01 02:25:18 +04:00
|
|
|
};
|
2008-09-18 23:09:34 +04:00
|
|
|
/** An entry associates a preference name to its corresponding value */
|
2002-04-30 00:57:31 +04:00
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
char *name, *value;
|
|
|
|
};
|
|
|
|
|
2002-05-04 00:30:19 +04:00
|
|
|
private:
|
|
|
|
|
2005-07-26 11:59:01 +04:00
|
|
|
// make the following functions unavailable
|
|
|
|
Fl_Preferences();
|
|
|
|
Fl_Preferences(const Fl_Preferences&);
|
|
|
|
Fl_Preferences &operator=(const Fl_Preferences&);
|
|
|
|
|
2002-05-04 00:30:19 +04:00
|
|
|
static char nameBuffer[128];
|
|
|
|
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT Node // a node contains a list to all its entries
|
2002-04-30 00:57:31 +04:00
|
|
|
{ // and all means to manage the tree structure
|
|
|
|
Node *child_, *next_, *parent_;
|
|
|
|
char *path_;
|
|
|
|
char dirty_;
|
|
|
|
public:
|
|
|
|
Node( const char *path );
|
|
|
|
~Node();
|
|
|
|
// node methods
|
|
|
|
int write( FILE *f );
|
|
|
|
Node *find( const char *path );
|
2002-09-06 00:44:36 +04:00
|
|
|
Node *search( const char *path, int offset=0 );
|
2002-04-30 00:57:31 +04:00
|
|
|
Node *addChild( const char *path );
|
|
|
|
void setParent( Node *parent );
|
2005-05-20 06:05:38 +04:00
|
|
|
Node *parent() { return parent_; }
|
2002-04-30 00:57:31 +04:00
|
|
|
char remove();
|
|
|
|
char dirty();
|
|
|
|
// entry methods
|
|
|
|
int nChildren();
|
|
|
|
const char *child( int ix );
|
|
|
|
void set( const char *name, const char *value );
|
|
|
|
void set( const char *line );
|
|
|
|
void add( const char *line );
|
|
|
|
const char *get( const char *name );
|
|
|
|
int getEntry( const char *name );
|
|
|
|
char deleteEntry( const char *name );
|
|
|
|
// public values
|
|
|
|
Entry *entry;
|
|
|
|
int nEntry, NEntry;
|
|
|
|
static int lastEntrySet;
|
|
|
|
};
|
|
|
|
friend class Node;
|
|
|
|
|
2003-01-21 17:51:54 +03:00
|
|
|
class FL_EXPORT RootNode // the root node manages file paths and basic reading and writing
|
2002-04-30 00:57:31 +04:00
|
|
|
{
|
|
|
|
Fl_Preferences *prefs_;
|
|
|
|
char *filename_;
|
|
|
|
char *vendor_, *application_;
|
|
|
|
public:
|
2002-05-04 00:30:19 +04:00
|
|
|
RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application );
|
2002-08-27 07:03:37 +04:00
|
|
|
RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application );
|
2002-04-30 00:57:31 +04:00
|
|
|
~RootNode();
|
|
|
|
int read();
|
|
|
|
int write();
|
2002-04-30 22:11:49 +04:00
|
|
|
char getPath( char *path, int pathlen );
|
2002-04-30 00:57:31 +04:00
|
|
|
};
|
|
|
|
friend class RootNode;
|
|
|
|
|
|
|
|
Node *node;
|
|
|
|
RootNode *rootNode;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !Fl_Preferences_H
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|