00001 #ifndef _FOOBAR2000_SDK_CFG_VAR_H_
00002 #define _FOOBAR2000_SDK_CFG_VAR_H_
00003
00006 class NOVTABLE cfg_var {
00007 protected:
00009 cfg_var(const GUID & p_guid) : m_guid(p_guid) {PFC_ASSERT(!core_api::are_services_available());next=list;list=this;};
00010 ~cfg_var() {PFC_ASSERT(!core_api::are_services_available());}
00011 public:
00014 virtual void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) = 0;
00018 virtual void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) = 0;
00019
00021 inline const GUID & get_guid() const {return m_guid;}
00022
00024 static void config_read_file(stream_reader * p_stream,abort_callback & p_abort);
00026 static void config_write_file(stream_writer * p_stream,abort_callback & p_abort);
00027 private:
00028 GUID m_guid;
00029 static cfg_var * list;
00030 cfg_var * next;
00031
00032 cfg_var(const cfg_var& ) {throw pfc::exception_not_implemented();}
00033 const cfg_var & operator=(const cfg_var& ) {throw pfc::exception_not_implemented();}
00034 };
00035
00038 template<typename t_inttype>
00039 class cfg_int_t : public cfg_var {
00040 private:
00041 t_inttype m_val;
00042 protected:
00043 void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {p_stream->write_lendian_t(m_val,p_abort);}
00044 void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) {
00045 t_inttype temp;
00046 p_stream->read_lendian_t(temp,p_abort);
00047 m_val = temp;
00048 }
00049
00050 public:
00053 explicit inline cfg_int_t(const GUID & p_guid,t_inttype p_default) : cfg_var(p_guid), m_val(p_default) {}
00054
00055 inline const cfg_int_t<t_inttype> & operator=(const cfg_int_t<t_inttype> & p_val) {m_val=p_val.m_val;return *this;}
00056 inline t_inttype operator=(t_inttype p_val) {m_val=p_val;return m_val;}
00057
00058 inline operator t_inttype() const {return m_val;}
00059
00060 inline t_inttype get_value() const {return m_val;}
00061 };
00062
00063 typedef cfg_int_t<t_int32> cfg_int;
00064 typedef cfg_int_t<t_uint32> cfg_uint;
00066 typedef cfg_int_t<GUID> cfg_guid;
00067 typedef cfg_int_t<bool> cfg_bool;
00068
00071 class cfg_string : public cfg_var, public pfc::string8
00072 {
00073 protected:
00074 void get_data_raw(stream_writer * p_stream,abort_callback & p_abort);
00075 void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort);
00076
00077 public:
00080 explicit inline cfg_string(const GUID & p_guid,const char * p_defaultval) : cfg_var(p_guid), pfc::string8(p_defaultval) {}
00081
00082 inline const cfg_string& operator=(const cfg_string & p_val) {set_string(p_val);return *this;}
00083 inline const cfg_string& operator=(const char* p_val) {set_string(p_val);return *this;}
00084
00085 inline operator const char * () const {return get_ptr();}
00086
00087 };
00088
00091 template<typename t_struct>
00092 class cfg_struct_t : public cfg_var {
00093 private:
00094 t_struct m_val;
00095 protected:
00096
00097 void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {p_stream->write_object(&m_val,sizeof(m_val),p_abort);}
00098 void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) {
00099 t_struct temp;
00100 p_stream->read_object(&temp,sizeof(temp),p_abort);
00101 m_val = temp;
00102 }
00103 public:
00105 inline cfg_struct_t(const GUID & p_guid,const t_struct & p_val) : cfg_var(p_guid), m_val(p_val) {}
00107 inline cfg_struct_t(const GUID & p_guid,int filler) : cfg_var(p_guid) {memset(&m_val,filler,sizeof(t_struct));}
00108
00109 inline const cfg_struct_t<t_struct> & operator=(const cfg_struct_t<t_struct> & p_val) {m_val = p_val.get_value();return *this;}
00110 inline const cfg_struct_t<t_struct> & operator=(const t_struct & p_val) {m_val = p_val;return *this;}
00111
00112 inline const t_struct& get_value() const {return m_val;}
00113 inline t_struct& get_value() {return m_val;}
00114 inline operator t_struct() const {return m_val;}
00115 };
00116
00117
00118 #endif