prefs.h 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef _prefs_h_
  2. #define _prefs_h_
  3. /* prefs.h
  4. *
  5. * Copyright (C) 2013,2015-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Preferences.h"
  21. #define prefs_begin(Klas) \
  22. public: static void f_preferences (); \
  23. void v_copyPreferencesToInstance () override;
  24. #define prefs_add_int(Klas,name,version,default) \
  25. private: static int s_##name; public: virtual int & pref_##name () { return s_##name; } \
  26. private: static conststring32 sdefault_##name; public: virtual conststring32 default_##name () { return sdefault_##name; }
  27. #define prefs_add_int_with_data(Klas,name,version,default) public: int p_##name; prefs_add_int (Klas, name, version, default)
  28. #define prefs_override_int(Klas,name,version,default) \
  29. private: static int s_##name; public: int & pref_##name () override { return s_##name; } \
  30. private: static conststring32 sdefault_##name; public: conststring32 default_##name () override { return sdefault_##name; }
  31. #define prefs_add_integer(Klas,name,version,default) \
  32. private: static integer s_##name; public: virtual integer & pref_##name () { return s_##name; } \
  33. private: static conststring32 sdefault_##name; public: virtual conststring32 default_##name () { return sdefault_##name; }
  34. #define prefs_add_integer_with_data(Klas,name,version,default) public: integer p_##name; prefs_add_integer (Klas, name, version, default)
  35. #define prefs_override_integer(Klas,name,version,default) \
  36. private: static integer s_##name; public: integer & pref_##name () override { return s_##name; } \
  37. private: static conststring32 sdefault_##name; public: conststring32 default_##name () override { return sdefault_##name; }
  38. #define prefs_add_bool(Klas,name,version,default) \
  39. private: static bool s_##name; public: virtual bool & pref_##name () { return s_##name; } \
  40. private: static bool sdefault_##name; public: virtual bool default_##name () { return sdefault_##name; }
  41. #define prefs_add_bool_with_data(Klas,name,version,default) public: bool p_##name; prefs_add_bool (Klas, name, version, default)
  42. #define prefs_override_bool(Klas,name,version,default) \
  43. private: static bool s_##name; public: bool & pref_##name () override { return s_##name; } \
  44. private: static bool sdefault_##name; public: bool default_##name () override { return sdefault_##name; }
  45. #define prefs_add_double(Klas,name,version,default) \
  46. private: static double s_##name; public: virtual double & pref_##name () { return s_##name; } \
  47. private: static conststring32 sdefault_##name; public: virtual conststring32 default_##name () { return sdefault_##name; }
  48. #define prefs_add_double_with_data(Klas,name,version,default) public: double p_##name; prefs_add_double (Klas, name, version, default)
  49. #define prefs_override_double(Klas,name,version,default) \
  50. private: static double s_##name; public: double & pref_##name () override { return s_##name; } \
  51. private: static conststring32 sdefault_##name; public: conststring32 default_##name () override { return sdefault_##name; }
  52. #define prefs_add_enum(Klas,name,version,enumerated,default) \
  53. private: static enum enumerated s_##name; public: virtual enum enumerated & pref_##name () { return s_##name; } \
  54. private: static enum enumerated sdefault_##name; public: virtual enum enumerated default_##name () { return sdefault_##name; }
  55. #define prefs_add_enum_with_data(Klas,name,version,enumerated,default) public: enumerated p_##name; prefs_add_enum (Klas, name, version, enumerated, default)
  56. #define prefs_override_enum(Klas,name,version,enumerated,default) \
  57. private: static enum enumerated s_##name; public: enum enumerated & pref_##name () override { return s_##name; } \
  58. private: static enum enumerated sdefault_##name; public: enum enumerated default_##name () override { return sdefault_##name; }
  59. #define prefs_add_string(Klas,name,version,default) \
  60. private: static char32 s_##name [Preferences_STRING_BUFFER_SIZE]; public: virtual char32 * pref_##name () { return & s_##name [0]; } \
  61. private: static conststring32 sdefault_##name; public: virtual conststring32 default_##name () { return sdefault_##name; }
  62. #define prefs_add_string_with_data(Klas,name,version,default) public: char32 p_##name [Preferences_STRING_BUFFER_SIZE]; prefs_add_string (Klas, name, version, default)
  63. #define prefs_override_string(Klas,name,version,default) \
  64. private: static char32 s_##name [Preferences_STRING_BUFFER_SIZE]; public: char32 * pref_##name () override { return & s_##name [0]; } \
  65. private: static conststring32 sdefault_##name; public: conststring32 default_##name () override{ return sdefault_##name; }
  66. #define prefs_end(Klas)
  67. /* End of file prefs.h */
  68. #endif