deep_array< contents > Class Template Reference

This object mimics a C array but tracks its contents as deep pointers. More...

#include <deep_array.h>

List of all members.

Public Member Functions

 deep_array (int number=0)
 Constructs a deep_array with room for "number" objects.
 deep_array (const deep_array< contents > &copy_from)
 copies the contents & sizing information from "copy_from".
 ~deep_array ()
 destroys the memory allocated for the objects.
bool valid () const
 Reports whether the construction succeeded and allocated memory.
void reset (int number=0)
 Resizes this array to the "number" of elements specified.
deep_arrayoperator= (const deep_array< contents > &copy_from)
 Copies the deep_array in "copy_from" into this.
int length () const
 Returns the current reported length of the allocated C array.
int last () const
 Returns the last valid element in the deep_array.
const contents & get (int index) const
 Accesses individual objects stored in "this" at the "index" position.
contents & use (int index)
 A non-constant version of get(); the returned object can be modified.
const contents & operator[] (int index) const
 Synonym for get that provides the expected array indexing syntax.
contents & operator[] (int index)
 Synonym for use that provides the expected array indexing syntax.
outcome put (int index, const contents &to_put)
 Stores an object at the index "index" in the deep_array.
outcome store (int index, contents *to_store)
 Drops the "to_store" pointer directly into our list at "index".
const contents * restore (int index) const
 Pulls the object at "index" back out of the array.
contents * acquire (int index)
 Retrieves the object at "index" and removes the slot in the array.
deep_array concatenation (const deep_array &to_concatenate) const
 Returns the concatenation of "this" and the array "to_concatenate".
deep_array concatenation (const contents &to_concatenate) const
 Returns the concatenation of "this" and the object "to_concatenate".
deep_arrayconcatenate (const deep_array &to_concatenate)
 Appends the array "to_concatenate" onto "this" and returns "this".
deep_arrayconcatenate (const contents &to_concatenate)
 Appends the object "to_concatenate" onto "this" and returns "this".
deep_array operator+ (const deep_array &to_cat) const
 Synonym for concatenation.
deep_array operator+ (const contents &to_concatenate) const
 Synonym for concatenation.
deep_arrayoperator+= (const deep_array &to_concatenate)
 Synonym for concatenate that modifies "this".
deep_arrayoperator+= (const contents &to_concatenate)
 Synonym for concatenate that modifies "this".
deep_array subarray (int start, int end) const
 Returns the array segment between the indices "start" and "end".
outcome insert (int index, int new_indices)
 Adds "new_indices" new positions for objects into the array at "index".
outcome overwrite (int index, const deep_array &write_with, int count=-1)
 Stores the array "write_with" into the current array at the "index".
outcome resize (int new_size, common::how_to_copy way=common::NEW_AT_END)
 Changes the size of the array to "new_size".
outcome zap (int start, int end)
 Deletes from "this" the objects inclusively between "start" and "end".
outcome shrink ()
 Cuts loose any allocated space that is beyond the real length.
void swap_contents (deep_array< contents > &other)
 Exchanges the contents of "this" and "other".


Detailed Description

template<class contents>
class deep_array< contents >

This object mimics a C array but tracks its contents as deep pointers.

This object is intended to provide an interface similar to the array template in basis, but it instead stores all contents as pointers rather than as a contiguous array. This saves a lot of copying costs for complicated objects. A method is provided that allows object pointers to be stored directly (see store(), restore() and acquire()).

Definition at line 32 of file deep_array.h.


Constructor & Destructor Documentation

template<class contents>
deep_array< contents >::deep_array ( int  number = 0  ) 

Constructs a deep_array with room for "number" objects.

Definition at line 25 of file deep_array.cpp.

template<class contents>
deep_array< contents >::deep_array ( const deep_array< contents > &  copy_from  ) 

copies the contents & sizing information from "copy_from".

Definition at line 31 of file deep_array.cpp.

References deep_array< contents >::length(), deep_array< contents >::put(), and deep_array< contents >::restore().

template<class contents>
deep_array< contents >::~deep_array (  ) 

destroys the memory allocated for the objects.

Definition at line 41 of file deep_array.cpp.

References WHACK().


Member Function Documentation

template<class contents>
bool deep_array< contents >::valid (  )  const [inline]

Reports whether the construction succeeded and allocated memory.

Definition at line 43 of file deep_array.h.

Referenced by data_structure::unpack().

template<class contents>
void deep_array< contents >::reset ( int  number = 0  ) 

Resizes this array to the "number" of elements specified.

Definition at line 45 of file deep_array.cpp.

Referenced by deep_array_tester(), deep_array< contents >::resize(), and data_structure::unpack().

template<class contents>
deep_array< contents > & deep_array< contents >::operator= ( const deep_array< contents > &  copy_from  ) 

Copies the deep_array in "copy_from" into this.

Definition at line 102 of file deep_array.cpp.

References NIL.

template<class contents>
int deep_array< contents >::length (  )  const

Returns the current reported length of the allocated C array.

Definition at line 49 of file deep_array.cpp.

Referenced by compare_deep_arrays(), deep_array< contents >::concatenate(), deep_array< contents >::deep_array(), deep_array_tester(), fill_in(), deep_array< contents >::overwrite(), data_structure::pack(), data_structure::packed_size(), and deep_array< contents >::resize().

template<class contents>
int deep_array< contents >::last (  )  const

Returns the last valid element in the deep_array.

Definition at line 53 of file deep_array.cpp.

Referenced by deep_array_tester().

template<class contents>
const contents & deep_array< contents >::get ( int  index  )  const

Accesses individual objects stored in "this" at the "index" position.

If the index is out of range, then a bogus reference (to internally held garbage) is returned.

Definition at line 115 of file deep_array.cpp.

References bounds_halt, FUNCDEF, and this.

Referenced by deep_array_tester(), and deep_array< istring >::operator[]().

template<class contents>
contents & deep_array< contents >::use ( int  index  ) 

A non-constant version of get(); the returned object can be modified.

Definition at line 127 of file deep_array.cpp.

References bounds_halt, FUNCDEF, deep_array< contents >::store(), and this.

Referenced by deep_array< istring >::operator[]().

template<class contents>
const contents& deep_array< contents >::operator[] ( int  index  )  const [inline]

Synonym for get that provides the expected array indexing syntax.

Definition at line 65 of file deep_array.h.

template<class contents>
contents& deep_array< contents >::operator[] ( int  index  )  [inline]

Synonym for use that provides the expected array indexing syntax.

Definition at line 67 of file deep_array.h.

template<class contents>
outcome deep_array< contents >::put ( int  index,
const contents &  to_put 
)

Stores an object at the index "index" in the deep_array.

The outcome is "OUT_OF_RANGE" if the index does not exist.

Definition at line 161 of file deep_array.cpp.

References common::BAD_INPUT, bounds_halt, FUNCDEF, common::OKAY, and this.

Referenced by deep_array< contents >::deep_array(), deep_array_tester(), fill_in(), deep_array< contents >::overwrite(), and deep_array< contents >::subarray().

template<class contents>
outcome deep_array< contents >::store ( int  index,
contents *  to_store 
)

Drops the "to_store" pointer directly into our list at "index".

Be careful! This requires that the deep_array take over ownership of the "to_store" object. The only valid way to get that object back is to acquire() it.

Definition at line 136 of file deep_array.cpp.

References common::BAD_INPUT, bounds_halt, FUNCDEF, common::OKAY, and this.

Referenced by deep_array< contents >::overwrite(), and deep_array< contents >::use().

template<class contents>
const contents * deep_array< contents >::restore ( int  index  )  const

Pulls the object at "index" back out of the array.

This leaves the slot at index empty. The returned object is now the caller's responsibility and must eventually be destroyed.

Definition at line 145 of file deep_array.cpp.

References bounds_halt, FUNCDEF, NIL, and this.

Referenced by deep_array< contents >::concatenate(), deep_array< contents >::deep_array(), fill_in(), deep_array< contents >::overwrite(), and deep_array< contents >::subarray().

template<class contents>
contents * deep_array< contents >::acquire ( int  index  ) 

Retrieves the object at "index" and removes the slot in the array.

This is just like restore() except that the "index" slot will be removed from the array. It's the equivalent of doing restore() followed by a zap().

Definition at line 153 of file deep_array.cpp.

References bounds_halt, FUNCDEF, NIL, and this.

template<class contents>
deep_array< contents > deep_array< contents >::concatenation ( const deep_array< contents > &  to_concatenate  )  const

Returns the concatenation of "this" and the array "to_concatenate".

Definition at line 172 of file deep_array.cpp.

References deep_array< contents >::concatenate().

Referenced by deep_array< istring >::operator+().

template<class contents>
deep_array< contents > deep_array< contents >::concatenation ( const contents &  to_concatenate  )  const

Returns the concatenation of "this" and the object "to_concatenate".

Definition at line 181 of file deep_array.cpp.

References deep_array< contents >::concatenate().

template<class contents>
deep_array< contents > & deep_array< contents >::concatenate ( const deep_array< contents > &  to_concatenate  ) 

Appends the array "to_concatenate" onto "this" and returns "this".

Definition at line 190 of file deep_array.cpp.

References deep_array< contents >::length(), NIL, and deep_array< contents >::restore().

Referenced by deep_array< contents >::concatenation(), deep_array_tester(), and deep_array< istring >::operator+=().

template<class contents>
deep_array< contents > & deep_array< contents >::concatenate ( const contents &  to_concatenate  ) 

Appends the object "to_concatenate" onto "this" and returns "this".

Definition at line 207 of file deep_array.cpp.

template<class contents>
deep_array deep_array< contents >::operator+ ( const deep_array< contents > &  to_cat  )  const [inline]

Synonym for concatenation.

Definition at line 101 of file deep_array.h.

template<class contents>
deep_array deep_array< contents >::operator+ ( const contents &  to_concatenate  )  const [inline]

Synonym for concatenation.

Definition at line 104 of file deep_array.h.

template<class contents>
deep_array& deep_array< contents >::operator+= ( const deep_array< contents > &  to_concatenate  )  [inline]

Synonym for concatenate that modifies "this".

Definition at line 107 of file deep_array.h.

template<class contents>
deep_array& deep_array< contents >::operator+= ( const contents &  to_concatenate  )  [inline]

Synonym for concatenate that modifies "this".

Definition at line 110 of file deep_array.h.

template<class contents>
deep_array< contents > deep_array< contents >::subarray ( int  start,
int  end 
) const

Returns the array segment between the indices "start" and "end".

This is all characters from "start" to "end" inclusively, as long as those values are valid for this array. Even then, an intelligent default is usually assumed if the indices are out of range.

Definition at line 215 of file deep_array.cpp.

References bounds_return, FUNCDEF, deep_array< contents >::put(), deep_array< contents >::restore(), and this.

Referenced by deep_array_tester().

template<class contents>
outcome deep_array< contents >::insert ( int  index,
int  new_indices 
)

Adds "new_indices" new positions for objects into the array at "index".

Definition at line 57 of file deep_array.cpp.

Referenced by deep_array_tester().

template<class contents>
outcome deep_array< contents >::overwrite ( int  index,
const deep_array< contents > &  write_with,
int  count = -1 
)

Stores the array "write_with" into the current array at the "index".

The current contents are overwritten with "write_with". If the index is invalid, then OUT_OF_RANGE is returned. If the "write_with" array cannot fit due to the boundaries of "this" array, then only the portion that can fit is used. If "count" is negative, the whole "write_with" array is used; otherwise, only "count" elements are used.

Definition at line 230 of file deep_array.cpp.

References common::BAD_INPUT, bounds_halt, FUNCDEF, deep_array< contents >::length(), negative(), NIL, common::OKAY, common::OUT_OF_RANGE, deep_array< contents >::put(), deep_array< contents >::restore(), deep_array< contents >::store(), and this.

Referenced by deep_array_tester().

template<class contents>
outcome deep_array< contents >::resize ( int  new_size,
common::how_to_copy  way = common::NEW_AT_END 
)

Changes the size of the array to "new_size".

If "way" is NEW_AT_END and the array grows, then new space is added at the end and the prefix of the array is the same as the old array. If the "way" is NEW_AT_END, but the array shrinks, then the new array is a prefix of the old array. If "way" is NEW_AT_BEGINNING and the array grows, then the suffix of the array is the same as the old one and the space is added at the beginning. if the "way" is NEW_AT_BEGINNING but the array shrinks, then the new array is a suffix of the old array. if "way" is DONT_COPY, then the old contents are not copied.

Definition at line 73 of file deep_array.cpp.

References common::DONT_COPY, deep_array< contents >::length(), common::NEW_AT_END, common::OKAY, and deep_array< contents >::reset().

Referenced by deep_array_tester().

template<class contents>
outcome deep_array< contents >::zap ( int  start,
int  end 
)

Deletes from "this" the objects inclusively between "start" and "end".

C-array conventions are used (0 through length()-1 are valid if length() > 0). If either index is out of range, then a default is assumed.

Definition at line 61 of file deep_array.cpp.

Referenced by deep_array_tester().

template<class contents>
outcome deep_array< contents >::shrink (  ) 

Cuts loose any allocated space that is beyond the real length.

Definition at line 66 of file deep_array.cpp.

References common::OKAY.

template<class contents>
void deep_array< contents >::swap_contents ( deep_array< contents > &  other  ) 

Exchanges the contents of "this" and "other".

No validation is performed but this should always succeed given deep_arrays that were constructed properly.

Definition at line 69 of file deep_array.cpp.

References deep_array< contents >::_real_list.

Referenced by data_structure::unpack().


The documentation for this class was generated from the following files:
Generated on Fri Oct 10 04:30:07 2008 for HOOPLE Libraries by  doxygen 1.5.1