comp.lang.ada
 help / color / mirror / Atom feed
From: Marek <ficorax@gmail.com>
Subject: Re: 2-dimensional view on 1 dimensional array
Date: Tue, 25 Oct 2022 18:59:14 +0200	[thread overview]
Message-ID: <tj94l2$238d3$2@dont-email.me> (raw)

I want just to know if it is possible to make different "view" on 1 
dimensional array. And of course I meant not 2-dimensional array but 
array of arrays. Reason for that is that I want to use slicing on that view.

Ok, here is full specification:

     generic
        type T is private;
        type T_Array is array (Natural range <>) of aliased T;
        type T_Array_Access is access all T_Array;
     package Buffers is

        type Row_Array is array (Natural range <>) of aliased 
T_Array_Access;

        type Row_Array_Access is access all Row_Array;

        type Buffer is tagged
           record
              Raw_Buffer : T_Array_Access   := null;
              Rows_Table : Row_Array_Access := null;
              Rows       : Natural          := 0;
              Columns    : Natural          := 0;
              Step       : Integer          := 0;
              Max_Rows   : Natural          := 0;
           end record;

        procedure Init
          (This    : in out Buffer;
           Buffer  :        T_Array_Access;
           Rows    :        Natural;
           Columns :        Natural;
           Step    :        Integer);

        procedure Set_Value
          (This  : in out Buffer;
           Value :        T);

       function Get_Buffer
         (This : Rendering_Buffer)
          return T_Array_Access
       is (This.Buffer);

       function Get_Rows_Table
         (This : Rendering_Buffer)
          return Row_Array_Access
       is (This.Rows);

       function Get_Columns
         (This : Rendering_Buffer)
          return Natural
       is (This.Columns);

       function Get_Rows
         (This : Rendering_Buffer)
          return Natural
       is (This.Rows);

       function Get_Step
         (This : Rendering_Buffer)
          return Integer
       is (This.Step);

       function Move_Start
         (This       : Rendering_Buffer;
          Col_Offset : Natural;
          Row_Offset : Natural)
          return T_Array_Access;

       function Row
         (This   : Rendering_Buffer;
          R      : Natural)
          return T_Array_Access;

       procedure Copy_From
         (This   : in out Rendering_Buffer;
          Source :        Rendering_Buffer);

     end Buffers;

I consider this package to be a kind of template that I can apply to the 
raw data and get what it expects. That is why I am using access types.
I know this is very C-ish but...

thank you for your answers everybody
Marek
p.s. Be aware that this group is read not only by software engineers. 
Carpenters may also happen ... :)

             reply	other threads:[~2022-10-25 16:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 16:59 Marek [this message]
2022-10-26  8:57 ` 2-dimensional view on 1 dimensional array J-P. Rosen
2022-10-26 15:08 ` AdaMagica
  -- strict thread matches above, loose matches on Subject: below --
2022-10-23 12:31 Marek
2022-10-24 10:31 ` AdaMagica
2022-10-24 10:35   ` AdaMagica
2022-10-25 11:05     ` AdaMagica
2022-10-25 12:57 ` J-P. Rosen
2022-10-25 15:53   ` Jeffrey R.Carter
2022-10-25 19:55     ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox