diff options
Diffstat (limited to 'utils/Array.cc')
-rw-r--r-- | utils/Array.cc | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/utils/Array.cc b/utils/Array.cc index e51e7ae..26bafbe 100644 --- a/utils/Array.cc +++ b/utils/Array.cc @@ -17,24 +17,24 @@ #include <memory.h> #include <stdio.h> -/*?class CcuArray -\typ{CcuArray}s are dynamic arrays whose lower bound is 0. For a -\typ{CcuArray} with size \var{size}, the valid indices are \var{0, \ldots, size -- 1.} -Their elements are of type \typ{CcuArrayItem*}. Methods are provided for +/*?class IvlArray +\typ{IvlArray}s are dynamic arrays whose lower bound is 0. For a +\typ{IvlArray} with size \var{size}, the valid indices are \var{0, \ldots, size -- 1.} +Their elements are of type \typ{IvlArrayItem*}. Methods are provided for initialization, data storage and retrieval, and a few other utilities. ?*/ -CcuArrayItem* CcuArray::InvalidCell = 0; +IvlArrayItem* IvlArray::InvalidCell = 0; /*? -Initialize a \typ{CcuArray} with size \var{size}. +Initialize a \typ{IvlArray} with size \var{size}. Entries are initialized to \var{value}. ?*/ -CcuArray :: CcuArray (int size, CcuArrayItem* value) +IvlArray :: IvlArray (int size, IvlArrayItem* value) { if (size > 0) { - Data = new CcuArrayItem* [size]; - register CcuArrayItem** p = Data; + Data = new IvlArrayItem* [size]; + register IvlArrayItem** p = Data; for (register int i = 0; i < size; ++i, ++p) *p = value; } else { @@ -47,15 +47,15 @@ CcuArray :: CcuArray (int size, CcuArrayItem* value) } /*?nodoc?*/ -CcuArray :: CcuArray (const CcuArray& a) +IvlArray :: IvlArray (const IvlArray& a) : Length (a.Length) { if (Length == 0) { Data = 0; } else { - Data = new CcuArrayItem* [Length]; - register CcuArrayItem** p; - register CcuArrayItem** q; + Data = new IvlArrayItem* [Length]; + register IvlArrayItem** p; + register IvlArrayItem** q; register int i; for (p = Data, q = a.Data, i = Length ; i--; ++p, ++q) *p = *q; @@ -63,7 +63,7 @@ CcuArray :: CcuArray (const CcuArray& a) } /*?nodoc?*/ -CcuArray :: ~CcuArray () +IvlArray :: ~IvlArray () { /* Free the data */ Clean (); @@ -74,7 +74,7 @@ CcuArray :: ~CcuArray () */ /*?hidden?*/ void -CcuArray :: Clean () +IvlArray :: Clean () { if (Data) #ifndef CPLUS_BUG4 @@ -87,14 +87,13 @@ CcuArray :: Clean () Length = 0; } - /*? Set all entries to \var{value}. ?*/ void -CcuArray :: Reset (CcuArrayItem* value) +IvlArray :: Reset (IvlArrayItem* value) { - register CcuArrayItem** p; + register IvlArrayItem** p; register int i; for (p = Data, i = Length ; i--; ++p) *p = value; @@ -104,15 +103,15 @@ CcuArray :: Reset (CcuArrayItem* value) Copy the contents of the array \var{from} into this array. The old contents, if any, are freed, and new memory is allocated for the copy. ?*/ -CcuArray& -CcuArray :: operator = (const CcuArray& from) +IvlArray& +IvlArray :: operator = (const IvlArray& from) { if (this != &from) { Clean (); Length = from.Length; if (Length > 0 && from.Data) { - Data = new CcuArrayItem* [Length]; - memcpy (Data, from.Data, Length * sizeof (CcuArrayItem*)); + Data = new IvlArrayItem* [Length]; + memcpy (Data, from.Data, Length * sizeof (IvlArrayItem*)); } else Data = 0; } @@ -125,25 +124,25 @@ are set to \var{value}. This function reallocates the contents of the array. ?*/ void -CcuArray :: Resize (int size, CcuArrayItem* value) +IvlArray :: Resize (int size, IvlArrayItem* value) { if (size <= 0) { Clean (); return; } - CcuArrayItem** NewData = new CcuArrayItem* [size]; + IvlArrayItem** NewData = new IvlArrayItem* [size]; /* if the new sequence is longer, copy and fill end, else just copy */ if (size > Length) { if (Length) - memcpy (NewData, Data, Length * sizeof (CcuArrayItem*)); + memcpy (NewData, Data, Length * sizeof (IvlArrayItem*)); - register CcuArrayItem** pfil = NewData + Length; + register IvlArrayItem** pfil = NewData + Length; for (register int i = size - Length; i--; *pfil++ = value) ; } else - memcpy (NewData, Data, size * sizeof (CcuArrayItem*)); + memcpy (NewData, Data, size * sizeof (IvlArrayItem*)); /* free old data and set new array */ @@ -152,12 +151,11 @@ CcuArray :: Resize (int size, CcuArrayItem* value) Length = size; } - /*? Return the address of the \var{i}th element. ?*/ -CcuArrayItem** -CcuArray :: operator + (register int i) const +IvlArrayItem** +IvlArray :: operator + (register int i) const { if (Check (i)) return Data+i; @@ -167,14 +165,13 @@ CcuArray :: operator + (register int i) const } } - /*? Get a reference to the \var{i}-th entry, so that this entry can be read or written. If \var{i} is outside the bounds, the operator returns a reference to a static variable which initially contains 0. ?*/ -CcuArrayItem*& -CcuArray :: operator [] (register int i) const +IvlArrayItem*& +IvlArray :: operator [] (register int i) const { if (Check (i)) return Data [i]; @@ -185,42 +182,42 @@ CcuArray :: operator [] (register int i) const } #ifdef DOC -/*?class CcuArrayOf -The generic class \typ{CcuArrayOf} is a derived class of \typ{CcuArray} that provides +/*?class IvlArrayOf +The generic class \typ{IvlArrayOf} is a derived class of \typ{IvlArray} that provides arrays of pointers to class objects. When parameterized by the class \typ{ITEM}, the following functions are redefined: ?*/ /*?nextdoc?*/ -CcuArrayOf :: CcuArrayOf (int size, ITEM* value = 0) +IvlArrayOf :: IvlArrayOf (int size, ITEM* value = 0) { } /*?nextdoc?*/ void -CcuArrayOf :: Reset (ITEM* value = 0) +IvlArrayOf :: Reset (ITEM* value = 0) { } /*?nextdoc?*/ void -CcuArrayOf :: Resize (int size, ITEM* value = 0) +IvlArrayOf :: Resize (int size, ITEM* value = 0) { } /*?nextdoc?*/ ITEM*& -CcuArrayOf :: operator [] (int i) const +IvlArrayOf :: operator [] (int i) const { } /*? -These functions are equivalent to their homonyms in the class \typ{CcuArray}, +These functions are equivalent to their homonyms in the class \typ{IvlArray}, except that they are customized in order to manipulate pointers to \typ{ITEM} instead of \typ{void*}. ?*/ ITEM** -CcuArrayOf :: operator + (int i) const +IvlArrayOf :: operator + (int i) const { } |