Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Map_Test.h
blob5b82ff9b7ef46bd725934f1c4fff18b203b39182
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Map_Test.h
7 * This file has the class definitions needed for template generation in
8 * Map_Test.cpp.
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)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/Active_Map_Manager.h"
25 #include "ace/Containers.h"
27 // Key data type.
28 typedef ACE_Array<char> KEY;
30 /**
31 * @class Key_Generator
33 * @brief Defines a key generator.
35 * This class is used in adapters of maps that do not produce keys.
37 class Key_Generator
39 public:
40 Key_Generator ()
41 : counter_ (0)
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);
56 // Add new key data.
57 ACE_OS::memcpy (&key[original_size],
58 &++this->counter_,
59 counter_key_size);
61 // Success.
62 return 0;
65 private:
66 u_long counter_;
69 class Hash_Key
71 public:
72 u_long operator () (const KEY &key) const
74 // Recover system generated part of key.
75 u_long value;
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],
81 sizeof value);
83 // Return the system key value as the hash value.
84 return value;
88 class Key_Adapter
90 public:
91 int encode (const KEY &original_key,
92 const ACE_Active_Map_Manager_Key &active_key,
93 KEY &modified_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]);
108 // Success.
109 return 0;
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]);
122 // Success.
123 return 0;
126 int decode (const KEY &modified_key,
127 KEY &original_key)
129 // Read the original user key data from the front of the
130 // modified key.
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);
139 // Success.
140 return 0;
144 #endif /* ACE_TESTS_MAP_TEST_H */