1 #ifndef _MAP_T_H_INCLUDED_ 2 #define _MAP_T_H_INCLUDED_ 10 template<
typename t_key,
typename t_value>
void operator() (
const t_key & p_key,
const t_value & p_value) {
m_destination.set(p_key,p_value);}
15 template<
typename t_storage_key,
typename t_storage_value,
typename t_comparator = comparator_default>
21 template<
typename _t_key,
typename _t_value>
22 void set(
const _t_key & p_key,
const _t_value & p_value) {
24 t_storage & storage = m_data.add_ex(t_search_set<_t_key,_t_value>(p_key,p_value), isnew);
25 if (!isnew) storage.m_value = p_value;
28 template<
typename _t_key>
30 return m_data.add(t_search_query<_t_key>(p_key)).m_value;
33 template<
typename _t_key>
35 return m_data.add_ex(t_search_query<_t_key>(p_key),p_isnew).m_value;
38 template<
typename _t_key>
40 return m_data.have_item(t_search_query<_t_key>(p_key));
43 template<
typename _t_key,
typename _t_value>
44 bool query(
const _t_key & p_key,_t_value & p_value)
const {
45 const t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key));
46 if (storage == NULL)
return false;
47 p_value = storage->m_value;
51 template<
typename _t_key>
52 const t_storage_value & operator[] (
const _t_key & p_key)
const {
53 const t_storage_value * ptr = query_ptr(p_key);
54 if (ptr == NULL)
throw exception_map_entry_not_found();
58 template<
typename _t_key>
59 t_storage_value & operator[] (
const _t_key & p_key) {
60 return find_or_add(p_key);
63 template<
typename _t_key>
64 const t_storage_value *
query_ptr(
const _t_key & p_key)
const {
65 const t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key));
66 if (storage == NULL)
return NULL;
67 return &storage->m_value;
70 template<
typename _t_key>
72 t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key));
73 if (storage == NULL)
return NULL;
74 return &storage->m_value;
77 template<
typename _t_key>
78 bool query_ptr(
const _t_key & p_key,
const t_storage_value * & out)
const {
79 const t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key));
80 if (storage == NULL)
return false;
81 out = &storage->m_value;
85 template<
typename _t_key>
86 bool query_ptr(
const _t_key & p_key, t_storage_value * & out) {
87 t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key));
88 if (storage == NULL)
return false;
89 out = &storage->m_value;
93 template<
bool inclusive,
bool above,
typename _t_key>
95 const t_storage * storage = m_data.template find_nearest_item<inclusive,above>(t_search_query<_t_key>(p_key));
96 if (storage == NULL)
return NULL;
97 p_key = storage->m_key;
98 return &storage->m_value;
101 template<
bool inclusive,
bool above,
typename _t_key>
103 t_storage * storage = m_data.template find_nearest_item<inclusive,above>(t_search_query<_t_key>(p_key));
104 if (storage == NULL)
return NULL;
105 p_key = storage->m_key;
106 return &storage->m_value;
109 template<
bool inclusive,
bool above,
typename _t_key,
typename _t_value>
111 const t_storage * storage = m_data.template find_nearest_item<inclusive,above>(t_search_query<_t_key>(p_key));
112 if (storage == NULL)
return false;
113 p_key = storage->m_key;
114 p_value = storage->m_value;
119 template<
typename _t_key>
120 bool remove(
const _t_key & p_key) {
121 return m_data.remove_item(t_search_query<_t_key>(p_key));
124 template<
typename t_callback>
126 enumeration_wrapper<t_callback> cb(p_callback);
127 m_data.enumerate(cb);
130 template<
typename t_callback>
132 enumeration_wrapper_var<t_callback> cb(p_callback);
133 m_data._enumerate_var(cb);
141 template<
typename t_source>
144 p_source.enumerate(wrapper);
148 template<
typename _t_key>
bool exists(
const _t_key & p_key)
const {
return have_item(p_key);}
151 template<
typename _t_key>
bool get_first(_t_key & p_out)
const {
152 return m_data.get_first(t_retrieve_key<_t_key>(p_out));
155 template<
typename _t_key>
bool get_last(_t_key & p_out)
const {
156 return m_data.get_last(t_retrieve_key<_t_key>(p_out));
160 template<
typename _t_key>
164 template<
typename t_what>
const t_self &
operator=(
const t_what & p_what) {m_key = p_what.
m_key;
return *
this;}
167 template<
typename _t_key>
172 template<
typename _t_key,
typename _t_value>
174 t_search_set(
const _t_key & p_key,
const _t_value & p_value) : m_key(p_key), m_value(p_value) {}
184 template<
typename _t_key>
187 template<
typename _t_key,
typename _t_value>
197 template<
typename t1,
typename t2>
198 inline static int compare(
const t1 & p_item1,
const t2 & p_item2) {
203 template<
typename t_callback>
212 template<
typename t_callback>
231 const_iterator
first()
const throw() {
return m_data.
first();}
232 const_iterator
last()
const throw() {
return m_data.
last();}
234 template<
typename _t_key> iterator
find(
const _t_key & key) {
return m_data.
find(t_search_query<_t_key>(key));}
235 template<
typename _t_key> const_iterator
find(
const _t_key & key)
const {
return m_data.
find(t_search_query<_t_key>(key));}
237 static bool equals(
const t_self & v1,
const t_self & v2) {
243 bool remove(iterator
const& iter) {
244 PFC_ASSERT(iter.is_valid());
245 return m_data.
remove(iter);
248 bool remove(const_iterator
const& iter) {
249 PFC_ASSERT(iter.is_valid());
250 return m_data.
remove(iter);
256 #endif //_MAP_T_H_INCLUDED_ const_iterator first() const
map_t< t_storage_key, t_storage_value, t_comparator > t_self
const t_storage_key m_key
iterator find(const _t_key &key)
void operator()(t_storage &p_item)
void enumerate(t_callback &p_callback) const
bool get_first(_t_key &p_out) const
bool operator!=(const t_self &other) const
t_destination & m_destination
t_storage_value & find_or_add_ex(_t_key const &p_key, bool &p_isnew)
bool query_ptr(const _t_key &p_key, const t_storage_value *&out) const
void operator()(const t_key &p_key, const t_value &p_value)
bool query_ptr(const _t_key &p_key, t_storage_value *&out)
int compare(t1 const &p1, t2 const &p2)
t_storage_value * query_ptr(const _t_key &p_key)
const_iterator find(const _t_key &key) const
iterator _first_var()
Unsafe! Caller must not modify items in a way that changes sort order!
traits_t< t_content > traits
t_storage(t_search_query< _t_key > const &p_source)
static bool equals(const t_storage &v1, const t_storage &v2)
bool operator!=(const t_storage &other) const
t_search_query(const _t_key &p_key)
const t_storage_value * query_nearest_ptr(_t_key &p_key) const
t_storage_value & find_or_add(_t_key const &p_key)
iterator _last_var()
Unsafe! Caller must not modify items in a way that changes sort order!
const_iterator find(t_param const &item) const
const_iterator first() const
const t_storage_value * query_ptr(const _t_key &p_key) const
avltree_t< t_storage, comparator_wrapper > t_content
const_iterator last() const
const t_self & operator=(const t_what &p_what)
enumeration_wrapper_var(t_callback &p_callback)
t_retrieve_key(_t_key &p_key)
bool get_last(_t_key &p_out) const
enumeration_wrapper(t_callback &p_callback)
t_retrieve_key< _t_key > t_self
t_storage(t_search_set< _t_key, _t_value > const &p_source)
bool query_nearest(_t_key &p_key, _t_value &p_value) const
void enumerate(t_callback &p_callback)
void overwrite(const t_source &p_source)
static int compare(const t1 &p_item1, const t2 &p_item2)
bool operator==(const t_self &other) const
t_content::iterator iterator
t_content::const_iterator const_iterator
void operator()(const t_storage &p_item)
t_search_set(const _t_key &p_key, const _t_value &p_value)
bool exists(const _t_key &p_key) const
__map_overwrite_wrapper(t_destination &p_destination)
bool operator==(const t_storage &other) const
PFC_DECLARE_EXCEPTION(exception_map_entry_not_found, exception,"Map entry not found")
bool remove(const_iterator const &iter)
const_iterator last() const
t_storage_value * query_nearest_ptr(_t_key &p_key)
static bool equals(const t_self &v1, const t_self &v2)
bool have_item(const _t_key &p_key) const
bool equals(const t1 &v1, const t2 &v2)
bool query(const _t_key &p_key, _t_value &p_value) const