summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog-98b6
-rw-r--r--ace/Containers_T.cpp27
-rw-r--r--ace/Containers_T.h7
3 files changed, 37 insertions, 3 deletions
diff --git a/ChangeLog-98b b/ChangeLog-98b
index 9fd076d9379..a4bc43ef251 100644
--- a/ChangeLog-98b
+++ b/ChangeLog-98b
@@ -1,3 +1,9 @@
+Mon Oct 12 09:43:07 1998 Carlos O'Ryan <coryan@cs.wustl.edu>
+
+ * ace/Containers_T.h:
+ * ace/Containers_T.cpp:
+ Added a new method to modify the size of an ACE_Array.
+
Mon Oct 12 09:23:49 1998 David L. Levine <levine@cs.wustl.edu>
* netsvcs/lib/Name_Handler.cpp (lists_entries): one more try
diff --git a/ace/Containers_T.cpp b/ace/Containers_T.cpp
index 525974bb1b2..87f5cc15706 100644
--- a/ace/Containers_T.cpp
+++ b/ace/Containers_T.cpp
@@ -2216,12 +2216,15 @@ ACE_Array<T>::ACE_Array (size_t size)
: max_size_ (size),
cur_size_ (size)
{
- ACE_NEW (this->array_, T[size]);
+ if (size != 0)
+ ACE_NEW (this->array_, T[size]);
+ else
+ this->array_ = 0;
}
template <class T>
ACE_Array<T>::ACE_Array (size_t size,
- const T &default_value)
+ const T &default_value)
: max_size_ (size),
cur_size_ (size)
{
@@ -2299,6 +2302,26 @@ ACE_Array<T>::get (T &item, size_t index) const
return -1;
}
+template<class T> int
+ACE_Array<T>::size (size_t new_size)
+{
+ if (new_size >= this->max_size_)
+ {
+ // @@ We should use auto_ptr<>!
+ T* tmp;
+ ACE_NEW_RETURN (tmp, T[new_size], -1);
+
+ for (size_t i = 0; i < this->cur_size_; ++i)
+ tmp[i] = this->array_[i];
+ delete[] this->array_;
+ this->array_ = tmp;
+ this->max_size_ = new_size;
+ }
+ this->cur_size_ = new_size;
+
+ return 0;
+}
+
// Compare this array with <s> for equality.
template <class T> int
diff --git a/ace/Containers_T.h b/ace/Containers_T.h
index fcf858053e0..bb1d445ff17 100644
--- a/ace/Containers_T.h
+++ b/ace/Containers_T.h
@@ -1376,7 +1376,7 @@ public:
// = Initialization and termination methods.
- ACE_Array (size_t size);
+ ACE_Array (size_t size = 0);
// Dynamically create an uninitialized array.
ACE_Array (size_t size, const T &default_value);
@@ -1421,6 +1421,11 @@ public:
size_t size (void) const;
// Returns the <cur_size_> of the array.
+ int 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.
+
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()