summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
Diffstat (limited to 'ace')
-rw-r--r--ace/Containers_T.cpp46
-rw-r--r--ace/Containers_T.h101
-rw-r--r--ace/Containers_T.i61
-rw-r--r--ace/OS.cpp2
-rw-r--r--ace/Object_Manager.cpp6
-rw-r--r--ace/Template_Instantiations.cpp4
6 files changed, 179 insertions, 41 deletions
diff --git a/ace/Containers_T.cpp b/ace/Containers_T.cpp
index 0b801da9429..794c5009fc5 100644
--- a/ace/Containers_T.cpp
+++ b/ace/Containers_T.cpp
@@ -2229,11 +2229,12 @@ ACE_DLList<T>::delete_tail (void)
return temp2;
}
+// ****************************************************************
// Dynamically initialize an array.
template <class T>
-ACE_Array<T>::ACE_Array (size_t size)
+ACE_Array_Base<T>::ACE_Array_Base (size_t size)
: max_size_ (size),
cur_size_ (size)
{
@@ -2244,8 +2245,8 @@ ACE_Array<T>::ACE_Array (size_t size)
}
template <class T>
-ACE_Array<T>::ACE_Array (size_t size,
- const T &default_value)
+ACE_Array_Base<T>::ACE_Array_Base (size_t size,
+ const T &default_value)
: max_size_ (size),
cur_size_ (size)
{
@@ -2258,7 +2259,7 @@ ACE_Array<T>::ACE_Array (size_t size,
// The copy constructor (performs initialization).
template <class T>
-ACE_Array<T>::ACE_Array (const ACE_Array<T> &s)
+ACE_Array_Base<T>::ACE_Array_Base (const ACE_Array_Base<T> &s)
: max_size_ (s.size ()),
cur_size_ (s.size ())
{
@@ -2270,18 +2271,18 @@ ACE_Array<T>::ACE_Array (const ACE_Array<T> &s)
// Assignment operator (performs assignment).
-template <class T> void
-ACE_Array<T>::operator= (const ACE_Array<T> &s)
+template <class T> ACE_Array_Base<T>&
+ACE_Array_Base<T>::operator= (const ACE_Array_Base<T> &s)
{
// Check for "self-assignment".
if (this == &s)
- return;
+ return *this;
else if (this->max_size_ < s.size ())
{
delete [] this->array_;
- ACE_NEW (this->array_, T[s.size ()]);
+ ACE_NEW_RETURN (this->array_, T[s.size ()], *this);
this->max_size_ = s.size ();
}
@@ -2290,12 +2291,14 @@ ACE_Array<T>::operator= (const ACE_Array<T> &s)
for (size_t i = 0; i < this->size (); i++)
this->array_[i] = s.array_[i];
+
+ return *this;
}
// Set an item in the array at location index.
template <class T> int
-ACE_Array<T>::set (const T &new_item, size_t index)
+ACE_Array_Base<T>::set (const T &new_item, size_t index)
{
if (this->in_range (index))
{
@@ -2309,7 +2312,7 @@ ACE_Array<T>::set (const T &new_item, size_t index)
// Get an item in the array at location index.
template <class T> int
-ACE_Array<T>::get (T &item, size_t index) const
+ACE_Array_Base<T>::get (T &item, size_t index) const
{
if (this->in_range (index))
{
@@ -2324,7 +2327,7 @@ ACE_Array<T>::get (T &item, size_t index) const
}
template<class T> int
-ACE_Array<T>::size (size_t new_size)
+ACE_Array_Base<T>::max_size (size_t new_size)
{
if (new_size >= this->max_size_)
{
@@ -2338,11 +2341,21 @@ ACE_Array<T>::size (size_t new_size)
this->array_ = tmp;
this->max_size_ = new_size;
}
- this->cur_size_ = new_size;
+ return 0;
+}
+template<class T> int
+ACE_Array_Base<T>::size (size_t new_size)
+{
+ int r = this->max_size (new_size);
+ if (r != 0)
+ return r;
+ this->cur_size_ = new_size;
return 0;
}
+// ****************************************************************
+
// Compare this array with <s> for equality.
template <class T> int
@@ -2350,16 +2363,19 @@ ACE_Array<T>::operator== (const ACE_Array<T> &s) const
{
if (this == &s)
return 1;
- else if (this->cur_size_ != s.cur_size_)
+ else if (this->size () != s.size ())
return 0;
- for (size_t index = 0; index < s.cur_size_; index++)
- if (this->array_[index] != s.array_[index])
+ for (size_t index = 0; index < s.size (); index++)
+ if ((*this)[index] != s[index])
return 0;
return 1;
}
+// ****************************************************************
+
+
template <class T> int
ACE_Array_Iterator<T>::next (T *&item)
{
diff --git a/ace/Containers_T.h b/ace/Containers_T.h
index 3dddf39b32d..c1e2508d443 100644
--- a/ace/Containers_T.h
+++ b/ace/Containers_T.h
@@ -1377,34 +1377,42 @@ private:
// Allocation strategy of the set.
};
+// ****************************************************************
+
// Forward declaration.
template <class T> class ACE_Array_Iterator;
-template <class T>
-class ACE_Array
+template<class T>
+class ACE_Array_Base
{
// = TITLE
- // Implement a dynamic array class.
+ // Implement a simple dynamic array
+ //
+ // = DESCRIPTION
+ // This parametric class implements a simple dynamic array;
+ // resizing must be controlled by the user. No comparison or find
+ // operations are implemented.
+ //
public:
+
// Define a "trait"
typedef T TYPE;
-
- // = Exceptions.
+ typedef ACE_Array_Iterator<T> ITERATOR;
// = Initialization and termination methods.
- ACE_Array (size_t size = 0);
+ ACE_Array_Base (size_t size = 0);
// Dynamically create an uninitialized array.
- ACE_Array (size_t size, const T &default_value);
+ ACE_Array_Base (size_t size, const T &default_value);
// Dynamically initialize the entire array to the <default_value>.
- ACE_Array (const ACE_Array<T> &s);
+ ACE_Array_Base (const ACE_Array_Base<T> &s);
// The copy constructor performs initialization by making an exact
// copy of the contents of parameter <s>, i.e., *this == s will
// return true.
- void operator= (const ACE_Array<T> &s);
+ ACE_Array_Base& operator= (const ACE_Array_Base<T> &s);
// Assignment operator performs an assignment by making an exact
// copy of the contents of parameter <s>, i.e., *this == s will
// return true. Note that if the <max_size_> of <array_> is >= than
@@ -1412,7 +1420,7 @@ public:
// <max_size_> is < <s.max_size_> we must delete the <array_>,
// reallocate a new <array_>, and then copy the contents of <s>.
- ~ACE_Array (void);
+ ~ACE_Array_Base (void);
// Clean up the array (e.g., delete dynamically allocated memory).
// = Set/get methods.
@@ -1443,15 +1451,14 @@ public:
// It copies the old contents into the new array.
// Return -1 on failure.
- int operator== (const ACE_Array<T> &s) const;
- // Compare this array with <s> for equality. Two arrays are equal
- // if their size()'s are equal and all the elements from 0 .. size()
- // are equal.
+ size_t max_size (void) const;
+ // Returns the <max_size_> of the array.
- int operator!= (const ACE_Array<T> &s) const;
- // Compare this array with <s> for inequality such that <*this> !=
- // <s> is always the complement of the boolean return value of
- // <*this> == <s>.
+ int max_size (size_t new_size);
+ // Changes the size of the array to match <new_size>.
+ // It copies the old contents into the new array.
+ // Return -1 on failure.
+ // It does not affect new_size
private:
int in_range (size_t index) const;
@@ -1475,6 +1482,60 @@ private:
friend class ACE_Array_Iterator<T>;
};
+// ****************************************************************
+
+template <class T>
+class ACE_Array : public ACE_Array_Base<T>
+{
+ // = TITLE
+ // Implement a dynamic array class.
+ //
+ // = DESCRIPTION
+ // This class extends ACE_Array_Base, it provides comparison
+ // operators.
+ //
+public:
+ // Define a "trait"
+ typedef T TYPE;
+
+ typedef ACE_Array_Iterator<T> ITERATOR;
+
+ // = Exceptions.
+
+ // = Initialization and termination methods.
+
+ ACE_Array (size_t size = 0);
+ // Dynamically create an uninitialized array.
+
+ ACE_Array (size_t size, const T &default_value);
+ // Dynamically initialize the entire array to the <default_value>.
+
+ ACE_Array (const ACE_Array<T> &s);
+ // The copy constructor performs initialization by making an exact
+ // copy of the contents of parameter <s>, i.e., *this == s will
+ // return true.
+
+ void operator= (const ACE_Array<T> &s);
+ // Assignment operator performs an assignment by making an exact
+ // copy of the contents of parameter <s>, i.e., *this == s will
+ // return true. Note that if the <max_size_> of <array_> is >= than
+ // <s.max_size_> we can copy it without reallocating. However, if
+ // <max_size_> is < <s.max_size_> we must delete the <array_>,
+ // reallocate a new <array_>, and then copy the contents of <s>.
+
+ // = Compare operators
+
+ int operator== (const ACE_Array<T> &s) const;
+ // Compare this array with <s> for equality. Two arrays are equal
+ // if their size()'s are equal and all the elements from 0 .. size()
+ // are equal.
+
+ int operator!= (const ACE_Array<T> &s) const;
+ // Compare this array with <s> for inequality such that <*this> !=
+ // <s> is always the complement of the boolean return value of
+ // <*this> == <s>.
+};
+
template <class T>
class ACE_Array_Iterator
{
@@ -1488,7 +1549,7 @@ class ACE_Array_Iterator
// odd, and dangerous.
public:
// = Initialization method.
- ACE_Array_Iterator (ACE_Array<T> &);
+ ACE_Array_Iterator (ACE_Array_Base<T> &);
// = Iteration methods.
@@ -1513,7 +1574,7 @@ private:
u_int current_;
// Pointer to the current item in the iteration.
- ACE_Array<T> &array_;
+ ACE_Array_Base<T> &array_;
// Pointer to the Array we're iterating over.
};
diff --git a/ace/Containers_T.i b/ace/Containers_T.i
index 50ec3667388..0f972b92884 100644
--- a/ace/Containers_T.i
+++ b/ace/Containers_T.i
@@ -301,38 +301,83 @@ ACE_Ordered_MultiSet<T>::size (void) const
return this->cur_size_;
}
+// ****************************************************************
+
// Clean up the array (e.g., delete dynamically allocated memory).
template <class T> ACE_INLINE
-ACE_Array<T>::~ACE_Array (void)
+ACE_Array_Base<T>::~ACE_Array_Base (void)
{
delete [] this->array_;
}
template <class T> ACE_INLINE size_t
-ACE_Array<T>::size (void) const
+ACE_Array_Base<T>::size (void) const
{
return this->cur_size_;
}
+template <class T> ACE_INLINE size_t
+ACE_Array_Base<T>::max_size (void) const
+{
+ return this->max_size_;
+}
+
template <class T> ACE_INLINE int
-ACE_Array<T>::in_range (size_t index) const
+ACE_Array_Base<T>::in_range (size_t index) const
{
return index < this->cur_size_;
}
template <class T> ACE_INLINE T &
-ACE_Array<T>::operator[] (size_t index)
+ACE_Array_Base<T>::operator[] (size_t index)
{
return this->array_[index];
}
template <class T> ACE_INLINE const T &
-ACE_Array<T>::operator[] (size_t index) const
+ACE_Array_Base<T>::operator[] (size_t index) const
{
return this->array_[index];
}
+// ****************************************************************
+
+template <class T> ACE_INLINE
+ACE_Array<T>::ACE_Array (size_t size)
+ : ACE_Array_Base<T>(size)
+{
+}
+
+template <class T> ACE_INLINE
+ACE_Array<T>::ACE_Array (size_t size,
+ const T &default_value)
+ : ACE_Array_Base<T> (size, default_value)
+{
+}
+
+// The copy constructor (performs initialization).
+
+template <class T>
+ACE_Array<T>::ACE_Array (const ACE_Array<T> &s)
+ : ACE_Array_Base<T> (s)
+{
+}
+
+// Assignment operator (performs assignment).
+
+template <class T> void
+ACE_Array<T>::operator= (const ACE_Array<T> &s)
+{
+ // Check for "self-assignment".
+
+ if (this == &s)
+ return;
+ else {
+ this->ACE_Array_Base<T>::operator= (s);
+ }
+}
+
// Compare this array with <s> for inequality.
template <class T> ACE_INLINE int
@@ -341,6 +386,8 @@ ACE_Array<T>::operator!= (const ACE_Array<T> &s) const
return !(*this == s);
}
+// ****************************************************************
+
template <class T> ACE_INLINE void
ACE_Array_Iterator<T>::dump (void) const
{
@@ -348,7 +395,7 @@ ACE_Array_Iterator<T>::dump (void) const
}
template <class T> ACE_INLINE
-ACE_Array_Iterator<T>::ACE_Array_Iterator (ACE_Array<T> &a)
+ACE_Array_Iterator<T>::ACE_Array_Iterator (ACE_Array_Base<T> &a)
: current_ (0),
array_ (a)
{
@@ -380,6 +427,8 @@ ACE_Array_Iterator<T>::done (void) const
return this->current_ >= array_.size ();
}
+// ****************************************************************
+
template <class T> ACE_INLINE void
ACE_DLList<T>::operator= (ACE_DLList<T> &l)
{
diff --git a/ace/OS.cpp b/ace/OS.cpp
index 6bd6ded7a00..fe136c43a04 100644
--- a/ace/OS.cpp
+++ b/ace/OS.cpp
@@ -1858,11 +1858,13 @@ ACE_TSS_Emulation::tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX])
# if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Array<ACE_TSS_Info>;
+template class ACE_Array_Base<ACE_TSS_Info>;
template class ACE_Array_Iterator<ACE_TSS_Info>;
template class ACE_Node<ACE_TSS_Ref>;
template class ACE_TSS<ACE_TSS_Keys>;
# elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
# pragma instantiate ACE_Array<ACE_TSS_Info>
+# pragma instantiate ACE_Array_Base<ACE_TSS_Info>
# pragma instantiate ACE_Array_Iterator<ACE_TSS_Info>
# pragma instantiate ACE_Node<ACE_TSS_Ref>
# pragma instantiate ACE_TSS<ACE_TSS_Keys>
diff --git a/ace/Object_Manager.cpp b/ace/Object_Manager.cpp
index 67dc50b614d..81af54dcbb3 100644
--- a/ace/Object_Manager.cpp
+++ b/ace/Object_Manager.cpp
@@ -961,8 +961,11 @@ ACE_Static_Object_Lock::cleanup_lock (void)
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
template class ACE_Array<ACE_Thread_Mutex *>;
+ template class ACE_Array_Base<ACE_Thread_Mutex *>;
template class ACE_Array<ACE_Mutex *>;
+ template class ACE_Array_Base<ACE_Mutex *>;
template class ACE_Array<ACE_RW_Thread_Mutex *>;
+ template class ACE_Array_Base<ACE_RW_Thread_Mutex *>;
template class ACE_Cleanup_Adapter<ACE_Null_Mutex>;
template class ACE_Cleanup_Adapter<ACE_Mutex>;
template class ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex>;
@@ -980,8 +983,11 @@ ACE_Static_Object_Lock::cleanup_lock (void)
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
# pragma instantiate ACE_Array<ACE_Thread_Mutex *>
+# pragma instantiate ACE_Array_Base<ACE_Thread_Mutex *>
# pragma instantiate ACE_Array<ACE_Mutex *>
+# pragma instantiate ACE_Array_Base<ACE_Mutex *>
# pragma instantiate ACE_Array<ACE_RW_Thread_Mutex *>
+# pragma instantiate ACE_Array_Base<ACE_RW_Thread_Mutex *>
# pragma instantiate ACE_Cleanup_Adapter<ACE_Null_Mutex>
# pragma instantiate ACE_Cleanup_Adapter<ACE_Mutex>
# pragma instantiate ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex>
diff --git a/ace/Template_Instantiations.cpp b/ace/Template_Instantiations.cpp
index eb19acdc688..54d458591f6 100644
--- a/ace/Template_Instantiations.cpp
+++ b/ace/Template_Instantiations.cpp
@@ -57,9 +57,13 @@ template class ACE_Guard<ACE_RW_Thread_Mutex>;
ACE_MT (template class ACE_TSS_Guard<ACE_Recursive_Thread_Mutex>);
template class ACE_Array<ACE_Mutex *>;
+template class ACE_Array_Base<ACE_Mutex *>;
template class ACE_Array<ACE_RW_Thread_Mutex *>;
+template class ACE_Array_Base<ACE_RW_Thread_Mutex *>;
template class ACE_Array<ACE_TSS_Info>;
+template class ACE_Array_Base<ACE_TSS_Info>;
template class ACE_Array<ACE_Thread_Mutex *>;
+template class ACE_Array_Base<ACE_Thread_Mutex *>;
template class ACE_Array_Iterator<ACE_TSS_Info>;
// ACE_PROCESS_MUTEX is defined in Malloc.h,