// Extensions to Fl_Preferences that facilitate easier access to boolean preferences and // to values when no "error" status is needed from Fl_Preferences::get(...) // // By Nathan Vander Wilt, 20/Apr/2005. // This work is in the public domain. I would appreciate some form of courtesy if you // publish works based on this file, but it's not necessary. USE THIS AT YOUR OWN RISK! #include class Fl_ExtPreferences : public Fl_Preferences { private: char* textbuff; public: Fl_ExtPreferences(enum Root root, const char *vendor, const char *application) : Fl_Preferences(root, vendor, application) { textbuff=0; } ~Fl_ExtPreferences() { if (textbuff) free(textbuff); } int set_bool(const char *entry, int tf=1) { // set a boolean entry if (tf) set(entry,tf); else unset(entry); } void unset(const char *entry) { deleteEntry(entry); } // unset a boolean entry int isset(const char *entry) { return entryExists(entry); } // check if an entry is set int get_bool(const char *entry) { // get a boolean directly if ( entryExists(entry) ) return 1; else return 0; } int get_int(const char *entry, int defaultValue=0) { // get an integer directly int ret; get(entry,ret,defaultValue); return ret; } float get_float(const char *entry, float defaultValue=0) { // get a float directly float ret; get(entry,ret,defaultValue); return ret; } double get_double(const char *entry, double defaultValue=0) { // get a double directly double ret; get(entry,ret,defaultValue); return ret; } char* get_text(const char *entry, const char *defaultValue=NULL) { if (textbuff) free(textbuff); int succ=get(entry,textbuff,defaultValue); if ( !succ && !defaultValue ) { textbuff=(char*) malloc(1); textbuff[0]='\0'; } return textbuff; } // TBD: would get_data() get any use? };