Diffstat (limited to 'include/konforka/pointer_map.h') (more/less context) (show whitespace changes)
-rw-r--r-- | include/konforka/pointer_map.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/include/konforka/pointer_map.h b/include/konforka/pointer_map.h index d706e71..00dd486 100644 --- a/include/konforka/pointer_map.h +++ b/include/konforka/pointer_map.h | |||
@@ -1,105 +1,106 @@ | |||
1 | #ifndef __KONFORKA_POINTER_MAP_H | 1 | #ifndef __KONFORKA_POINTER_MAP_H |
2 | #define __KONFORKA_POINTER_MAP_H | 2 | #define __KONFORKA_POINTER_MAP_H |
3 | 3 | ||
4 | #include <typeinfo> | 4 | #include <typeinfo> |
5 | 5 | ||
6 | /** | 6 | /** |
7 | * @file | 7 | * @file |
8 | * @brief mapping of pointers. | 8 | * @brief mapping of pointers. |
9 | * | 9 | * |
10 | * The support for global mapping of pointers. Useful when using third-party | 10 | * The support for global mapping of pointers. Useful when using third-party |
11 | * libraries callbacks when the library does not provide mechanism for passing | 11 | * libraries callbacks when the library does not provide mechanism for passing |
12 | * along custom context-dependent data. | 12 | * along custom context-dependent data. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | namespace konforka { | 15 | namespace konforka { |
16 | using std::type_info; | ||
16 | 17 | ||
17 | /** | 18 | /** |
18 | * @brief internally used actual implementation of mapping pointer. | 19 | * @brief internally used actual implementation of mapping pointer. |
19 | * | 20 | * |
20 | * @param tf the typeid of the key pointer. | 21 | * @param tf the typeid of the key pointer. |
21 | * @param pf the key pointer. | 22 | * @param pf the key pointer. |
22 | * @param tt the typeid of the value pointer. | 23 | * @param tt the typeid of the value pointer. |
23 | * @param pt the value pointer. | 24 | * @param pt the value pointer. |
24 | */ | 25 | */ |
25 | void _map_pointer(const type_info& tf,void *pf,const type_info& tt,void *pt); | 26 | void _map_pointer(const type_info& tf,void *pf,const type_info& tt,void *pt); |
26 | /** | 27 | /** |
27 | * @brief internally used actual implementation of destroying mapped | 28 | * @brief internally used actual implementation of destroying mapped |
28 | * pointer. | 29 | * pointer. |
29 | * | 30 | * |
30 | * @param tf the typeid of the key pointer. | 31 | * @param tf the typeid of the key pointer. |
31 | * @param pf the key pointer. | 32 | * @param pf the key pointer. |
32 | * @param tt the typeid of the value pointer. | 33 | * @param tt the typeid of the value pointer. |
33 | * @param pt the value pointer. | 34 | * @param pt the value pointer. |
34 | */ | 35 | */ |
35 | void _unmap_pointer(const type_info& tf,void *pf,const type_info& tt,void *pt); | 36 | void _unmap_pointer(const type_info& tf,void *pf,const type_info& tt,void *pt); |
36 | /** | 37 | /** |
37 | * @brief internally used actual implementation of retrieving mapped | 38 | * @brief internally used actual implementation of retrieving mapped |
38 | * pointer. | 39 | * pointer. |
39 | * | 40 | * |
40 | * @param tf the typeid of the key pointer. | 41 | * @param tf the typeid of the key pointer. |
41 | * @param pf the key pointer. | 42 | * @param pf the key pointer. |
42 | * @param tt the typeid of the value pointer. | 43 | * @param tt the typeid of the value pointer. |
43 | * @return the value. | 44 | * @return the value. |
44 | */ | 45 | */ |
45 | void *_mapped_pointer(const type_info& tf,void *pf,const type_info& tt); | 46 | void *_mapped_pointer(const type_info& tf,void *pf,const type_info& tt); |
46 | 47 | ||
47 | /** | 48 | /** |
48 | * @brief the object, maintaining mapped pointer. | 49 | * @brief the object, maintaining mapped pointer. |
49 | * | 50 | * |
50 | * @param from_t the key type. | 51 | * @param from_t the key type. |
51 | * @param to_t the value type. | 52 | * @param to_t the value type. |
52 | */ | 53 | */ |
53 | template<typename from_t,typename to_t> | 54 | template<typename from_t,typename to_t> |
54 | class map_pointer { | 55 | class map_pointer { |
55 | public: | 56 | public: |
56 | /** | 57 | /** |
57 | * stored key. | 58 | * stored key. |
58 | */ | 59 | */ |
59 | from_t _from; | 60 | from_t _from; |
60 | /** | 61 | /** |
61 | * stored value. | 62 | * stored value. |
62 | */ | 63 | */ |
63 | to_t _to; | 64 | to_t _to; |
64 | /** | 65 | /** |
65 | * flag, specifying that the object is currently mapped. | 66 | * flag, specifying that the object is currently mapped. |
66 | */ | 67 | */ |
67 | bool bmapped; | 68 | bool bmapped; |
68 | 69 | ||
69 | /** | 70 | /** |
70 | * @brief constructs the object, mapping the key/value pair. | 71 | * @brief constructs the object, mapping the key/value pair. |
71 | * | 72 | * |
72 | * @param f the key. | 73 | * @param f the key. |
73 | * @param t the value. | 74 | * @param t the value. |
74 | */ | 75 | */ |
75 | map_pointer(from_t f,to_t t) | 76 | map_pointer(from_t f,to_t t) |
76 | : _from(f), _to(t), bmapped(false) { | 77 | : _from(f), _to(t), bmapped(false) { |
77 | _map_pointer(typeid(from_t),_from,typeid(to_t),_to); | 78 | _map_pointer(typeid(from_t),_from,typeid(to_t),_to); |
78 | bmapped=true; | 79 | bmapped=true; |
79 | } | 80 | } |
80 | /** | 81 | /** |
81 | * @brief destructor unmaps the key/value pair stored. | 82 | * @brief destructor unmaps the key/value pair stored. |
82 | */ | 83 | */ |
83 | ~map_pointer() { | 84 | ~map_pointer() { |
84 | if(bmapped) | 85 | if(bmapped) |
85 | _unmap_pointer(typeid(from_t),_from,typeid(to_t),_to); | 86 | _unmap_pointer(typeid(from_t),_from,typeid(to_t),_to); |
86 | } | 87 | } |
87 | }; | 88 | }; |
88 | 89 | ||
89 | /** | 90 | /** |
90 | * The template function for pointer retrieval. | 91 | * The template function for pointer retrieval. |
91 | * | 92 | * |
92 | * @param from_t the key type. | 93 | * @param from_t the key type. |
93 | * @param to_t the value type. | 94 | * @param to_t the value type. |
94 | * @param f the key. | 95 | * @param f the key. |
95 | * @return the value. | 96 | * @return the value. |
96 | */ | 97 | */ |
97 | template<typename from_t,typename to_t> | 98 | template<typename from_t,typename to_t> |
98 | to_t mapped_pointer(from_t f) { | 99 | to_t mapped_pointer(from_t f) { |
99 | return (to_t)_mapped_pointer(typeid(from_t),f,typeid(to_t)); | 100 | return (to_t)_mapped_pointer(typeid(from_t),f,typeid(to_t)); |
100 | } | 101 | } |
101 | 102 | ||
102 | } | 103 | } |
103 | 104 | ||
104 | #endif /* __KONFORKA_POINTER_MAP_H */ | 105 | #endif /* __KONFORKA_POINTER_MAP_H */ |
105 | /* vim:set ft=cpp: */ | 106 | /* vim:set ft=cpp: */ |