From 1209e9dcd7e1e97bedc747d06ba4eea837562158 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 22 Oct 2023 19:30:37 +0200 Subject: Make Fl_String and Fl_Int_Vector private (#789) - add CMake option 'OPTION_USE_STD' - add configure option '--enable-use_std' - move FL/Fl_String.H to src/Fl_String.H - move FL/Fl_Int_Vector.H to src/Fl_Int_Vector.H - remove Fl_String from demo program examples/callbacks.cxx - remove Fl_Int_Vector from public header FL/Fl_Table.H - some methods of Fl_Table are no longer inline - add CMake option OPTION_USE_STD to allow std::string in some selected functions and methods Experimental, may be removed before release: - use either Fl_Int_Vector or std::vector in Fl_Table depending on CMake OPTION_USE_STD or configure --enable-use_std Move all fl_filename* functions that use Fl_String to fluid Main changes in fluid: - add fluid_filename.h and .cxx - include "fluid_filename.h" rather than Update fl_input(), fl_password() and test/ask - add maxchar parameter to fl_input() and fl_password() - fl_input_str() and fl_password_str() are optional and return std::string if enabled (FLTK_USE_STD) --- src/Fl_Preferences.cxx | 90 ++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 40 deletions(-) (limited to 'src/Fl_Preferences.cxx') diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 6a6150fad..f4a769d69 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -1,8 +1,8 @@ // // Preferences methods for the Fast Light Tool Kit (FLTK). // -// Copyright 2011-2022 by Bill Spitzak and others. // Copyright 2002-2010 by Matthias Melcher. +// Copyright 2011-2023 by Bill Spitzak and others. // // 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 @@ -28,6 +28,9 @@ #include #include +#if (FLTK_USE_STD) +#include +#endif char Fl_Preferences::nameBuffer[128]; char Fl_Preferences::uuidBuffer[40]; @@ -844,46 +847,36 @@ char Fl_Preferences::get( const char *key, char *&text, const char *defaultValue return ( v != defaultValue ); } -// /** -// 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] key 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 -// */ -//char Fl_Preferences::get( const char *key, Fl_String &value, const Fl_String &defaultValue ) { -// const char *v = node->get( key ); -// if (v) { -// if ( strchr( v, '\\' ) ) { -// char *text = decodeText( v ); -// value = text; -// ::free(text); -// } else { -// value = v; -// } -// return 1; -// } else { -// value = defaultValue; -// return 0; -// } -//} - -// /** -// 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 preference file. -// -// \param[in] entry name of entry -// \param[in] value set this entry to value (stops at the first nul character). -// \return 0 if setting the value failed -// */ -//char Fl_Preferences::set( const char *entry, const Fl_String &value ) { -// return set(entry, value.c_str()); -//} +#if (FLTK_USE_STD) +/** + 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] key 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 + */ +char Fl_Preferences::get( const char *key, std::string &value, const std::string &defaultValue ) { + const char *v = node->get( key ); + if (v) { + if ( strchr( v, '\\' ) ) { + char *text = decodeText( v ); + value = text; + ::free(text); + } else { + value = v; + } + return 1; + } else { + value = defaultValue; + return 0; + } +} + +#endif /** Sets an entry (name/value pair). The return value indicates if there @@ -1055,6 +1048,23 @@ char Fl_Preferences::set( const char *key, const void *data, int dsize ) { return 1; } +#if (FLTK_USE_STD) + +/** + 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 preference file. + + \param[in] entry name of entry + \param[in] value set this entry to value (stops at the first nul character). + \return 0 if setting the value failed + */ +char Fl_Preferences::set( const char *entry, const std::string &value ) { + return set(entry, value.c_str()); +} + +#endif // FLTK_USE_STD + /** Returns the size of the value part of an entry. -- cgit v1.2.3