summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>1999-03-16 01:24:02 +0000
committerSteve Huston <shuston@riverace.com>1999-03-16 01:24:02 +0000
commit1853b53fb42ad6c689e787cebcdcae01f2c53e41 (patch)
tree63a5a3252c96f980aef016b5458ec59ec900fe4a /tests
parentacbfbacbd62396df1175b0b3f9ed2090ed263fbf (diff)
downloadATCD-1853b53fb42ad6c689e787cebcdcae01f2c53e41.tar.gz
Template defs for Map_Test.cpp.
Diffstat (limited to 'tests')
-rw-r--r--tests/Map_Test.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/Map_Test.h b/tests/Map_Test.h
new file mode 100644
index 00000000000..432ae1a4d57
--- /dev/null
+++ b/tests/Map_Test.h
@@ -0,0 +1,142 @@
+// $Id$
+
+// This file has the class definitions needed for template generation in
+// Map_Test.cpp. They have to be in a separate file so AIX xlC can
+// find them at auto-instantiate time.
+
+#ifndef ACE_MAP_TEST_H
+#define ACE_MAP_TEST_H
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/OS.h"
+#include "ace/Active_Map_Manager.h"
+#include "ace/Containers.h"
+
+
+// Key data type.
+typedef ACE_Array<char> KEY;
+
+////////////////////////////////////////////////////////////////////////////////
+
+class Key_Generator
+{
+ // = TITLE
+ // Defines a key generator.
+ //
+ // = DESCRIPTION
+ // This class is used in adapters of maps that do not produce keys.
+public:
+
+ Key_Generator (void)
+ : counter_ (0)
+ {
+ }
+
+ int operator() (KEY &key)
+ {
+ // Keep original information in the key intact.
+ size_t original_size = key.size ();
+
+ // Size of this counter key.
+ size_t counter_key_size = sizeof this->counter_;
+
+ // Resize to accommodate both the original data and the new key.
+ key.size (counter_key_size + original_size);
+
+ // Add new key data.
+ ACE_OS::memcpy (&key[original_size],
+ &++this->counter_,
+ sizeof this->counter_);
+
+ // Success.
+ return 0;
+ }
+
+private:
+ u_long counter_;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class Hash_Key
+{
+public:
+ u_long operator () (const KEY &key) const
+ {
+ // Recover system generated part of key.
+ u_long value;
+ size_t counter_key_size = sizeof (u_long);
+
+ // Copy system key from user key.
+ ACE_OS::memcpy (&value,
+ &key[key.size () - counter_key_size],
+ sizeof value);
+
+ // Return the system key value as the hash value.
+ return value;
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class Key_Adapter
+{
+public:
+
+ int encode (const KEY &original_key,
+ const ACE_Active_Map_Manager_Key &active_key,
+ KEY &modified_key)
+ {
+ // Keep original information in the key intact.
+ modified_key = original_key;
+ size_t original_size = modified_key.size ();
+
+ // Size of active key.
+ size_t active_key_size = active_key.size ();
+
+ // Resize to accommodate both the original data and the new active key.
+ modified_key.size (active_key_size + original_size);
+
+ // Copy active key data into user key.
+ active_key.encode (&modified_key[original_size]);
+
+ // Success.
+ return 0;
+ }
+
+ int decode (const KEY &modified_key,
+ ACE_Active_Map_Manager_Key &active_key)
+ {
+ // Read the active key data from the back of the key.
+ size_t active_key_size = active_key.size ();
+ size_t original_size = modified_key.size () - active_key_size;
+
+ // Read off value of index and generation.
+ active_key.decode (&modified_key[original_size]);
+
+ // Success.
+ return 0;
+ }
+
+ int decode (const KEY &modified_key,
+ KEY &original_key)
+ {
+ // Read the original user key data from the front of the
+ // modified key.
+ size_t active_key_size = ACE_Active_Map_Manager_Key::size ();
+
+ // Copy all the data.
+ original_key = modified_key;
+
+ // Resize to ignore active key data.
+ original_key.size (original_key.size () - active_key_size);
+
+ // Success.
+ return 0;
+ }
+};
+
+#endif /* ACE_MAP_TEST_H */