Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / ObjectKey_Table.cpp
blob9d00c62275c723e52e5872f653c8aa36cfc5f20a
1 #include "tao/ObjectKey_Table.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/Refcounted_ObjectKey.h"
5 #if !defined (__ACE_INLINE__)
6 # include "tao/ObjectKey_Table.inl"
7 #endif /* ! __ACE_INLINE__ */
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
11 bool
12 TAO::Less_Than_ObjectKey::operator () (const TAO::ObjectKey &lhs,
13 const TAO::ObjectKey &rhs) const
15 const CORBA::ULong rlen = rhs.length ();
16 const CORBA::ULong llen = lhs.length ();
17 if (llen < rlen)
19 return 1;
21 else if (llen > rlen)
23 return 0;
26 const CORBA::Octet * rhs_buff = rhs.get_buffer ();
27 const CORBA::Octet * lhs_buff = lhs.get_buffer ();
28 const bool result = (ACE_OS::memcmp (lhs_buff, rhs_buff, rlen) < 0);
30 return result;
33 /********************************************************/
34 TAO::ObjectKey_Table::ObjectKey_Table ()
35 : table_ ()
39 TAO::ObjectKey_Table::~ObjectKey_Table ()
41 this->table_.close ();
44 int
45 TAO::ObjectKey_Table::destroy ()
47 if (this->table_.current_size ())
49 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
50 ace_mon,
51 this->lock_,
52 0);
54 TABLE::ITERATOR end_iter = this->table_.end ();
55 TABLE::ITERATOR start;
57 while ((start = this->table_.begin ()) != end_iter)
59 TABLE::ENTRY &ent = (*start);
61 ent.item ()->decr_refcount ();
62 this->table_.unbind (&ent);
66 return 0;
69 int
70 TAO::ObjectKey_Table::bind_i (const TAO::ObjectKey &key,
71 TAO::Refcounted_ObjectKey *&key_new)
73 ACE_NEW_RETURN (key_new,
74 TAO::Refcounted_ObjectKey (key),
75 -1);
77 int const retval = this->table_.bind (key, key_new);
79 if (retval != -1)
81 key_new->incr_refcount ();
83 else
85 key_new->decr_refcount ();
88 return retval;
91 int
92 TAO::ObjectKey_Table::unbind_i (TAO::Refcounted_ObjectKey *&key_new)
94 TAO::Refcounted_ObjectKey *tmp = nullptr;
96 if (this->table_.unbind (key_new->object_key (), tmp) != -1)
98 // @@ Cant do much if the unbind fails.
99 // Remove our refcount on the ObjectKey
100 (void) tmp->decr_refcount ();
103 return 0;
106 TAO_END_VERSIONED_NAMESPACE_DECL