diff options
Diffstat (limited to 'src/maps/shashmap.tmpl')
| -rw-r--r-- | src/maps/shashmap.tmpl | 142 |
1 files changed, 85 insertions, 57 deletions
diff --git a/src/maps/shashmap.tmpl b/src/maps/shashmap.tmpl index 6a70f61..0bd5796 100644 --- a/src/maps/shashmap.tmpl +++ b/src/maps/shashmap.tmpl @@ -1,129 +1,157 @@ -template<class obj_type> -shashmap<obj_type>::shashmap() +template<class obj_type, class key_type_, class hash_type, class alloc_type> +shashmap<obj_type, key_type_, hash_type, alloc_type>::shashmap() { - pthread_mutex_init( &mut_shashmap, NULL ); + pthread_mutex_init( &mut_shashmap, NULL ); } -template<class obj_type> -shashmap<obj_type>::~shashmap() +template<class obj_type, class key_type_, class hash_type, class alloc_type> +shashmap<obj_type, key_type_, hash_type, alloc_type>::~shashmap() { - pthread_mutex_destroy( &mut_shashmap ); + pthread_mutex_destroy( &mut_shashmap ); } -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::add_elem(obj_type t_obj, string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::add_elem(obj_type t_obj, key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - (*this)[s_key] = t_obj; + (*this)[t_key] = t_obj; pthread_mutex_unlock( &mut_shashmap ); -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::add_elem_insecure(obj_type t_obj, string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::add_elem_insecure(obj_type t_obj, key_type_ t_key) +{ + (*this)[t_key] = t_obj; +} + +template<class obj_type, class key_type_, class hash_type, class alloc_type> +obj_type +shashmap<obj_type, key_type_, hash_type, alloc_type>::get_set_elem(obj_type t_obj, key_type_ t_key) { - (*this)[s_key] = t_obj; -} + pthread_mutex_lock( &mut_shashmap ); + obj_type t_ret = hashmap<obj_type, key_type_, hash_type, alloc_type>::get_set_elem(t_obj, t_key); + pthread_mutex_unlock( &mut_shashmap ); + return t_ret; +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> obj_type -shashmap<obj_type>::get_set_elem(obj_type t_obj, string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::get_or_callback_set +(obj_type (*func)(void*), void* p_void, key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - obj_type t_ret = hashmap<obj_type>::get_set_elem(t_obj, s_key); + obj_type t_ret = hashmap<obj_type, key_type_, hash_type, alloc_type>::get_or_callback_set + (func, p_void, t_key); pthread_mutex_unlock( &mut_shashmap ); return t_ret; -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::set_elem(obj_type t_obj, string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::set_elem(obj_type t_obj, key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - (*this)[s_key] = t_obj; + (*this)[t_key] = t_obj; pthread_mutex_unlock( &mut_shashmap ); -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> obj_type -shashmap<obj_type>::get_elem(string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::get_elem(key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - obj_type t_ret = hashmap<obj_type>::get_elem(s_key); + obj_type t_ret = hashmap<obj_type, key_type_, hash_type, alloc_type>::get_elem(t_key); pthread_mutex_unlock( &mut_shashmap ); return t_ret; -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::del_elem(string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::del_elem(key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - hashmap<obj_type>::erase(s_key); + hashmap<obj_type, key_type_, hash_type, alloc_type>::erase(t_key); pthread_mutex_unlock( &mut_shashmap ); -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::del_elem_insecure(string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::del_elem_insecure(key_type_ t_key) { - hashmap<obj_type>::erase(s_key); -} + hashmap<obj_type, key_type_, hash_type, alloc_type>::erase(t_key); +} -template<class obj_type> -vector<string>* -shashmap<obj_type>::get_key_vector() +template<class obj_type, class key_type_, class hash_type, class alloc_type> +vector<key_type_>* +shashmap<obj_type, key_type_, hash_type, alloc_type>::get_key_vector() { pthread_mutex_lock( &mut_shashmap ); - vector<string>* p_vec = hashmap<obj_type>::get_key_vector(); + vector<key_type_>* p_vec = hashmap<obj_type, key_type_, hash_type, alloc_type>::get_key_vector(); pthread_mutex_unlock( &mut_shashmap ); return p_vec; -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::clear() +shashmap<obj_type, key_type_, hash_type, alloc_type>::clear() { pthread_mutex_lock( &mut_shashmap ); - hashmap<obj_type>::clear(); + hashmap<obj_type, key_type_, hash_type, alloc_type>::clear(); pthread_mutex_unlock( &mut_shashmap ); -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> int -shashmap<obj_type>::size() +shashmap<obj_type, key_type_, hash_type, alloc_type>::size() { pthread_mutex_lock( &mut_shashmap ); - int i_size = hashmap<obj_type>::size(); + int i_size = hashmap<obj_type, key_type_, hash_type, alloc_type>::size(); pthread_mutex_unlock( &mut_shashmap ); return i_size; -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> bool -shashmap<obj_type>::exists(string s_key) +shashmap<obj_type, key_type_, hash_type, alloc_type>::exists(key_type_ t_key) { pthread_mutex_lock( &mut_shashmap ); - bool b_ret = hashmap<obj_type>::exists(s_key); + bool b_ret = hashmap<obj_type, key_type_, hash_type, alloc_type>::exists(t_key); pthread_mutex_unlock( &mut_shashmap ); return b_ret; -} +} -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::run_func( void (*func)(obj_type) ) +shashmap<obj_type, key_type_, hash_type, alloc_type>::run_func( void (*func)(obj_type) ) { pthread_mutex_lock( &mut_shashmap ); - hashmap<obj_type>::run_func(func); + hashmap<obj_type, key_type_, hash_type, alloc_type>::run_func(func); pthread_mutex_unlock( &mut_shashmap ); } -template<class obj_type> +template<class obj_type, class key_type_, class hash_type, class alloc_type> void -shashmap<obj_type>::run_func( void (*func)(obj_type, void*), void* v_arg ) +shashmap<obj_type, key_type_, hash_type, alloc_type>::run_func( void (*func)(obj_type, void*), void* v_arg ) { pthread_mutex_lock( &mut_shashmap ); - hashmap<obj_type>::run_func(func, v_arg); + hashmap<obj_type, key_type_, hash_type, alloc_type>::run_func(func, v_arg); pthread_mutex_unlock( &mut_shashmap ); } + +template<class obj_type, class key_type_, class hash_type, class alloc_type> +void +shashmap<obj_type, key_type_, hash_type, alloc_type>::dumpit() +{ + dumpable::add + ("[shashmap]"); + vector<key_type_>* p_vec = get_key_vector(); + + typename vector<key_type_>::iterator iter; + for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) + dumpable::add + (*iter); + + delete p_vec; +} |
