3 //=============================================================================
7 * This file has the class definitions needed for template generation in
10 * @author Irfan Pyarali <irfan@cs.wustl.edu>
12 //=============================================================================
15 #ifndef ACE_TESTS_MAP_TEST_H
16 #define ACE_TESTS_MAP_TEST_H
18 #include "ace/OS_NS_string.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/Active_Map_Manager.h"
25 #include "ace/Containers.h"
28 typedef ACE_Array
<char> KEY
;
31 * @class Key_Generator
33 * @brief Defines a key generator.
35 * This class is used in adapters of maps that do not produce keys.
45 int operator() (KEY
&key
)
47 // Keep original information in the key intact.
48 size_t original_size
= key
.size ();
50 // Size of this counter key.
51 const size_t counter_key_size
= sizeof this->counter_
;
53 // Resize to accommodate both the original data and the new key.
54 key
.size (counter_key_size
+ original_size
);
57 ACE_OS::memcpy (&key
[original_size
],
72 u_long
operator () (const KEY
&key
) const
74 // Recover system generated part of key.
76 size_t counter_key_size
= sizeof (u_long
);
78 // Copy system key from user key.
79 ACE_OS::memcpy (&value
,
80 &key
[key
.size () - counter_key_size
],
83 // Return the system key value as the hash value.
91 int encode (const KEY
&original_key
,
92 const ACE_Active_Map_Manager_Key
&active_key
,
95 // Keep original information in the key intact.
96 modified_key
= original_key
;
97 size_t original_size
= modified_key
.size ();
99 // Size of active key.
100 size_t active_key_size
= active_key
.size ();
102 // Resize to accommodate both the original data and the new active key.
103 modified_key
.size (active_key_size
+ original_size
);
105 // Copy active key data into user key.
106 active_key
.encode (&modified_key
[original_size
]);
112 int decode (const KEY
&modified_key
,
113 ACE_Active_Map_Manager_Key
&active_key
)
115 // Read the active key data from the back of the key.
116 size_t active_key_size
= active_key
.size ();
117 size_t original_size
= modified_key
.size () - active_key_size
;
119 // Read off value of index and generation.
120 active_key
.decode (&modified_key
[original_size
]);
126 int decode (const KEY
&modified_key
,
129 // Read the original user key data from the front of the
131 size_t active_key_size
= ACE_Active_Map_Manager_Key::size ();
133 // Copy all the data.
134 original_key
= modified_key
;
136 // Resize to ignore active key data.
137 original_key
.size (original_key
.size () - active_key_size
);
144 #endif /* ACE_TESTS_MAP_TEST_H */