1 #ifndef _FOOBAR2000_SDK_CFG_VAR_H_ 2 #define _FOOBAR2000_SDK_CFG_VAR_H_ 4 #define CFG_VAR_ASSERT_SAFEINIT PFC_ASSERT(!core_api::are_services_available()); 11 cfg_var_reader(
const GUID & guid) : m_guid(guid) { CFG_VAR_ASSERT_SAFEINIT; m_next = g_list; g_list =
this; }
34 cfg_var_writer(
const GUID & guid) : m_guid(guid) { CFG_VAR_ASSERT_SAFEINIT; m_next = g_list; g_list =
this;}
64 template<
typename t_
inttype>
72 p_stream->read_lendian_t(temp,p_abort);
82 inline t_inttype
operator=(t_inttype p_val) {m_val=p_val;
return m_val;}
84 inline operator t_inttype()
const {
return m_val;}
110 inline operator const char * ()
const {
return get_ptr();}
118 p_stream->write_object(m_val.get_ptr(),m_val.length(),p_abort);
122 p_stream->read_string_raw(temp,p_abort);
131 void set(
const char * val,
t_size valLen = ~0) {
133 m_val.set_string(val, valLen);
142 template<
typename t_struct>
151 p_stream->read_object(&temp,
sizeof(temp),p_abort);
163 inline const t_struct&
get_value()
const {
return m_val;}
165 inline operator t_struct()
const {
return m_val;}
169 template<
typename TObj>
174 template<
typename TSource,
unsigned Count>
cfg_objList(
const GUID& guid,
const TSource (& source)[Count]) :
cfg_var(guid) {
177 template<
typename TSource,
unsigned Count>
void reset(
const TSource (& source)[Count]) {
178 this->set_size(Count);
for(
t_size walk = 0; walk < Count; ++walk) (*
this)[walk] = source[walk];
182 out << pfc::downcast_guarded<t_uint32>(this->
get_size());
183 for(
t_size walk = 0; walk < this->
get_size(); ++walk) out << (*
this)[walk];
189 this->set_count(count);
190 for(
t_uint32 walk = 0; walk < count; ++walk) in >> (*this)[walk];
196 template<
typename t_in> t_self &
operator=(t_in
const & source) {this->remove_all(); this->add_items(source);
return *
this;}
197 template<
typename t_in> t_self &
operator+=(t_in
const & p_source) {this->add_item(p_source);
return *
this;}
198 template<
typename t_in> t_self &
operator|=(t_in
const & p_source) {this->add_items(p_source);
return *
this;}
200 template<
typename TList>
207 out << pfc::downcast_guarded<t_uint32>(this->get_count());
208 for(
typename TList::const_iterator walk = this->first(); walk.is_valid(); ++walk) out << *walk;
214 for(
t_uint32 walk = 0; walk < count; ++walk) {
215 typename TList::t_item item; in >> item; this->add_item(item);
218 template<
typename t_in> t_self &
operator=(t_in
const & source) {this->remove_all(); this->add_items(source);
return *
this;}
219 template<
typename t_in> t_self &
operator+=(t_in
const & p_source) {this->add_item(p_source);
return *
this;}
220 template<
typename t_in> t_self &
operator|=(t_in
const & p_source) {this->add_items(p_source);
return *
this;}
223 template<
typename TObj>
234 const TObj * ptr =
this;
255 m_var.set_count(count);
256 for(
t_uint32 walk = 0; walk < count; ++walk) {
273 out << pfc::downcast_guarded<t_uint32>(this->get_count());
274 for(
typename TMap::const_iterator walk = this->first(); walk.is_valid(); ++walk) {
275 out << walk->m_key << walk->m_value;
282 for(
t_uint32 walk = 0; walk < count; ++walk) {
283 typename TMap::t_key key; in >> key; PFC_ASSERT( !this->have_item(key) );
284 try { in >> this->find_or_add( key ); }
catch(...) { this->
remove(key);
throw; }
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...
cfg_string_mt(const GUID &id, const char *defVal)
t_filesize get_size(HANDLE p_handle)
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...
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...
const cfg_struct_t< t_struct > & operator=(const cfg_struct_t< t_struct > &p_val)
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...
cfg_objList(const GUID &guid, const TSource(&source)[Count])
cfg_struct_t(const GUID &p_guid, int filler)
t_inttype get_value() const
t_inttype operator=(t_inttype p_val)
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...
cfg_objListImporter(TMasterVar &var, const GUID &guid)
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...
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...
cfg_int_t(const GUID &p_guid, t_inttype p_default)
cfg_var(const GUID &p_guid)
const t_struct & get_value() const
cfg_obj(const GUID &guid, const TInitData &initData)
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...
string8_t< pfc::alloc_standard > string8
cfg_objListEx< TList > t_self
cfg_objMap(const GUID &id)
t_self & operator|=(t_in const &p_source)
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...
Reader part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_reader ...
t_self & operator=(t_in const &source)
static cfg_var_reader * g_list
cfg_int_t< t_uint32 > cfg_uint
cfg_int_t< GUID > cfg_guid
Since relevant byteswapping functions also understand GUIDs, this can be abused to declare a cfg_guid...
cfg_obj(const GUID &guid)
const cfg_string & operator=(const char *p_val)
static cfg_var_writer * g_list
Generic integer config variable class. Template parameter can be used to specify integer type to use...
cfg_struct_t(const GUID &p_guid, const t_struct &p_val)
t_self & operator=(t_in const &source)
cfg_objList(const GUID &guid)
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...
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...
String config variable. Stored in the stream with int32 header containing size in bytes...
cfg_objList< TObj > t_self
t_self & operator+=(t_in const &p_source)
const cfg_int_t< t_inttype > & operator=(const cfg_int_t< t_inttype > &p_val)
void reset(const TSource(&source)[Count])
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...
const cfg_string & operator=(const cfg_string &p_val)
t_self & operator+=(t_in const &p_source)
Struct config variable template. Warning: not endian safe, should be used only for nonportable code...
cfg_objListEx(const GUID &guid)
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...
cfg_int_t< t_int32 > cfg_int
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...
Writer part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_writer ...
cfg_int_t< bool > cfg_bool
t_self & operator|=(t_in const &p_source)
cfg_var_writer(const GUID &guid)
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...
Base class for configuration variable classes; provides self-registration mechaisms and methods to se...
cfg_var_reader(const GUID &guid)
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
cfg_objList< TObj > TMasterVar
const cfg_struct_t< t_struct > & operator=(const t_struct &p_val)
cfg_string(const GUID &p_guid, const char *p_defaultval)