From c8b2ef7b899766d04562f7e04a84251cea8fa701 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:44 +0200 Subject: tagging ychat-0.8.0 --- src/memb/memb.h | 50 +++++++++++++++++++++++++++++++++++++-- src/memb/memb.tmpl | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/memb/tupel.h | 2 ++ src/memb/tupel.tmpl | 14 +++++------ 4 files changed, 122 insertions(+), 11 deletions(-) (limited to 'src/memb') diff --git a/src/memb/memb.h b/src/memb/memb.h index 9c398ec..f0df6ed 100644 --- a/src/memb/memb.h +++ b/src/memb/memb.h @@ -2,7 +2,8 @@ #define MEMB_H #include "../incl.h" -#include "../maps/nhashmap.h" +#include "../wrap.h" +#include "../maps/hashmap.h" #include "tupel.h" using namespace std; @@ -11,13 +12,58 @@ template class memb { private: - nhashmap< mutexed_tupel* > map_elems; + hashmap< mutexed_tupel* > map_elems; public: + memb() + {} + memb(vector &vec_fields); + void initialize(vector &vec_fields); inline obj_type get_elem(string s_key); inline void set_elem(obj_type t_obj, string s_key); +}; +struct memb_string : protected memb +{ + memb_string() + {} + memb_string(vector &vec_fields) : memb(vec_fields) + {} + void init_strings(vector vec_fields) + { + initialize(vec_fields); + } + inline string get_string(string s_key); + inline void set_string(string s_obj, string s_key); +}; + +struct memb_int : protected memb +{ + memb_int() + {} + void init_ints(vector vec_fields) + { + initialize(vec_fields); + } + inline int get_int(string s_key); + inline void set_int(int i_obj, string s_key); }; +struct memb_bool : protected memb +{ + memb_bool() + {} + void init_bools(vector vec_fields) + { + initialize(vec_fields); + } + inline bool get_bool(string s_key); + inline void set_bool(bool b_obj, string s_key); +}; + +class memb_base : public memb_string, public memb_int, public memb_bool + {} +; + #include "memb.tmpl" #endif diff --git a/src/memb/memb.tmpl b/src/memb/memb.tmpl index 0b4da0e..5c745cc 100644 --- a/src/memb/memb.tmpl +++ b/src/memb/memb.tmpl @@ -1,3 +1,20 @@ + +template +memb::memb(vector &vec_fields) +{ + initialize(vec_fields); +} + +template +void +memb::initialize(vector &vec_fields) +{ + obj_type t_default; + vector::iterator iter; + for (iter = vec_fields.begin(); iter != vec_fields.end(); ++iter) + map_elems[*iter] = new mutexed_tupel(t_default); +} + template obj_type memb::get_elem(string s_key) @@ -6,12 +23,58 @@ memb::get_elem(string s_key) if ( p_tupel ) return p_tupel->get_elem(); - return obj_type(); + obj_type t_ret; + return t_ret; } template void memb::set_elem(obj_type t_obj, string s_key) { - // mutexed_tupel *p_tupel = map_elems + mutexed_tupel *p_tupel = map_elems.get_elem(s_key); + if ( p_tupel ) + { + p_tupel->set_elem(t_obj); + return; + } + + //wrap::system_message(MEMBERE+string("("+s_key+")")); +} + +string +memb_string::get_string(string s_key) +{ + return get_elem(s_key); +} + +void +memb_string::set_string(string s_obj, string s_key) +{ + set_elem(s_obj, s_key); +} + +int +memb_int::get_int(string s_key) +{ + return get_elem(s_key); +} + +void +memb_int::set_int(int i_obj, string s_key) +{ + set_elem(i_obj, s_key); } + +bool +memb_bool::get_bool(string s_key) +{ + return get_elem(s_key); +} + +void +memb_bool::set_bool(bool b_obj, string s_key) +{ + set_elem(b_obj, s_key); +} + + diff --git a/src/memb/tupel.h b/src/memb/tupel.h index bb1939e..864a092 100644 --- a/src/memb/tupel.h +++ b/src/memb/tupel.h @@ -13,7 +13,9 @@ class tupel private: pthread_mutex_t mut_tupel; obj_type t_obj; + public: + tupel(); tupel(obj_type t_obj); ~tupel(); diff --git a/src/memb/tupel.tmpl b/src/memb/tupel.tmpl index bdde516..ab42748 100644 --- a/src/memb/tupel.tmpl +++ b/src/memb/tupel.tmpl @@ -1,29 +1,29 @@ template tupel::tupel() { - pthread_mutex_init( &mut_tupel, NULL ); + pthread_mutex_init(&mut_tupel, NULL); } template tupel::tupel(obj_type t_obj) { this->t_obj = t_obj; - pthread_mutex_init( &mut_tupel, NULL ); + pthread_mutex_init(&mut_tupel, NULL); } template tupel::~tupel() { - pthread_mutex_destroy( &mut_tupel ); + pthread_mutex_destroy(&mut_tupel); } template obj_type tupel::get_elem() { - pthread_mutex_lock( &mut_tupel ); + pthread_mutex_lock(&mut_tupel); obj_type t_ret = t_obj; - pthread_mutex_unlock( &mut_tupel ); + pthread_mutex_unlock(&mut_tupel); return t_ret; } @@ -31,7 +31,7 @@ template void tupel::set_elem(obj_type t_obj) { - pthread_mutex_lock( &mut_tupel ); + pthread_mutex_lock(&mut_tupel); this->t_obj = t_obj; - pthread_mutex_unlock( &mut_tupel ); + pthread_mutex_unlock(&mut_tupel); } -- cgit v1.2.3