2002-04-30 00:57:31 +04:00
|
|
|
//
|
2018-02-09 17:39:42 +03:00
|
|
|
// Preferences implementation for the Fast Light Tool Kit (FLTK).
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
2022-01-19 18:08:29 +03:00
|
|
|
// Copyright 2002-2022 by Matthias Melcher.
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2002-04-30 00:57:31 +04:00
|
|
|
//
|
|
|
|
|
2008-10-15 17:46:06 +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
|
|
|
|
|
2009-04-01 18:10:58 +04:00
|
|
|
# include <stdio.h>
|
2020-07-01 19:03:10 +03:00
|
|
|
# include "Fl_Export.H"
|
2002-04-30 00:57:31 +04:00
|
|
|
|
|
|
|
/**
|
2022-01-19 18:08:29 +03:00
|
|
|
\brief Fl_Preferences store user settings between application starts.
|
|
|
|
|
|
|
|
Fl_Preferences are similar to the Registry on Windows and Preferences on MacOS,
|
|
|
|
providing a simple method to store customisable user settings between app
|
|
|
|
launches, i.e. the previous window position or a history of previously
|
|
|
|
used documents.
|
|
|
|
|
|
|
|
Preferences are organized in a hierarchy of groups. Every group can contain
|
2022-01-24 00:35:21 +03:00
|
|
|
more groups and any number of key/value pairs. Keys can be text strings
|
2022-01-19 18:08:29 +03:00
|
|
|
containing ASCII letters, digits, periods, and underscores. Forward slashes
|
|
|
|
in a key name are treated as subgroups, i.e the key 'window/width' would
|
2022-01-24 00:35:21 +03:00
|
|
|
actually refer to the key 'width' inside the group 'window'.
|
2022-01-19 18:08:29 +03:00
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
Keys usually have a unique name within their group. Duplicate keys are
|
|
|
|
possible though and can be accessed using the index based functions.
|
2022-01-19 18:08:29 +03:00
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
A value can be an UTF-8 string. Control characters and UTF-8 sequences are
|
|
|
|
stores as octal values. Long strings are wrap at the line ending and will be
|
2022-01-19 18:08:29 +03:00
|
|
|
reassembled when reading the file back.
|
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
Several methods allow setting and getting numerical values and binary data.
|
2022-01-19 18:08:29 +03:00
|
|
|
|
|
|
|
Preferences are stored in text files that can be edited manually if needed.
|
|
|
|
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.
|
|
|
|
|
|
|
|
FLTK preferences are not meant to replace a fully features database. No merging
|
|
|
|
of data takes place. If several instances of an app access the same database at
|
|
|
|
the same time, only the most recent changes will persist.
|
|
|
|
|
|
|
|
Preferences should no be used to store document data. The .prefs file should
|
|
|
|
be kept small for performance reasons. One application can have multiple
|
|
|
|
preferences files. Extensive binary data however should be stored in separate
|
2022-01-24 00:35:21 +03:00
|
|
|
files: see \a Fl_Preferences::get_userdata_path() .
|
2022-01-19 18:08:29 +03:00
|
|
|
|
|
|
|
Fl_Preferences are not thread-safe. They can temprorarily change the locale
|
2022-01-24 00:35:21 +03:00
|
|
|
on some platforms during read an write access, which is also changes it
|
|
|
|
temporarily in other threads of the same app.
|
2022-01-19 18:08:29 +03:00
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
Typically a preferences database is read at startup, and then reopended and
|
|
|
|
written at app shutdown:
|
|
|
|
```
|
2022-01-19 18:08:29 +03:00
|
|
|
int appWindowWidth, appWindowHeight;
|
2022-01-24 00:35:21 +03:00
|
|
|
|
2022-01-19 18:08:29 +03:00
|
|
|
void launch() {
|
|
|
|
Fl_Preferences app(Fl_Preferences::USER_L, "matthiasm.com", "hello");
|
|
|
|
// 'app' constructor will be called, reading data from .prefs file
|
|
|
|
Fl_Preferences window(app, "window");
|
|
|
|
window.get("width", appWindowWidth, 800);
|
|
|
|
window.get("height", appWindowHeight, 600);
|
|
|
|
// 'app' destructor will be called, writing data to .prefs file
|
|
|
|
}
|
2022-01-24 00:35:21 +03:00
|
|
|
|
2022-01-19 18:08:29 +03:00
|
|
|
void quit() {
|
|
|
|
Fl_Preferences app(Fl_Preferences::USER_L, "matthiasm.com", "hello");
|
|
|
|
Fl_Preferences window(app, "window");
|
|
|
|
window.set("width", appWindowWidth);
|
|
|
|
window.set("height", appWindowHeight);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
\see Fl_Preferences::Fl_Preferences( Root root, const char *vendor, const char *application )
|
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
As a special case, Fl_Preferences can be memory mapped and not be associated
|
2022-01-19 18:08:29 +03:00
|
|
|
with a file on disk.
|
|
|
|
|
|
|
|
\see Fl_Preferences::Fl_Preferences( Fl_Preferences *parent, const char *group )
|
2022-01-24 00:35:21 +03:00
|
|
|
for more details on memory mapped preferences.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2012-01-18 15:39:57 +04:00
|
|
|
\note Starting with FLTK 1.3, preference databases are expected to
|
2020-05-24 15:18:08 +03:00
|
|
|
be in UTF-8 encoding. Previous databases were stored in the
|
|
|
|
current character set or code page which renders them incompatible
|
|
|
|
for text entries using international characters.
|
2020-01-14 21:21:58 +03:00
|
|
|
|
2020-05-24 15:18:08 +03:00
|
|
|
\note Starting with FLTK 1.4, searching a valid path to store
|
|
|
|
the preferences files has changed slightly. Please see
|
|
|
|
Fl_Preferences::Fl_Preferences(Root, const char*, const char*)
|
|
|
|
for details.
|
2022-01-19 18:08:29 +03:00
|
|
|
|
|
|
|
\note Starting with FLTK 1.4, preference files should be created with
|
|
|
|
`SYSTEM_L` or `USER_L` to be interchangeable between computers with
|
|
|
|
differing loacale settings. The legacy modes, `LOCAL` and `SYSTEM`, will
|
|
|
|
read and write floating point values using the decimal point of the
|
|
|
|
current locale. As a result, a fp-value would be writte '3,1415' on a
|
|
|
|
German machine, and would be read back as '3.0' on a US machine because
|
|
|
|
the comma would not be recoginized as an alternative decimal point.
|
2002-04-30 00:57:31 +04:00
|
|
|
*/
|
2010-12-05 03:38:16 +03:00
|
|
|
class FL_EXPORT Fl_Preferences {
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2020-07-01 19:03:10 +03: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
|
|
|
*/
|
2020-07-01 19:03:10 +03:00
|
|
|
enum Root {
|
2022-02-03 22:46:13 +03:00
|
|
|
UNKNOWN_ROOT_TYPE = -1, ///< Returned if storage could not be determined.
|
|
|
|
SYSTEM = 0, ///< Preferences are used system-wide, deprecated, see SYSTEM_L
|
|
|
|
USER, ///< Preferences apply only to the current user, deprecated, see USER_L
|
|
|
|
MEMORY, ///< Returned if querying memory mapped preferences
|
|
|
|
ROOT_MASK = 0x00FF, ///< mask for the values above
|
|
|
|
CORE = 0x0100, ///< OR'd by FLTK to read and write core library preferences and options
|
|
|
|
C_LOCALE = 0x1000, ///< this flag should always be set, it makes sure that floating point
|
|
|
|
///< values are written correctly independently of the current locale
|
|
|
|
SYSTEM_L = SYSTEM | C_LOCALE, ///< Preferences are used system-wide, locale independent
|
|
|
|
USER_L = USER | C_LOCALE, ///< Preferences apply only to the current user, locale independent
|
|
|
|
CORE_SYSTEM_L = CORE | SYSTEM_L, ///< same as CORE | SYSTEM | C_LOCALE
|
|
|
|
CORE_USER_L = CORE | USER_L, ///< same as CORE | USER | C_LOCALE
|
|
|
|
CORE_SYSTEM = CORE | SYSTEM, ///< deprecated, same as CORE | SYSTEM
|
|
|
|
CORE_USER = CORE | USER, ///< deprecated, same as CORE | USER
|
2008-04-08 04:09:16 +04:00
|
|
|
};
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-12-29 01:26:48 +03:00
|
|
|
/**
|
|
|
|
Every Fl_Preferences-Group has a uniqe ID.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-12-29 01:26:48 +03:00
|
|
|
ID's can be retrieved from an Fl_Preferences-Group and can then be used
|
2020-07-01 19:03:10 +03:00
|
|
|
to create more Fl_Preference references to the same data set, as long as the
|
2010-04-03 17:03:43 +04:00
|
|
|
database remains open.
|
2009-12-29 01:26:48 +03:00
|
|
|
*/
|
|
|
|
typedef void *ID;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
static const char *new_UUID();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2019-12-31 20:30:04 +03:00
|
|
|
/** Set this, if no call to Fl_Preferences shall access the file sytem
|
|
|
|
@see Fl_Preferences::file_access(unsigned int)
|
|
|
|
@see Fl_Preferences::file_access()
|
|
|
|
*/
|
|
|
|
static const unsigned int NONE = 0x0000;
|
|
|
|
/** set this if it is ok for applications to read user preference files */
|
|
|
|
static const unsigned int USER_READ_OK = 0x0001;
|
|
|
|
/** set this if it is ok for applications to create and write user preference files */
|
|
|
|
static const unsigned int USER_WRITE_OK = 0x0002;
|
|
|
|
/** set this if it is ok for applications to read, create, and write user preference files */
|
|
|
|
static const unsigned int USER_OK = USER_READ_OK | USER_WRITE_OK;
|
|
|
|
/** set this if it is ok for applications to read system wide preference files */
|
|
|
|
static const unsigned int SYSTEM_READ_OK = 0x0004;
|
|
|
|
/** set this if it is ok for applications to create and write system wide preference files */
|
|
|
|
static const unsigned int SYSTEM_WRITE_OK = 0x0008;
|
|
|
|
/** set this if it is ok for applications to read, create, and write system wide preference files */
|
|
|
|
static const unsigned int SYSTEM_OK = SYSTEM_READ_OK | SYSTEM_WRITE_OK;
|
|
|
|
/** set this if it is ok for applications to read, create, and write any kind of preference files */
|
|
|
|
static const unsigned int APP_OK = SYSTEM_OK | USER_OK;
|
|
|
|
/** Set this if it is ok for FLTK to read preference files. USER_READ_OK and/or SYSTEM_READ_OK must also be set. */
|
|
|
|
static const unsigned int CORE_READ_OK = 0x0010;
|
|
|
|
/** Set this if it is ok for FLTK to create or write preference files. USER_WRITE_OK and/or SYSTEM_WRITE_OK must also be set. */
|
|
|
|
static const unsigned int CORE_WRITE_OK = 0x0020;
|
|
|
|
/** set this if it is ok for FLTK to read, create, or write preference files */
|
|
|
|
static const unsigned int CORE_OK = CORE_READ_OK | CORE_WRITE_OK;
|
|
|
|
/** set this to allow FLTK and applications to read preference files */
|
|
|
|
static const unsigned int ALL_READ_OK = USER_READ_OK | SYSTEM_READ_OK | CORE_READ_OK;
|
|
|
|
/** set this to allow FLTK and applications to create and write preference files */
|
|
|
|
static const unsigned int ALL_WRITE_OK = USER_WRITE_OK | SYSTEM_WRITE_OK | CORE_WRITE_OK;
|
|
|
|
/** set this to give FLTK and applications permission to read, write, and create preference files */
|
|
|
|
static const unsigned int ALL = ALL_READ_OK | ALL_WRITE_OK;
|
|
|
|
|
|
|
|
static void file_access(unsigned int flags);
|
|
|
|
static unsigned int file_access();
|
2022-01-19 18:08:29 +03:00
|
|
|
static Root filename( char *buffer, size_t buffer_size, Root root, const char *vendor, const char *application );
|
2019-12-31 20:30:04 +03:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Preferences( Root root, const char *vendor, const char *application );
|
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
|
|
|
Fl_Preferences( Fl_Preferences &parent, const char *group );
|
2009-12-27 23:14:04 +03:00
|
|
|
Fl_Preferences( Fl_Preferences *parent, const char *group );
|
|
|
|
Fl_Preferences( Fl_Preferences &parent, int groupIndex );
|
|
|
|
Fl_Preferences( Fl_Preferences *parent, int groupIndex );
|
2010-01-24 03:16:33 +03:00
|
|
|
Fl_Preferences(const Fl_Preferences&);
|
2009-12-29 01:26:48 +03:00
|
|
|
Fl_Preferences( ID id );
|
2010-10-31 23:47:50 +03:00
|
|
|
virtual ~Fl_Preferences();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2022-01-19 18:08:29 +03:00
|
|
|
Root filename( char *buffer, size_t buffer_size);
|
|
|
|
|
2009-12-29 02:10:11 +03:00
|
|
|
/** Return an ID that can later be reused to open more references to this dataset.
|
|
|
|
*/
|
|
|
|
ID id() { return (ID)node; }
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2010-04-03 17:03:43 +04:00
|
|
|
/** Remove the group with this ID from a database.
|
2010-01-24 03:16:33 +03:00
|
|
|
*/
|
2010-04-03 13:14:03 +04:00
|
|
|
static char remove(ID id_) { return ((Node*)id_)->remove(); }
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2009-12-27 23:14:04 +03:00
|
|
|
/** Return the name of this entry.
|
|
|
|
*/
|
|
|
|
const char *name() { return node->name(); }
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2012-01-18 15:39:57 +04:00
|
|
|
/** Return the full path to this entry.
|
2009-12-27 23:14:04 +03:00
|
|
|
*/
|
|
|
|
const char *path() { return node->path(); }
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
int groups();
|
2008-09-18 02:25:45 +04:00
|
|
|
const char *group( int num_group );
|
2022-01-24 00:35:21 +03:00
|
|
|
char group_exists( const char *key );
|
|
|
|
char delete_group( const char *group );
|
|
|
|
char delete_all_groups();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
int entries();
|
2008-04-08 04:09:16 +04:00
|
|
|
const char *entry( int index );
|
2022-01-24 00:35:21 +03:00
|
|
|
char entry_exists( const char *key );
|
|
|
|
char delete_entry( const char *entry );
|
|
|
|
char delete_all_entries();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2010-01-12 11:48:55 +03:00
|
|
|
char clear();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, int value );
|
|
|
|
char set( const char *entry, float value );
|
2006-08-18 11:29:09 +04:00
|
|
|
char set( const char *entry, float value, int precision );
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, double value );
|
2006-08-18 11:29:09 +04:00
|
|
|
char set( const char *entry, double value, int precision );
|
2002-08-14 20:19:48 +04:00
|
|
|
char set( const char *entry, const char *value );
|
2020-07-01 19:03:10 +03:00
|
|
|
char set( const char *entry, const void *value, int size );
|
|
|
|
|
2008-10-31 19:30:07 +03:00
|
|
|
char get( const char *entry, int &value, int defaultValue );
|
2002-08-14 20:19:48 +04:00
|
|
|
char get( const char *entry, float &value, float defaultValue );
|
|
|
|
char get( const char *entry, double &value, double defaultValue );
|
|
|
|
char get( const char *entry, char *&value, const char *defaultValue );
|
|
|
|
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 );
|
2022-01-19 18:08:29 +03:00
|
|
|
char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int *size );
|
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
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
char get_userdata_path( char *path, int pathlen );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2022-01-19 18:08:29 +03:00
|
|
|
int flush();
|
|
|
|
|
|
|
|
int dirty();
|
2002-04-30 00:57:31 +04:00
|
|
|
|
2022-01-24 00:35:21 +03:00
|
|
|
/** \cond PRIVATE */
|
|
|
|
static const char *newUUID() { return new_UUID(); }
|
|
|
|
char groupExists( const char *key ) { return group_exists(key); }
|
|
|
|
char deleteGroup( const char *group ) { return delete_group(group); }
|
|
|
|
char deleteAllGroups() { return delete_all_groups(); }
|
|
|
|
char entryExists( const char *key ) { return entry_exists(key); }
|
|
|
|
char deleteEntry( const char *entry ) { return delete_entry(entry); }
|
|
|
|
char deleteAllEntries() { return delete_all_entries(); }
|
|
|
|
char getUserdataPath( char *path, int pathlen ) { return get_userdata_path(path, pathlen); }
|
|
|
|
/** \endcond */
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/**
|
2012-01-18 15:39:57 +04:00
|
|
|
'Name' provides a simple method to create numerical or more complex
|
2008-09-15 00:00:03 +04:00
|
|
|
procedural names for entries and groups on the fly.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2012-01-18 15:39:57 +04:00
|
|
|
Example: prefs.set(Fl_Preferences::Name("File%d",i),file[i]);.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2012-01-18 15:39:57 +04:00
|
|
|
See test/preferences.cxx as a sample for writing arrays into preferences.
|
|
|
|
|
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
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
public:
|
2002-08-14 20:19:48 +04:00
|
|
|
Name( unsigned int n );
|
|
|
|
Name( const char *format, ... );
|
2008-04-08 04:09:16 +04:00
|
|
|
|
|
|
|
/**
|
2008-10-31 19:30:07 +03:00
|
|
|
Return the Name as a "C" string.
|
2008-09-15 00:00:03 +04:00
|
|
|
\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
|
|
|
};
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal An entry associates a preference name to its corresponding value */
|
2010-12-05 03:38:16 +03:00
|
|
|
struct Entry {
|
2002-04-30 00:57:31 +04:00
|
|
|
char *name, *value;
|
|
|
|
};
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
private:
|
2010-01-24 03:16:33 +03:00
|
|
|
Fl_Preferences() : node(0), rootNode(0) { }
|
2005-07-26 11:59:01 +04:00
|
|
|
Fl_Preferences &operator=(const Fl_Preferences&);
|
|
|
|
|
2002-05-04 00:30:19 +04:00
|
|
|
static char nameBuffer[128];
|
2009-12-27 23:14:04 +03:00
|
|
|
static char uuidBuffer[40];
|
2010-01-24 03:16:33 +03:00
|
|
|
static Fl_Preferences *runtimePrefs;
|
2019-12-31 20:30:04 +03:00
|
|
|
static unsigned int fileAccess_;
|
2002-05-04 00:30:19 +04:00
|
|
|
|
2013-09-17 00:25:14 +04:00
|
|
|
public: // older Sun compilers need this (public definition of the following classes)
|
2009-12-29 01:26:48 +03:00
|
|
|
class RootNode;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
class FL_EXPORT Node { // a node contains a list to all its entries
|
|
|
|
// and all means to manage the tree structure
|
2022-01-19 18:08:29 +03:00
|
|
|
Node *first_child_, *next_;
|
2020-07-01 19:03:10 +03:00
|
|
|
union { // these two are mutually exclusive
|
|
|
|
Node *parent_; // top_ bit clear
|
2022-01-19 18:08:29 +03:00
|
|
|
RootNode *root_node_; // top_ bit set
|
2009-12-29 01:26:48 +03:00
|
|
|
};
|
2002-04-30 00:57:31 +04:00
|
|
|
char *path_;
|
2010-02-21 00:14:47 +03:00
|
|
|
Entry *entry_;
|
|
|
|
int nEntry_, NEntry_;
|
2010-01-07 19:02:44 +03:00
|
|
|
unsigned char dirty_:1;
|
|
|
|
unsigned char top_:1;
|
2010-02-21 00:14:47 +03:00
|
|
|
unsigned char indexed_:1;
|
|
|
|
// indexing routines
|
|
|
|
Node **index_;
|
|
|
|
int nIndex_, NIndex_;
|
|
|
|
void createIndex();
|
|
|
|
void updateIndex();
|
|
|
|
void deleteIndex();
|
|
|
|
public:
|
|
|
|
static int lastEntrySet;
|
2002-04-30 00:57:31 +04:00
|
|
|
public:
|
|
|
|
Node( const char *path );
|
|
|
|
~Node();
|
|
|
|
// node methods
|
|
|
|
int write( FILE *f );
|
2009-12-27 23:14:04 +03:00
|
|
|
const char *name();
|
|
|
|
const char *path() { return path_; }
|
2002-04-30 00:57:31 +04:00
|
|
|
Node *find( const char *path );
|
2002-09-06 00:44:36 +04:00
|
|
|
Node *search( const char *path, int offset=0 );
|
2010-01-11 01:37:56 +03:00
|
|
|
Node *childNode( int ix );
|
2002-04-30 00:57:31 +04:00
|
|
|
Node *addChild( const char *path );
|
|
|
|
void setParent( Node *parent );
|
2009-12-29 02:10:11 +03:00
|
|
|
Node *parent() { return top_?0L:parent_; }
|
2022-01-19 18:08:29 +03:00
|
|
|
void setRoot(RootNode *r) { root_node_ = r; top_ = 1; }
|
2009-12-29 01:26:48 +03:00
|
|
|
RootNode *findRoot();
|
2002-04-30 00:57:31 +04:00
|
|
|
char remove();
|
|
|
|
char dirty();
|
2017-07-08 00:00:17 +03:00
|
|
|
void clearDirtyFlags();
|
2010-01-12 11:48:55 +03:00
|
|
|
void deleteAllChildren();
|
2002-04-30 00:57:31 +04:00
|
|
|
// 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 );
|
2010-01-12 11:48:55 +03:00
|
|
|
void deleteAllEntries();
|
2010-02-21 00:14:47 +03:00
|
|
|
int nEntry() { return nEntry_; }
|
|
|
|
Entry &entry(int i) { return entry_[i]; }
|
2002-04-30 00:57:31 +04:00
|
|
|
};
|
|
|
|
friend class Node;
|
|
|
|
|
2020-07-01 19:03:10 +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_;
|
2022-01-19 18:08:29 +03:00
|
|
|
Root root_type_;
|
2002-04-30 00:57:31 +04:00
|
|
|
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 );
|
2010-01-24 03:16:33 +03:00
|
|
|
RootNode( Fl_Preferences * );
|
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 );
|
2022-01-19 18:08:29 +03:00
|
|
|
char *filename() { return filename_; }
|
|
|
|
Root root() { return root_type_; }
|
2002-04-30 00:57:31 +04:00
|
|
|
};
|
|
|
|
friend class RootNode;
|
|
|
|
|
2010-01-24 03:16:33 +03:00
|
|
|
protected:
|
2002-04-30 00:57:31 +04:00
|
|
|
Node *node;
|
|
|
|
RootNode *rootNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !Fl_Preferences_H
|