comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: A question about private types
Date: Thu, 12 Jun 2014 08:21:39 -0700 (PDT)
Date: 2014-06-12T08:21:39-07:00	[thread overview]
Message-ID: <5c5d9f4a-cfcd-47ec-bd96-29e0e02bf32d@googlegroups.com> (raw)
In-Reply-To: <$ql0lCCpEcmTFwCt@ada-augusta.demon.co.uk>

On Thursday, June 12, 2014 8:03:05 AM UTC-7, Mike H wrote:
> ... Or, at lest, I expect the answer to be about private types.

> My instinct is that the package below is vulnerable to erroneous use
> because the "Address" component of "Cell_type" can be changed. I suspect
> that this vulnerability could be removed if "Grid_index_type" is made
> read only. I have attempted to make it a private type but it then
> becomes non-discrete and can no longer be used as a parameter in
> functions such as "Line_of".
> 
> Help please! And, preferably, in a form where the new source code is
> sufficiently transparent to be understood when doing a "walk-through"
> with a C++ speaker.

If you want to prevent clients from modifying the "Address" of a Cell_Type, the answer is to make Cell_Type (not Grid_Index_Type) private, and add procedures/functions for retrieving the fields from Cell_Type that you want to give them permission to retrieve, and for setting the fields that you want to give them permission to set.

By the way, I don't understand this:
  
> I have attempted to make [Grid_Index_Type] a private type but it then 
> becomes non-discrete and can no longer be used as a parameter in 
> functions such as "Line_of".

Making Grid_Index_Type private would cause problems for your Grid_Type definition (although you might be able to use Ada 2012's user-defined indexing features to get around it).  But why would Grid_Index_Type no longer be usable as a parameter to Line_Of?  I'm asking this just in case you have some misunderstanding about the language that needs to be corrected.

                              -- Adam


  reply	other threads:[~2014-06-12 15:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12 15:03 A question about private types Mike H
2014-06-12 15:21 ` Adam Beneschan [this message]
2014-06-12 17:20 ` Jeffrey Carter
2014-06-12 18:11   ` Mike H
replies disabled

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