comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: [newbie] simple(?) data structures
Date: Sun, 13 Jun 2004 04:46:14 GMT
Date: 2004-06-13T04:46:14+00:00	[thread overview]
Message-ID: <q_Qyc.8373$Hg2.4956@attbi_s04> (raw)
In-Reply-To: 2j1e30Fsrg8vU1@uni-berlin.de

To me this looks like a simple dynamically sized structure.  Here is the
package spec I might use.  Note that in your example you set the x and y
sizes to the same.  For my spec I force them to the same size in the
Go_Board definition.

package Go is

  type Stone is ( Empty, Black, White );

  Max_Size : constant := 10_000;

  type Go_Range is range 1 .. Max_Size;

  type Go_Board( Go_Size : Go_Range ) is private;

  function Get_Stone( board : Go_Board; x, y : Go_Range ) return Stone;

  function Get_Size( board : Go_Board ) return Go_Range;

private
  type Go_Cells is array( Go_Range range <>, Go_Range range <> ) of Stone;

  type Go_Board( Go_Size : Go_Range ) is
    record
      data : Go_Cells( 1 .. Go_Size, 1 .. Go_Size );
    end record;

end Go;

Steve
(The Duck)

"Roland Illig" <roland.illig@gmx.de> wrote in message
news:2j1e30Fsrg8vU1@uni-berlin.de...
> Hi,
>
> I'm doing my first steps with Ada. I tried to model a Go board and
> failed. In Java/C++, I would do it like this:
>
> enum Stone { Empty, Black, White };
>
> class Go_Board {
>      private Stone[][] data;
>
>      public Go_Board(int size) {
>          data = new Stone[size][size];
>      }
>      public int getWidth() {
>          return data[0].length;
>      }
>      public int getHeight() {
>          return data.length;
>      }
>      public Stone getStone(int x, int y) {
>          return data[y][x];
>      }
> }
> /* EOF */
>
> How can I do this in Ada? I already tried something with packages and
> generics, but that did not look nice. But I want it to look nice and
Adaish.
>
> Roland





  parent reply	other threads:[~2004-06-13  4:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-12 22:23 [newbie] simple(?) data structures Roland Illig
2004-06-12 22:52 ` Frank
2004-06-13  0:10 ` Ludovic Brenta
2004-06-13  3:13   ` Roland Illig
2004-06-13  7:59     ` Marius Amado Alves
2004-06-13 11:56       ` Ludovic Brenta
2004-06-13 14:47     ` Stephen Leake
2004-06-13 18:24       ` Jeffrey Carter
2004-06-13  0:31 ` Jeffrey Carter
2004-06-13  1:26 ` tmoran
2004-06-13  2:47 ` tmoran
2004-06-13  3:53   ` Roland Illig
2004-06-13 10:12     ` Georg Bauhaus
2004-06-13 23:32       ` Robert I. Eachus
2004-06-14 12:29         ` Georg Bauhaus
2004-06-13  4:46 ` Steve [this message]
2004-06-13  4:59   ` tmoran
2004-06-13 17:58     ` Jeffrey Carter
2004-06-16 11:08 ` Roland Illig
2004-06-16 21:05   ` Georg Bauhaus
2004-06-16 23:23     ` Roland Illig
2004-06-17  0:44       ` Jeffrey Carter
2004-06-17 12:37         ` Hyman Rosen
2004-06-17 13:11           ` Björn Persson
2004-06-18  9:55             ` Ole-Hjalmar Kristensen
2004-06-18 11:03               ` Björn Persson
2004-06-18 12:04               ` Hyman Rosen
2004-06-22  8:11                 ` Ole-Hjalmar Kristensen
2004-06-18  0:20           ` David Starner
2004-06-18  5:06             ` Hyman Rosen
2004-06-18  5:47               ` Martin Krischik
2004-06-18  7:30                 ` Brian May
2004-06-18 14:21                 ` Larry Kilgallen
2004-06-19 19:51                 ` Robert I. Eachus
2004-06-18 15:04               ` Georg Bauhaus
2004-06-19  2:02               ` James Rogers
2004-06-18  9:51           ` Ole-Hjalmar Kristensen
2004-06-27 13:12   ` Jacob Sparre Andersen
2004-06-24  0:09 ` Matthew Heaney
2004-06-24 14:50   ` Nick Roberts
replies disabled

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