From 9cd3ccffd5372dfde3af478e3f832f18db4be3f1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:41 +0200 Subject: tagging tags --- ychat-0.7.6/src/maps/hashmap.tmpl | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ychat-0.7.6/src/maps/hashmap.tmpl (limited to 'ychat-0.7.6/src/maps/hashmap.tmpl') diff --git a/ychat-0.7.6/src/maps/hashmap.tmpl b/ychat-0.7.6/src/maps/hashmap.tmpl new file mode 100644 index 0000000..e9da338 --- /dev/null +++ b/ychat-0.7.6/src/maps/hashmap.tmpl @@ -0,0 +1,74 @@ +template +obj_type +hashmap::get_set_elem(obj_type t_obj, string s_key) +{ + typename hashmap::iterator iter = this->find(s_key); + + if ( iter == this->end() ) + { + set_elem(t_obj, s_key); + return obj_type(); + } + + obj_type t_ret = iter->second; + iter->second = t_obj; + + return t_ret; +} + +template +void +hashmap::set_elem(obj_type t_obj, string s_key) +{ + (*this)[s_key] = t_obj; +} + +template +obj_type +hashmap::get_elem(string s_key) +{ + typename hashmap::iterator iter = this->find(s_key); + + if ( iter != this->end() ) + return iter->second; + + return obj_type(); +} + +template +vector* +hashmap::get_key_vector() +{ + vector* p_vec = new vector; + typename hashmap::iterator iter; + + for ( iter = this->begin(); iter != this->end(); ++iter ) + p_vec->push_back(iter->first); + + return p_vec; +} + +template +bool +hashmap::exists(string s_key) +{ + return this->find(s_key) != this->end(); +} + +template +void +hashmap::run_func( void (*func)(obj_type) ) +{ + typename hashmap::iterator iter; + for ( iter = this->begin(); iter != this->end(); ++iter ) + ( *func ) ( iter->second ); +} + +template +void +hashmap::run_func( void (*func)(obj_type, void*), void* v_arg ) +{ + typename hashmap::iterator iter; + for ( iter = this->begin(); iter != this->end(); ++iter ) + ( *func ) ( iter->second, v_arg ); +} -- cgit v1.2.3