summaryrefslogtreecommitdiff
path: root/TAO/tao/MProfile.cpp
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-12 16:13:38 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-12 16:13:38 +0000
commit49c1b7e5025c95ee641163330b34d8bd94d50022 (patch)
tree9ea8ce3e5b34edcaf8ec639e3fb2b1244a32e4a6 /TAO/tao/MProfile.cpp
parent2fe713022754c7550170243856faacdfb3c8bf6b (diff)
downloadATCD-49c1b7e5025c95ee641163330b34d8bd94d50022.tar.gz
ChangeLogTag:Wed May 12 10:38:03 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
Diffstat (limited to 'TAO/tao/MProfile.cpp')
-rw-r--r--TAO/tao/MProfile.cpp159
1 files changed, 107 insertions, 52 deletions
diff --git a/TAO/tao/MProfile.cpp b/TAO/tao/MProfile.cpp
index 963f4becb77..777b81ddabb 100644
--- a/TAO/tao/MProfile.cpp
+++ b/TAO/tao/MProfile.cpp
@@ -10,50 +10,42 @@ ACE_RCSID(tao, MProfile, "$Id$")
# include "tao/MProfile.i"
#endif /* __ACE_INLINE__ */
-int
-TAO_MProfile::set (CORBA::ULong sz)
+void
+TAO_MProfile::cleanup (void)
{
- if (sz == 0)
+ if (this->pfiles_ != 0)
{
- // Release all of our profiles.
+ for (TAO_PHandle i = 0; i < this->last_; ++i)
+ if (this->pfiles_[i])
+ this->pfiles_[i]->_decr_refcnt ();
+ }
- for (TAO_PHandle h = 0;
- h < this->size_;
- h++)
- if (this->pfiles_[h])
- {
- this->pfiles_[h]->_decr_refcnt ();
- this->pfiles_[h] = 0;
- }
+ delete [] this->pfiles_;
+ this->pfiles_ = 0;
- if (this->size_)
- delete [] this->pfiles_;
-
- if (forward_from_)
- delete forward_from_;
-
- pfiles_ = 0;
- current_ = 0;
- size_ = 0;
- last_= 0;
-
- this->pfiles_ = 0;
- this->current_ = 0;
- this->size_ = 0;
- this->last_= 0;
+ this->current_ = 0;
+ this->size_ = 0;
+ this->last_ = 0;
+}
+int
+TAO_MProfile::set (CORBA::ULong sz)
+{
+ if (sz == 0)
+ {
+ this->cleanup ();
return 0;
}
// See if we already have an existing profile list or if we need to
// get ridof what we have. @@ Fred, please be consistent with your
// use of this-> as a prefix for data members.
- if (size_)
+ if (this->size_ != 0)
{
// Release all of our profiles.
for (TAO_PHandle h = 0;
- h < size_;
+ h < this->size_;
h++)
if (this->pfiles_[h])
{
@@ -61,10 +53,13 @@ TAO_MProfile::set (CORBA::ULong sz)
this->pfiles_[h] = 0;
}
- // Next see if we can reuse our profile list memory Since
+ // Next see if we can reuse our profile list memory
if (this->size_ != sz)
{
// we cant reuse memory since the array sized are different!
+ // @@ Fred: if sz < this->size_ you could avoid this memory
+ // allocation, you only need another flag to keep the
+ // "capacity".
delete [] this->pfiles_;
ACE_NEW_RETURN (this->pfiles_,
@@ -77,36 +72,40 @@ TAO_MProfile::set (CORBA::ULong sz)
ACE_NEW_RETURN (this->pfiles_,
TAO_Profile_ptr [sz],
-1);
- // this->pfiles_
+ this->size_ = sz;
+ this->last_ = 0;
+ this->current_ = 0;
+
+#if 0
+ // @@ Fred: this does *not* work, the literal 0 is the null pointer,
+ // but the bit representation may be something else.
ACE_OS::memset (this->pfiles_,
0,
sizeof (TAO_Profile_ptr) * sz);
- size_ = sz;
- this->last_ = 0;
- this->current_ = 0;
+#else
+ for (int i = 0; i != this->size_; ++i)
+ this->pfiles_[i] = 0;
+#endif
// @@ since we are being reset, get rid of forward references!
- if (forward_from_)
- delete forward_from_;
+ // if (forward_from_)
+ // delete forward_from_;
- return size_;
+ return this->size_;
}
int
-TAO_MProfile::set (TAO_MProfile *mprofile)
+TAO_MProfile::set (const TAO_MProfile &mprofile)
{
// NOTE: We use mprofile->last_ instead of mprofile->size_ to set
// this->size_. This is so we can use set () to trim a profile
// list!!
- if (mprofile == 0)
- return this->set ((CORBA::ULong) 0);
-
- this->set (mprofile->last_);
+ this->set (mprofile.last_);
// set indexes ...
- this->last_ = mprofile->last_;
+ this->last_ = mprofile.last_;
// These are set in set (ULong);
// this->current_ = 0;
@@ -114,17 +113,73 @@ TAO_MProfile::set (TAO_MProfile *mprofile)
// Now reference all profiles.
- for (TAO_PHandle h = 0;
- h < this->size_;
- h++)
- if (mprofile->pfiles_[h])
- {
- this->pfiles_[h] = mprofile->pfiles_[h];
+ for (TAO_PHandle h = 0; h < this->size_; h++)
+ {
+ this->pfiles_[h] = mprofile.pfiles_[h];
+ if (this->pfiles_[h] != 0)
this->pfiles_[h]->_incr_refcnt ();
- }
+ }
- if (mprofile->forward_from_)
- this->forward_from_ = mprofile->forward_from_;
+ //
+ // @@ Fred: here was a gross violation of the invariants for this
+ // class: if the forward_from_ is owned by us (we call delete all
+ // the time on it) we cannot share it with mprofile.
+ //
+ // if (mprofile->forward_from_)
+ // this->forward_from_ = mprofile->forward_from_;
return 1;
}
+
+int
+TAO_MProfile::add_profile (TAO_Profile *pfile)
+{
+ // skip by the used slots
+ if (last_ == size_) // full!
+ return -1;
+
+ pfiles_[last_++] = pfile;
+
+ if (pfile && pfile->_incr_refcnt () == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%P|%t) Unable to increment reference count in add_profile!\n"),
+ -1);
+ return last_ - 1;
+}
+
+CORBA::Boolean
+TAO_MProfile::is_equivalent (TAO_MProfile *first,
+ TAO_MProfile *second,
+ CORBA::Environment &env)
+{
+ // Two profile lists are equivalent iff at least one of the profiles
+ // form the first list is_equivalent to at least one of the profiles
+ // from the second list!!
+ TAO_Profile_ptr *pfiles1 = first->pfiles ();
+ TAO_Profile_ptr *pfiles2 = second->pfiles ();
+ TAO_PHandle first_cnt = first->profile_count ();
+ TAO_PHandle second_cnt = second->profile_count ();
+
+ for (TAO_PHandle h1 = 0; h1 < first_cnt;h1++)
+ for (TAO_PHandle h2 = 0; h2 < second_cnt; h2++ )
+ if (pfiles1[h1]->is_equivalent (pfiles2[h2], env))
+ return 1;
+
+ return 0;
+}
+
+CORBA::ULong
+TAO_MProfile::hash (CORBA::ULong max, CORBA::Environment &env)
+{
+ CORBA::ULong hashval = 0;
+
+ if (last_ == 0)
+ return 0;
+
+ for (TAO_PHandle h=0; h < last_ ; h++)
+ hashval += pfiles_[h]->hash (max, env);
+
+ // The above hash function return an ULong between 0 and max here we
+ // simply take the average value and round.
+ return hashval / last_;
+}