Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / PortableServer / Key_Adapters.cpp
blobb48962042fcd1a94ce7013b056bdc4e2e801c489
1 // -*- C++ -*-
2 #include "tao/PortableServer/Key_Adapters.h"
4 #include "ace/ACE.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/Map_T.h"
8 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
10 TAO_Incremental_Key_Generator::TAO_Incremental_Key_Generator ()
11 : counter_ (0)
15 int
16 TAO_Incremental_Key_Generator::operator() (PortableServer::ObjectId &id)
18 const size_t cntr_size = sizeof this->counter_;
19 // Resize to accommodate the counter.
20 id.length (cntr_size);
22 // Add new key data.
23 ACE_OS::memcpy (id.get_buffer (),
24 &++this->counter_,
25 cntr_size);
27 // Success.
28 return 0;
31 ////////////////////////////////////////////////////////////////////////////////
33 u_long
34 TAO_ObjectId_Hash::operator () (const PortableServer::ObjectId &id) const
36 return ACE::hash_pjw ((const char *) id.get_buffer (),
37 id.length ());
40 ////////////////////////////////////////////////////////////////////////////////
42 int
43 TAO_Ignore_Original_Key_Adapter::encode (const PortableServer::ObjectId &,
44 const ACE_Active_Map_Manager_Key &active_key,
45 PortableServer::ObjectId &modified_key)
47 // Size of active key.
48 size_t const active_key_size = active_key.size ();
50 // Resize to accommodate both the original data and the new active key.
51 modified_key.length (static_cast <CORBA::ULong> (active_key_size));
53 // Copy active key data into user key.
54 active_key.encode (modified_key.get_buffer ());
56 // Success.
57 return 0;
60 int
61 TAO_Ignore_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
62 ACE_Active_Map_Manager_Key &active_key)
64 // Read off value of index and generation.
65 active_key.decode (modified_key.get_buffer ());
67 // Success.
68 return 0;
71 int
72 TAO_Ignore_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
73 PortableServer::ObjectId &original_key)
75 // Smartly copy all the data; <original_key does not own the data>.
76 original_key.replace (modified_key.maximum (),
77 modified_key.length (),
78 const_cast <CORBA::Octet *>
79 (modified_key.get_buffer ()),
80 0);
82 // Success.
83 return 0;
86 ////////////////////////////////////////////////////////////////////////////////
88 int
89 TAO_Preserve_Original_Key_Adapter::encode (const PortableServer::ObjectId &original_key,
90 const ACE_Active_Map_Manager_Key &active_key,
91 PortableServer::ObjectId &modified_key)
93 // Size of active key.
94 size_t const active_key_size = active_key.size ();
96 // Resize to accommodate both the original data and the new active key.
97 modified_key.length (static_cast <CORBA::ULong> (active_key_size)
98 + original_key.length ());
100 // Copy active key data into user key.
101 active_key.encode (modified_key.get_buffer ());
103 // Copy the original key after the active key.
104 ACE_OS::memcpy (modified_key.get_buffer () + active_key_size,
105 original_key.get_buffer (),
106 original_key.length ());
108 // Success.
109 return 0;
113 TAO_Preserve_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
114 ACE_Active_Map_Manager_Key &active_key)
116 // Read off value of index and generation.
117 active_key.decode (modified_key.get_buffer ());
119 // Success.
120 return 0;
124 TAO_Preserve_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
125 PortableServer::ObjectId &original_key)
127 // Size of active key.
128 size_t const active_key_size = ACE_Active_Map_Manager_Key::size ();
130 // Smartly copy all the data; <original_key does not own the data>.
131 original_key.replace (static_cast <CORBA::ULong>
132 (modified_key.maximum () - active_key_size),
133 static_cast <CORBA::ULong>
134 (modified_key.length () - active_key_size),
135 const_cast <CORBA::Octet *>
136 (modified_key.get_buffer ()) + active_key_size,
139 // Success.
140 return 0;
143 TAO_END_VERSIONED_NAMESPACE_DECL