foobar2000 SDK  2015-08-03
advconfig.h
Go to the documentation of this file.
1 class NOVTABLE advconfig_entry : public service_base {
5 public:
6  virtual void get_name(pfc::string_base & p_out) = 0;
7  virtual GUID get_guid() = 0;
8  virtual GUID get_parent() = 0;
9  virtual void reset() = 0;
10  virtual double get_sort_priority() = 0;
11 
12  t_uint32 get_preferences_flags_();
13 
14  static bool g_find(service_ptr_t<advconfig_entry>& out, const GUID & id) {
15  service_enum_t<advconfig_entry> e; service_ptr_t<advconfig_entry> ptr; while(e.next(ptr)) { if (ptr->get_guid() == id) {out = ptr; return true;} } return false;
16  }
17 
18  template<typename outptr> static bool g_find_t(outptr & out, const GUID & id) {
20  if (!g_find(temp, id)) return false;
21  return temp->service_query_t(out);
22  }
23 
24  static const GUID guid_root;
25  static const GUID guid_branch_tagging,guid_branch_decoding,guid_branch_tools,guid_branch_playback,guid_branch_display;
26 
27  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(advconfig_entry);
28 };
29 
32 class NOVTABLE advconfig_branch : public advconfig_entry {
33 public:
34  FB2K_MAKE_SERVICE_INTERFACE(advconfig_branch,advconfig_entry);
35 };
36 
40 class NOVTABLE advconfig_entry_checkbox : public advconfig_entry {
41 public:
42  virtual bool get_state() = 0;
43  virtual void set_state(bool p_state) = 0;
44  virtual bool is_radio() = 0;
45 
46  bool get_default_state_();
47 
48  FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_checkbox,advconfig_entry);
49 };
50 
53 public:
54  virtual bool get_default_state() = 0;
55  virtual t_uint32 get_preferences_flags() {return 0;} //signals whether changing this setting should trigger playback restart or app restart; see: preferences_state::* constants
56 };
57 
60 class NOVTABLE advconfig_entry_string : public advconfig_entry {
61 public:
62  virtual void get_state(pfc::string_base & p_out) = 0;
63  virtual void set_state(const char * p_string,t_size p_length = ~0) = 0;
64  virtual t_uint32 get_flags() = 0;
65 
66  void get_default_state_(pfc::string_base & out);
67 
68  enum {
69  flag_is_integer = 1 << 0,
70  flag_is_signed = 1 << 1,
71  };
72 
73  FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_string,advconfig_entry);
74 };
75 
78 public:
79  virtual void get_default_state(pfc::string_base & out) = 0;
80  virtual void validate(pfc::string_base & val) {}
81  virtual t_uint32 get_preferences_flags() {return 0;} //signals whether changing this setting should trigger playback restart or app restart; see: preferences_state::* constants
82 };
83 
84 
88 public:
89  advconfig_branch_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority) : m_name(p_name), m_guid(p_guid), m_parent(p_parent), m_priority(p_priority) {}
90  void get_name(pfc::string_base & p_out) {p_out = m_name;}
91  GUID get_guid() {return m_guid;}
92  GUID get_parent() {return m_parent;}
93  void reset() {}
94  double get_sort_priority() {return m_priority;}
95 private:
97  GUID m_guid,m_parent;
98  const double m_priority;
99 };
100 
103 template<bool p_is_radio = false, uint32_t prefFlags = 0>
105 public:
106  advconfig_entry_checkbox_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,bool p_initialstate)
107  : m_name(p_name), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate), m_parent(p_parent), m_priority(p_priority) {}
108 
109  void get_name(pfc::string_base & p_out) {p_out = m_name;}
110  GUID get_guid() {return m_state.get_guid();}
111  GUID get_parent() {return m_parent;}
112  void reset() {m_state = m_initialstate;}
113  bool get_state() {return m_state;}
114  void set_state(bool p_state) {m_state = p_state;}
115  bool is_radio() {return p_is_radio;}
116  double get_sort_priority() {return m_priority;}
117  bool get_state_() const {return m_state;}
118  bool get_default_state() {return m_initialstate;}
119  bool get_default_state_() const {return m_initialstate;}
120  t_uint32 get_preferences_flags() {return prefFlags;}
121 private:
123  const bool m_initialstate;
126  const double m_priority;
127 };
128 
131 class advconfig_branch_factory : public service_factory_single_t<advconfig_branch_impl> {
132 public:
133  advconfig_branch_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority)
134  : service_factory_single_t<advconfig_branch_impl>(p_name,p_guid,p_parent,p_priority) {}
135 };
136 
139 template<bool p_is_radio, uint32_t prefFlags = 0>
140 class advconfig_checkbox_factory_t : public service_factory_single_t<advconfig_entry_checkbox_impl<p_is_radio, prefFlags> > {
141 public:
142  advconfig_checkbox_factory_t(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,bool p_initialstate)
143  : service_factory_single_t<advconfig_entry_checkbox_impl<p_is_radio, prefFlags> >(p_name,p_guid,p_parent,p_priority,p_initialstate) {}
144 
145  bool get() const {return this->get_static_instance().get_state_();}
146  void set(bool val) {this->get_static_instance().set_state(val);}
147  operator bool() const {return get();}
148  bool operator=(bool val) {set(val); return val;}
149 };
150 
155 
156 
159 public:
160  advconfig_entry_string_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate, t_uint32 p_prefFlags)
161  : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate), m_prefFlags(p_prefFlags) {}
162  void get_name(pfc::string_base & p_out) {p_out = m_name;}
163  GUID get_guid() {return m_state.get_guid();}
164  GUID get_parent() {return m_parent;}
165  void reset() {core_api::ensure_main_thread();m_state = m_initialstate;}
166  double get_sort_priority() {return m_priority;}
167  void get_state(pfc::string_base & p_out) {core_api::ensure_main_thread();p_out = m_state;}
168  void set_state(const char * p_string,t_size p_length = ~0) {core_api::ensure_main_thread();m_state.set_string(p_string,p_length);}
169  t_uint32 get_flags() {return 0;}
170  void get_default_state(pfc::string_base & out) {out = m_initialstate;}
171  t_uint32 get_preferences_flags() {return m_prefFlags;}
172 private:
173  const pfc::string8 m_initialstate, m_name;
175  const double m_priority;
176  const GUID m_parent;
178 };
179 
182 class advconfig_string_factory : public service_factory_single_t<advconfig_entry_string_impl> {
183 public:
184  advconfig_string_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate, t_uint32 p_prefFlags = 0)
185  : service_factory_single_t<advconfig_entry_string_impl>(p_name,p_guid,p_parent,p_priority,p_initialstate, p_prefFlags) {}
186 
187  void get(pfc::string_base & out) {get_static_instance().get_state(out);}
188  void set(const char * in) {get_static_instance().set_state(in);}
189 };
190 
191 
194 public:
195  advconfig_entry_integer_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,t_uint64 p_initialstate,t_uint64 p_min,t_uint64 p_max, t_uint32 p_prefFlags)
196  : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initval(p_initialstate), m_min(p_min), m_max(p_max), m_state(p_guid,p_initialstate), m_prefFlags(p_prefFlags) {}
197  void get_name(pfc::string_base & p_out) {p_out = m_name;}
198  GUID get_guid() {return m_state.get_guid();}
199  GUID get_parent() {return m_parent;}
200  void reset() {m_state = m_initval;}
201  double get_sort_priority() {return m_priority;}
202  void get_state(pfc::string_base & p_out) {p_out = pfc::format_uint(m_state.get_value());}
203  void set_state(const char * p_string,t_size p_length) {set_state_int(pfc::atoui64_ex(p_string,p_length));}
205 
206  t_uint64 get_state_int() const {return m_state;}
207  void set_state_int(t_uint64 val) {m_state = pfc::clip_t<t_uint64>(val,m_min,m_max);}
208 
210  out = pfc::format_uint(m_initval);
211  }
213  val = pfc::format_uint( pfc::clip_t<t_uint64>(pfc::atoui64_ex(val,~0), m_min, m_max) );
214  }
215  t_uint32 get_preferences_flags() {return m_prefFlags;}
216 private:
218  const double m_priority;
219  const t_uint64 m_initval, m_min, m_max;
220  const GUID m_parent;
223 };
224 
227 class advconfig_integer_factory : public service_factory_single_t<advconfig_entry_integer_impl> {
228 public:
229  advconfig_integer_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,t_uint64 p_initialstate,t_uint64 p_min,t_uint64 p_max, t_uint32 p_prefFlags = 0)
230  : service_factory_single_t<advconfig_entry_integer_impl>(p_name,p_guid,p_parent,p_priority,p_initialstate,p_min,p_max,p_prefFlags) {}
231 
232  t_uint64 get() const {return get_static_instance().get_state_int();}
233  void set(t_uint64 val) {get_static_instance().set_state_int(val);}
234 
235  operator t_uint64() const {return get();}
236  t_uint64 operator=(t_uint64 val) {set(val); return val;}
237 };
238 
239 
241 class NOVTABLE advconfig_entry_enum : public advconfig_entry {
242 public:
243  virtual t_size get_value_count() = 0;
244  virtual void enum_value(pfc::string_base & p_out,t_size p_index) = 0;
245  virtual t_size get_state() = 0;
246  virtual void set_state(t_size p_value) = 0;
247 
248  FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_enum,advconfig_entry);
249 };
250 
251 
252 
253 
256 public:
257  advconfig_entry_string_impl_MT(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate, t_uint32 p_prefFlags)
258  : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate), m_prefFlags(p_prefFlags) {}
259  void get_name(pfc::string_base & p_out) {p_out = m_name;}
260  GUID get_guid() {return m_state.get_guid();}
261  GUID get_parent() {return m_parent;}
262  void reset() {
263  insync(m_sync);
264  m_state = m_initialstate;
265  }
266  double get_sort_priority() {return m_priority;}
267  void get_state(pfc::string_base & p_out) {
268  insync(m_sync);
269  p_out = m_state;
270  }
271  void set_state(const char * p_string,t_size p_length = ~0) {
272  insync(m_sync);
273  m_state.set_string(p_string,p_length);
274  }
275  t_uint32 get_flags() {return 0;}
276  void get_default_state(pfc::string_base & out) {out = m_initialstate;}
277  t_uint32 get_preferences_flags() {return m_prefFlags;}
278 private:
279  const pfc::string8 m_initialstate, m_name;
282  const double m_priority;
283  const GUID m_parent;
285 };
286 
288 class advconfig_string_factory_MT : public service_factory_single_t<advconfig_entry_string_impl_MT> {
289 public:
290  advconfig_string_factory_MT(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate, t_uint32 p_prefFlags = 0)
291  : service_factory_single_t<advconfig_entry_string_impl_MT>(p_name,p_guid,p_parent,p_priority,p_initialstate, p_prefFlags) {}
292 
293  void get(pfc::string_base & out) {get_static_instance().get_state(out);}
294  void set(const char * in) {get_static_instance().set_state(in);}
295 };
296 
297 
298 
299 
300 /*
301  Advanced Preferences variable declaration examples
302 
303  static advconfig_string_factory mystring("name goes here",myguid,parentguid,0,"asdf");
304  to retrieve state: pfc::string8 val; mystring.get(val);
305 
306  static advconfig_checkbox_factory mycheckbox("name goes here",myguid,parentguid,0,false);
307  to retrieve state: mycheckbox.get();
308 
309  static advconfig_integer_factory myint("name goes here",myguid,parentguid,0,initialValue,minimumValue,maximumValue);
310  to retrieve state: myint.get();
311 */
t_uint32 get_flags()
Definition: advconfig.h:204
t_uint32 get_preferences_flags()
Definition: advconfig.h:120
void ensure_main_thread()
Triggers a bug check if the calling thread is not the main app thread.
static const GUID guid_root
Definition: advconfig.h:24
GUID get_parent()
Definition: advconfig.h:111
const double m_priority
Definition: advconfig.h:282
cfg_string m_state
Definition: advconfig.h:174
advconfig_branch_factory(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority)
Definition: advconfig.h:133
Standard implementation of advconfig_branch. Usage: no need to use this class directly - use advconf...
Definition: advconfig.h:87
const pfc::string8 m_name
Definition: advconfig.h:173
advconfig_entry_string_impl(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, const char *p_initialstate, t_uint32 p_prefFlags)
Definition: advconfig.h:160
Definition: pfc.h:71
void reset()
Definition: advconfig.h:165
t_uint32 get_preferences_flags()
Definition: advconfig.h:215
uint64_t t_uint64
Definition: int_types.h:3
advconfig_checkbox_factory_t(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, bool p_initialstate)
Definition: advconfig.h:142
const t_uint32 m_prefFlags
Definition: advconfig.h:284
GUID m_parent
Definition: advconfig.h:125
GUID get_guid()
Definition: advconfig.h:110
t_uint32 get_flags()
Definition: advconfig.h:275
const pfc::string8 m_name
Definition: advconfig.h:279
double get_sort_priority()
Definition: advconfig.h:94
advconfig_checkbox_factory_t< false > advconfig_checkbox_factory
Service factory helper around standard advconfig_entry_checkbox implementation, specialized for check...
Definition: advconfig.h:152
Definition: advconfig.h:76
Service factory helper around standard advconfig_entry_checkbox implementation. Use this class to reg...
Definition: advconfig.h:140
const GUID m_parent
Definition: advconfig.h:220
const bool m_initialstate
Definition: advconfig.h:123
t_uint32 get_preferences_flags()
Definition: advconfig.h:277
void set_state_int(t_uint64 val)
Definition: advconfig.h:207
bool get_state_() const
Definition: advconfig.h:117
Creates a new branch in Advanced Preferences. Implementation: see advconfig_branch_impl / advconfig_...
Definition: advconfig.h:32
pfc::string8 m_name
Definition: advconfig.h:122
void set_state(bool p_state)
Definition: advconfig.h:114
void reset()
Definition: advconfig.h:262
double get_sort_priority()
Definition: advconfig.h:166
advconfig_entry_checkbox_impl(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, bool p_initialstate)
Definition: advconfig.h:106
Entrypoint class for adding items to Advanced Preferences page. Implementations must derive from one...
Definition: advconfig.h:4
t_uint32 get_preferences_flags()
Definition: advconfig.h:171
advconfig_entry_integer_impl(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, t_uint64 p_initialstate, t_uint64 p_min, t_uint64 p_max, t_uint32 p_prefFlags)
Definition: advconfig.h:195
FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_string, advconfig_entry)
Not currently used, reserved for future use.
Definition: advconfig.h:241
virtual FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_checkbox_v2, advconfig_entry_checkbox) public t_uint32 get_preferences_flags()
Definition: advconfig.h:55
Definition: advconfig.h:51
const double m_priority
Definition: advconfig.h:175
double get_sort_priority()
Definition: advconfig.h:116
bool get_default_state_() const
Definition: advconfig.h:119
static bool g_find_t(outptr &out, const GUID &id)
Definition: advconfig.h:18
GUID get_parent()
Definition: advconfig.h:199
cfg_string m_state
Definition: advconfig.h:280
const pfc::string8 m_name
Definition: advconfig.h:221
const t_uint32 m_prefFlags
Definition: advconfig.h:177
double get_sort_priority()
Definition: advconfig.h:266
static bool g_find(service_ptr_t< advconfig_entry > &out, const GUID &id)
Definition: advconfig.h:14
const t_uint32 m_prefFlags
Definition: advconfig.h:222
void get_default_state(pfc::string_base &out)
Definition: advconfig.h:209
void reset()
Definition: advconfig.h:112
Standard implementation of advconfig_entry_checkbox. p_is_radio parameter controls whether we&#39;re imp...
Definition: advconfig.h:104
size_t t_size
Definition: int_types.h:48
double get_sort_priority()
Definition: advconfig.h:201
const double m_priority
Definition: advconfig.h:98
advconfig_string_factory(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, const char *p_initialstate, t_uint32 p_prefFlags=0)
Definition: advconfig.h:184
bool get_state()
Definition: advconfig.h:113
Special advconfig_entry_string implementation - implements integer entries. Use advconfig_integer_fac...
Definition: advconfig.h:193
FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_checkbox, advconfig_entry)
cfg_bool m_state
Definition: advconfig.h:124
t_uint64 atoui64_ex(const char *src, t_size len)
Service factory helper around standard advconfig_entry_string implementation. Use this class to regis...
Definition: advconfig.h:182
void set_state(const char *p_string, t_size p_length)
Definition: advconfig.h:203
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
advconfig_integer_factory(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, t_uint64 p_initialstate, t_uint64 p_min, t_uint64 p_max, t_uint32 p_prefFlags=0)
Definition: advconfig.h:229
const t_uint64 m_min
Definition: advconfig.h:219
advconfig_checkbox_factory_t< true > advconfig_radio_factory
Service factory helper around standard advconfig_entry_checkbox implementation, specialized for radio...
Definition: advconfig.h:154
const GUID m_parent
Definition: advconfig.h:176
void validate(pfc::string_base &val)
Definition: advconfig.h:212
String config variable. Stored in the stream with int32 header containing size in bytes...
Definition: cfg_var.h:97
GUID get_guid()
Definition: advconfig.h:198
Service factory helper around integer-specialized advconfig_entry_string implementation. Use this class to register your own integer entries in Advanced Preferences. Usage: static advconfig_integer_factory myint(name, itemID, parentID, priority, initialValue, minValue, maxValue);.
Definition: advconfig.h:227
t_uint64 get_state_int() const
Definition: advconfig.h:206
void set_state(const char *p_string, t_size p_length=~0)
Definition: advconfig.h:271
GUID get_guid()
Definition: advconfig.h:260
GUID get_guid()
Definition: advconfig.h:163
pfc::string8 m_name
Definition: advconfig.h:96
const GUID m_parent
Definition: advconfig.h:283
bool is_radio()
Definition: advconfig.h:115
void set_state(const char *p_string, t_size p_length=~0)
Definition: advconfig.h:168
Service factory helper around standard advconfig_branch implementation. Use this class to register yo...
Definition: advconfig.h:131
Creates a string/integer editbox entry in Advanced Preferences. Implementation: see advconfig_entry_s...
Definition: advconfig.h:60
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
GUID get_parent()
Definition: advconfig.h:261
const double m_priority
Definition: advconfig.h:218
void get_default_state(pfc::string_base &out)
Definition: advconfig.h:276
const double m_priority
Definition: advconfig.h:126
bool operator=(bool val)
Definition: advconfig.h:148
Creates a checkbox/radiocheckbox entry in Advanced Preferences. The difference between checkboxes an...
Definition: advconfig.h:40
void get_default_state(pfc::string_base &out)
Definition: advconfig.h:170
void get_state(pfc::string_base &p_out)
Definition: advconfig.h:167
void get_name(pfc::string_base &p_out)
Definition: advconfig.h:90
cfg_int_t< t_uint64 > m_state
Definition: advconfig.h:217
void get_name(pfc::string_base &p_out)
Definition: advconfig.h:109
t_uint32 get_flags()
Definition: advconfig.h:169
void get_name(pfc::string_base &p_out)
Definition: advconfig.h:197
bool get_default_state()
Definition: advconfig.h:118
void get_state(pfc::string_base &p_out)
Definition: advconfig.h:267
advconfig_entry_string_impl_MT(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, const char *p_initialstate, t_uint32 p_prefFlags)
Definition: advconfig.h:257
Definition: advconfig.h:69
Special version if advconfig_entry_string_impl that allows the value to be retrieved from worker thre...
Definition: advconfig.h:255
critical_section m_sync
Definition: advconfig.h:281
void get_name(pfc::string_base &p_out)
Definition: advconfig.h:162
t_uint64 operator=(t_uint64 val)
Definition: advconfig.h:236
GUID get_parent()
Definition: advconfig.h:164
virtual FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_string_v2, advconfig_entry_string) public void validate(pfc::string_base &val)
Definition: advconfig.h:80
Special version if advconfig_string_factory that allows the value to be retrieved from worker threads...
Definition: advconfig.h:288
advconfig_branch_impl(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority)
Definition: advconfig.h:89
void reset()
Definition: advconfig.h:200
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
void get_state(pfc::string_base &p_out)
Definition: advconfig.h:202
static const GUID guid_branch_tools
Definition: advconfig.h:25
uint32_t t_uint32
Definition: int_types.h:5
Standard advconfig_entry_string implementation. Use advconfig_string_factory to register your own str...
Definition: advconfig.h:158
virtual t_uint32 get_preferences_flags()
Definition: advconfig.h:81
void get_name(pfc::string_base &p_out)
Definition: advconfig.h:259
advconfig_string_factory_MT(const char *p_name, const GUID &p_guid, const GUID &p_parent, double p_priority, const char *p_initialstate, t_uint32 p_prefFlags=0)
Definition: advconfig.h:290