/* -*- C++ -*- */ // $Id$ // ============================================================================ // // = LIBRARY // ace // // = FILENAME // Array.h // // = AUTHOR // Doug Schmidt // // ============================================================================ #if !defined (ACE_ARRAY_H) #define ACE_ARRAY_H #include "ace/ACE.h" template class ACE_Array { public: // Define a "trait" typedef T TYPE; // = Exceptions. // = Initialization and termination methods. ACE_Array (size_t size); // Dynamically create an uninitialized array. ACE_Array (size_t size, const T &default_value); // Dynamically initialize the entire array to the . ACE_Array (const ACE_Array &s); // The copy constructor performs initialization by making an exact // copy of the contents of parameter , i.e., *this == s will // return true. void operator= (const ACE_Array &s); // Assignment operator performs an assignment by making an exact // copy of the contents of parameter , i.e., *this == s will // return true. Note that if the of is >= than // we can copy it without reallocating. However, if // is < we must delete the , // reallocate a new , and then copy the contents of . ~ACE_Array (void); // Clean up the array (e.g., delete dynamically allocated memory). // = Set/get methods. T &operator [] (size_t index); // Set item in the array at location . Doesn't // perform range checking. const T &operator [] (size_t index) const; // Get item in the array at location . Doesn't // perform range checking. int set (const T &new_item, size_t index); // Set an item in the array at location . Returns // -1 if is not in range, else returns 0. int get (T &item, size_t index) const; // Get an item in the array at location . Returns -1 if // is not in range, else returns 0. Note that this function // copies the item. If you want to avoid the copy, you can use // the const operator [], but then you'll be responsible for range checking. size_t size (void) const; // Returns the of the array. int operator== (const ACE_Array &s) const; // Compare this array with 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 &s) const; // Compare this array with for inequality such that <*this> != // is always the complement of the boolean return value of // <*this> == . private: int in_range (size_t index) const; // Returns 1 if is within range, i.e., 0 >= < // , else returns 0. size_t max_size_; // Maximum size of the array, i.e., the total number of elements // in . size_t cur_size_; // Current size of the array. This starts out being == to // . However, if we are assigned a smaller array, then // will become less than . The purpose of // keeping track of both sizes is to avoid reallocating memory if we // don't have to. T *array_; // Pointer to the array's storage buffer. }; #if defined (__ACE_INLINE__) #include "ace/Array.i" #endif /* __ACE_INLINE__ */ #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) #include "ace/Array.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) #pragma implementation ("Array.cpp") #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ #endif /* ACE_ARRAY_H */