foobar2000 SDK  2015-08-03
cfg_var.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
5 
7 {
9  for(cfg_var_reader * walk = g_list; walk != NULL; walk = walk->m_next) {
10  vars.set(walk->m_guid,walk);
11  }
12  for(;;) {
13 
14  GUID guid;
15  t_uint32 size;
16 
17  if (p_stream->read(&guid,sizeof(guid),p_abort) != sizeof(guid)) break;
18  guid = pfc::byteswap_if_be_t(guid);
19  p_stream->read_lendian_t(size,p_abort);
20 
21  cfg_var_reader * var;
22  if (vars.query(guid,var)) {
23  stream_reader_limited_ref wrapper(p_stream,size);
24  try {
25  var->set_data_raw(&wrapper,size,p_abort);
26  } catch(exception_io_data) {}
27  wrapper.flush_remaining(p_abort);
28  } else {
29  p_stream->skip_object(size,p_abort);
30  }
31  }
32 }
33 
35  cfg_var_writer * ptr;
37  for(ptr = g_list; ptr; ptr = ptr->m_next) {
38  temp.set_size(0);
39  {
41  ptr->get_data_raw(&stream,p_abort);
42  }
43  p_stream->write_lendian_t(ptr->m_guid,p_abort);
44  p_stream->write_lendian_t(pfc::downcast_guarded<t_uint32>(temp.get_size()),p_abort);
45  if (temp.get_size() > 0) {
46  p_stream->write_object(temp.get_ptr(),temp.get_size(),p_abort);
47  }
48  }
49 }
50 
51 
53  p_stream->write_object(get_ptr(),length(),p_abort);
54 }
55 
56 void cfg_string::set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) {
58  p_stream->read_string_raw(temp,p_abort);
59  set_string(temp);
60 }
Definition: map.h:16
const t_item * get_ptr() const
Definition: array.h:213
virtual void set_data_raw(stream_reader *p_stream, t_size p_sizehint, abort_callback &p_abort)=0
Sets state of the variable. Called only from main thread, when reading configuration file...
static void config_write_file(stream_writer *p_stream, abort_callback &p_abort)
For internal use only, do not call.
Definition: cfg_var.cpp:34
Definition: pfc.h:71
cfg_var_reader * m_next
Definition: cfg_var.h:25
virtual void get_data_raw(stream_writer *p_stream, abort_callback &p_abort)=0
Retrieves state of the variable. Called only from main thread, when writing configuration file...
void set_data_raw(stream_reader *p_stream, t_size p_sizehint, abort_callback &p_abort)
Sets state of the variable. Called only from main thread, when reading configuration file...
Definition: cfg_var.cpp:56
static void config_read_file(stream_reader *p_stream, abort_callback &p_abort)
For internal use only, do not call.
Definition: cfg_var.cpp:6
void flush_remaining(abort_callback &p_abort)
Reader part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_reader ...
Definition: cfg_var.h:8
static cfg_var_reader * g_list
Definition: cfg_var.h:24
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
static cfg_var_writer * g_list
Definition: cfg_var.h:46
void get_data_raw(stream_writer *p_stream, abort_callback &p_abort)
Retrieves state of the variable. Called only from main thread, when writing configuration file...
Definition: cfg_var.cpp:52
void set(const _t_key &p_key, const _t_value &p_value)
Definition: map.h:22
Writer part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_writer ...
Definition: cfg_var.h:31
t_size get_size() const
Definition: array.h:130
T byteswap_if_be_t(T p_param)
const GUID m_guid
Definition: cfg_var.h:44
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
uint32_t t_uint32
Definition: int_types.h:5
cfg_var_writer * m_next
Definition: cfg_var.h:47
bool query(const _t_key &p_key, _t_value &p_value) const
Definition: map.h:44