3 //=============================================================================
7 * This file has the class definitions needed for template generation in
8 * Map_Test.cpp. They have to be in a separate file so AIX xlC can
9 * find them at auto-instantiate time.
11 * @author Irfan Pyarali <irfan@cs.wustl.edu>
13 //=============================================================================
16 #ifndef ACE_TESTS_MAP_TEST_H
17 #define ACE_TESTS_MAP_TEST_H
19 #include "ace/OS_NS_string.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Active_Map_Manager.h"
26 #include "ace/Containers.h"
29 typedef ACE_Array
<char> KEY
;
32 * @class Key_Generator
34 * @brief Defines a key generator.
36 * This class is used in adapters of maps that do not produce keys.
47 int operator() (KEY
&key
)
49 // Keep original information in the key intact.
50 size_t original_size
= key
.size ();
52 // Size of this counter key.
53 const size_t counter_key_size
= sizeof this->counter_
;
55 // Resize to accommodate both the original data and the new key.
56 key
.size (counter_key_size
+ original_size
);
59 ACE_OS::memcpy (&key
[original_size
],
74 u_long
operator () (const KEY
&key
) const
76 // Recover system generated part of key.
78 size_t counter_key_size
= sizeof (u_long
);
80 // Copy system key from user key.
81 ACE_OS::memcpy (&value
,
82 &key
[key
.size () - counter_key_size
],
85 // Return the system key value as the hash value.
94 int encode (const KEY
&original_key
,
95 const ACE_Active_Map_Manager_Key
&active_key
,
98 // Keep original information in the key intact.
99 modified_key
= original_key
;
100 size_t original_size
= modified_key
.size ();
102 // Size of active key.
103 size_t active_key_size
= active_key
.size ();
105 // Resize to accommodate both the original data and the new active key.
106 modified_key
.size (active_key_size
+ original_size
);
108 // Copy active key data into user key.
109 active_key
.encode (&modified_key
[original_size
]);
115 int decode (const KEY
&modified_key
,
116 ACE_Active_Map_Manager_Key
&active_key
)
118 // Read the active key data from the back of the key.
119 size_t active_key_size
= active_key
.size ();
120 size_t original_size
= modified_key
.size () - active_key_size
;
122 // Read off value of index and generation.
123 active_key
.decode (&modified_key
[original_size
]);
129 int decode (const KEY
&modified_key
,
132 // Read the original user key data from the front of the
134 size_t active_key_size
= ACE_Active_Map_Manager_Key::size ();
136 // Copy all the data.
137 original_key
= modified_key
;
139 // Resize to ignore active key data.
140 original_key
.size (original_key
.size () - active_key_size
);
147 #endif /* ACE_TESTS_MAP_TEST_H */