      *>----------------------------------------------------------------
      *> An Array is a indexed collection of objects or intrinsic
      *> data. The indices should be pic x(4) comp-5 items and range in
      *> value between 1 and the size of the array.
      *>
      *> Copyright (C) 1991-1999 Micro Focus International Ltd.
      *>
      *>----------------------------------------------------------------
      $set mfoo
       class-id. Array data is protected
               inherits from arrayedcollection with data.


        object section.
        class-control.
           arrayedcollection is class "arrayed"
           array is class "array".

       class-object.
       object-storage section.
       end class-object.

       Object.
       object-storage section.
      *>----------------------------------------------------------------
      *> Returns self as this is already an instance of Array.
      *>----------------------------------------------------------------
       method-id. "asArray".
       linkage section.
       01 defaultresult    usage object reference.

       procedure division returning defaultresult.
           invoke self "copy" returning defaultResult
           exit method.
       end method "asArray".

      *>----------------------------------------------------------------
      *> Return the element at index position anIndex. Raise an
      *> exception if anIndex is outside the bounds of the array.
      *>----------------------------------------------------------------
       method-id. "at".
       local-storage section.
       01 realindex             pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 returnelement        COLLECTABLE.
       01 instanceData         pic x.
       procedure division using anindex returning returnelement.
           if anindex < 1 or anindex > numberelements
               invoke self "errorInBounds" returning returnelement
               exit method
           else
               compute realindex = (anindex - 1) * collectionstride + 1
               set address of instanceData to collptr
      $if GC defined
               if collectionTemplate = null
                   call "oopsassignobjectreference" using
                       by reference returnelement
                       by value
                          instancedata(realindex : objectreferencesize)
               else
                   if Storingobjects
                       invoke instancedata(realindex : collectionstride)
                         as collectionTemplate "getValue"
                         returning returnElement
                   else
                       move instancedata(realindex : collectionstride)
                        to returnelement(1:collectionStride)
                   end-if
               end-if
      $else
               move instancedata(realindex : collectionstride)
                    to returnelement(1:collectionStride)
      $end
               exit method
           end-if.
       end method "at".


      *>----------------------------------------------------------------
      *> PRIVATE. Return the element at index position anIndex. Raise an
      *> exception if anIndex is outside the bounds of the array.
      *>----------------------------------------------------------------
       method-id. "atNoGC".
       local-storage section.
       01 realindex             pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 returnelement        COLLECTABLE.
       01 instanceData         pic x.
       procedure division using anindex returning returnelement.
           compute realindex = (anindex - 1) * collectionstride + 1
           set address of instanceData to collptr
           move instancedata(realindex : collectionstride)
                    to returnelement(1:collectionStride)
           exit method
       end method "atNoGC".

      *>---------------------------------------------------------------
      *> Store aValue at position anIndex. Raise an
      *> exception if anIndex is outside the bounds of the array.
      *>---------------------------------------------------------------
       method-id. "atPut".
       local-storage section.
       01 realindex             pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 avalue               COLLECTABLE.
       01 instanceData         pic x.
       procedure division using anindex avalue.
           if anindex < 1 or anindex > numberelements
               invoke self "errorinBounds"
           else
               compute realindex = (anindex - 1) * collectionstride + 1
               set address of instanceData to collptr
      $if GC defined  
               if collectionTemplate = null
                   call "oopsassignobjectreference" using
                     by reference instancedata(realindex:)
                     by value avalue(1:objectreferencesize)
               else
                   if Storingobjects
                       invoke avalue(1:collectionStride)
                         as collectionTemplate "getValue"
                         returning instancedata(realindex:)
                   else
                       move avalue(1:collectionStride)
                        to instancedata(realindex : collectionstride)
                   end-if
               end-if
      $else
               move avalue(1:collectionStride)
                 to instancedata(realindex : collectionstride)
      $end
           end-if
           exit method.
       end method "atPut".
       end object.
       end class array.
