00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_RUTZ_ASSOCARRAY_H_UTC20050626084020_DEFINED
00035 #define GROOVX_RUTZ_ASSOCARRAY_H_UTC20050626084020_DEFINED
00036
00037 #include "rutz/fstring.h"
00038
00039 namespace rutz
00040 {
00041 class file_pos;
00042
00043
00045
00048 class assoc_array_base
00049 {
00050 public:
00052 typedef void (kill_func_t) (void*);
00053
00055
00064 assoc_array_base(kill_func_t* f, const char* descr, bool nocase);
00065
00067 ~assoc_array_base();
00068
00070 rutz::fstring get_known_keys(const char* sep) const;
00071
00073 void throw_for_key(const char* key,
00074 const rutz::file_pos& pos) const;
00075
00077 void throw_for_key(const rutz::fstring& key,
00078 const rutz::file_pos& pos) const;
00079
00081 void* get_value_for_key(const rutz::fstring& name) const;
00082
00084 void* get_value_for_key(const char* name) const;
00085
00087 void set_value_for_key(const char* name, void* ptr);
00088
00090 void clear();
00091
00092 private:
00093 assoc_array_base(const assoc_array_base&);
00094 assoc_array_base& operator=(const assoc_array_base&);
00095
00096 struct impl;
00097 impl* const rep;
00098 };
00099
00100
00102
00103 template<class value_t>
00104 class assoc_array
00105 {
00106 public:
00108
00117 assoc_array(const char* descr, bool nocase = false)
00118 : base(&delete_ptr, descr, nocase) {}
00119
00121 rutz::fstring get_known_keys(const char* sep) const
00122 { return base.get_known_keys(sep); }
00123
00125 void throw_for_key(const char* key,
00126 const rutz::file_pos& pos) const
00127 { base.throw_for_key(key, pos); }
00128
00130 void throw_for_key(const rutz::fstring& key,
00131 const rutz::file_pos& pos) const
00132 { base.throw_for_key(key, pos); }
00133
00135 value_t* get_ptr_for_key(const rutz::fstring& key) const
00136 { return static_cast<value_t*>(base.get_value_for_key(key)); }
00137
00139 value_t* get_ptr_for_key(const char* key) const
00140 { return static_cast<value_t*>(base.get_value_for_key(key)); }
00141
00143 void set_ptr_for_key(const char* key, value_t* ptr)
00144 { base.set_value_for_key(key, static_cast<void*>(ptr)); }
00145
00146 private:
00147 rutz::assoc_array_base base;
00148
00149 static void delete_ptr(void* ptr)
00150 { delete static_cast<value_t*>(ptr); }
00151 };
00152 }
00153
00154 static const char __attribute__((used)) vcid_groovx_rutz_assocarray_h_utc20050626084020[] = "$Id: assocarray.h 10097 2007-08-07 19:08:27Z rjpeters $ $HeadURL: file:
00155 #endif // !GROOVX_RUTZ_ASSOCARRAY_H_UTC20050626084020_DEFINED