Key_Adapters.cpp

Go to the documentation of this file.
00001 // $Id: Key_Adapters.cpp 71473 2006-03-10 07:19:20Z jtc $
00002 
00003 #include "tao/PortableServer/Key_Adapters.h"
00004 
00005 #include "ace/ACE.h"
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/Map_T.h"
00008 
00009 ACE_RCSID (PortableServer,
00010            Key_Adapters,
00011            "$Id: Key_Adapters.cpp 71473 2006-03-10 07:19:20Z jtc $")
00012 
00013 ///////////////////////////////////////////////////////////////////////////////
00014 
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016 
00017 TAO_Incremental_Key_Generator::TAO_Incremental_Key_Generator (void)
00018   : counter_ (0)
00019 {
00020 }
00021 
00022 int
00023 TAO_Incremental_Key_Generator::operator() (PortableServer::ObjectId &id)
00024 {
00025   // Resize to accommodate the counter.
00026   id.length (sizeof this->counter_);
00027 
00028   // Add new key data.
00029   ACE_OS::memcpy (id.get_buffer (),
00030                   &++this->counter_,
00031                   sizeof this->counter_);
00032 
00033   // Success.
00034   return 0;
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////////////////
00038 
00039 u_long
00040 TAO_ObjectId_Hash::operator () (const PortableServer::ObjectId &id) const
00041 {
00042   return ACE::hash_pjw ((const char *) id.get_buffer (),
00043                         id.length ());
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////////////////
00047 
00048 int
00049 TAO_Ignore_Original_Key_Adapter::encode (const PortableServer::ObjectId &original_key,
00050                                          const ACE_Active_Map_Manager_Key &active_key,
00051                                          PortableServer::ObjectId &modified_key)
00052 {
00053   ACE_UNUSED_ARG (original_key);
00054 
00055   // Size of active key.
00056   size_t active_key_size = active_key.size ();
00057 
00058   // Resize to accommodate both the original data and the new active key.
00059   modified_key.length (static_cast <CORBA::ULong> (active_key_size));
00060 
00061   // Copy active key data into user key.
00062   active_key.encode (modified_key.get_buffer ());
00063 
00064   // Success.
00065   return 0;
00066 }
00067 
00068 int
00069 TAO_Ignore_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
00070                                          ACE_Active_Map_Manager_Key &active_key)
00071 {
00072   // Read off value of index and generation.
00073   active_key.decode (modified_key.get_buffer ());
00074 
00075   // Success.
00076   return 0;
00077 }
00078 
00079 int
00080 TAO_Ignore_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
00081                                          PortableServer::ObjectId &original_key)
00082 {
00083   // Smartly copy all the data; <original_key does not own the data>.
00084   original_key.replace (modified_key.maximum (),
00085                         modified_key.length (),
00086                         const_cast <CORBA::Octet *>
00087                                    (modified_key.get_buffer ()),
00088                         0);
00089 
00090   // Success.
00091   return 0;
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////////////////
00095 
00096 int
00097 TAO_Preserve_Original_Key_Adapter::encode (const PortableServer::ObjectId &original_key,
00098                                            const ACE_Active_Map_Manager_Key &active_key,
00099                                            PortableServer::ObjectId &modified_key)
00100 {
00101   // Size of active key.
00102   size_t active_key_size = active_key.size ();
00103 
00104   // Resize to accommodate both the original data and the new active key.
00105   modified_key.length (static_cast <CORBA::ULong> (active_key_size)
00106                          + original_key.length ());
00107 
00108   // Copy active key data into user key.
00109   active_key.encode (modified_key.get_buffer ());
00110 
00111   // Copy the original key after the active key.
00112   ACE_OS::memcpy (modified_key.get_buffer () + active_key_size,
00113                   original_key.get_buffer (),
00114                   original_key.length ());
00115 
00116   // Success.
00117   return 0;
00118 }
00119 
00120 int
00121 TAO_Preserve_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
00122                                            ACE_Active_Map_Manager_Key &active_key)
00123 {
00124   // Read off value of index and generation.
00125   active_key.decode (modified_key.get_buffer ());
00126 
00127   // Success.
00128   return 0;
00129 }
00130 
00131 int
00132 TAO_Preserve_Original_Key_Adapter::decode (const PortableServer::ObjectId &modified_key,
00133                                            PortableServer::ObjectId &original_key)
00134 {
00135   // Size of active key.
00136   size_t active_key_size = ACE_Active_Map_Manager_Key::size ();
00137 
00138   // Smartly copy all the data; <original_key does not own the data>.
00139   original_key.replace (static_cast <CORBA::ULong>
00140                             (modified_key.maximum () - active_key_size),
00141                         static_cast <CORBA::ULong>
00142                             (modified_key.length () - active_key_size),
00143                         const_cast <CORBA::Octet *>
00144                             (modified_key.get_buffer ()) + active_key_size,
00145                         0);
00146 
00147   // Success.
00148   return 0;
00149 }
00150 
00151 TAO_END_VERSIONED_NAMESPACE_DECL
00152 

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7