Simple way to copy fltk prefs to runtime prefs

11 views
Skip to first unread message

anmol....@gmail.com

unread,
Apr 25, 2021, 1:23:45 PM4/25/21
to fltk.general

    prefsP_= new Fl_Preferences(Fl_Preferences::USER, vendor, product);
    dataP_ = new Fl_Preferences(nullptr, "Runtime");

As we know, prefsP_ is written to HDD. dataP_ is only maintained in memory. In my code design, I'd like to make an identical copy of prefsP_ as runtime. The user can access these values without disk access and modify them as needed.

Only values that need to be saved will be written to HDD via prefsP_

Is there an API call like -  copy (prefsP_, dataP_) or something similar ?

anmol....@gmail.com

unread,
Apr 25, 2021, 1:47:46 PM4/25/21
to fltk.general

ATM, I am using this. Just wondering if there is an API call I am missing.

  void copyGroup_(Fl_Preferences& src, Fl_Preferences& dst)
  {
      for (int i = 0; i < src.groups(); ++i) {
          Fl_Preferences s(src, i);
          Fl_Preferences d(dst, s.name());
          copyGroup_(s, d);
      }
      for (int i = 0; i < src.entries(); ++i) {
          const char* name = src.entry(i);
          char* data;
          src.get(name, data, "");
          dst.set(name, data);
          ::free(data);
      }
  }

copyPrefs() {
  Fl_Preferences srcFile(Fl_Preferences::USER, "fltk.org", "Hello");
  Fl_Preferences dstFile("/Users/matt/test.cfg", "matthiasm.com", "export");
  copyGroup_(srcFile, dstFile);
}
Reply all
Reply to author
Forward
0 new messages