comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <John_Volan@syspac.com>
Cc: John_Volan@syspac.com
Subject: Re: Ada 83:  Type defaults
Date: 1996/09/11
Date: 1996-09-11T00:00:00+00:00	[thread overview]
Message-ID: <3236F243.7FAA@syspac.com> (raw)
In-Reply-To: 516mkh$d3m@ryker.dma.gov


hehmeyerj wrote:
> 
> This may be a simple problem but...
> 
> I have an enumeration type declaration.  For example:
> 
> type x is (A, B, C, D);
> 
> And I have about three hundred variables of type x scattered throughout
> 50 packages.  How would you default the type to, say A, without going
> to each individual variable declaration and explicitly defaulting them.
> (ie y : x := A;)
> 
> TIA

You can't specify a default value for a scalar type (e.g. enumeration
type) but you can for a record type (whether public or private):

  package P is -- whatever you originally had X in
    type X is private;
    function A return X; -- returns X'(Value => A_Value)
    function B return X; -- returns X'(Value => B_Value)
    function C return X; -- returns X'(Value => C_Value)
    function D return X; -- returns X'(Value => D_Value)
    -- Don't know how much enumeration semantics you need, but you may
    -- need to declare overloadings for "<", ">", "<=", ">=", and 
    -- something that can take the place of 'Succ, 'Pred, etc. If you
really
    -- need to be able to iterate over X in a for loop, you're out of
    -- luck, sorry
  private
    type X_Value is (A_Value, B_Value, C_Value, D_Value);
    type X is record
      Value : X_Value := A_Value; -- default
    end record;
  end P;

  -- package body left as an exercise for the reader :-) ...

------------------------------------------------------------------------
Internet.Usenet.Put_Signature 
  (Name => "John G. Volan",  Home_Email => "John_Volan@syspac.com",
   Employer => "S.A.I.C.",   Work_Email => "John_Volan@dayton.saic.com",
   Slogan => "Ada95: The World's *FIRST* International-Standard OOPL",
   Disclaimer => "My employer never defined these opinions, so using " &
     "them is totally erroneous...or is that a bounded error now? :-)");
------------------------------------------------------------------------




  reply	other threads:[~1996-09-11  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-11  0:00 Ada 83: Type defaults hehmeyerj
1996-09-11  0:00 ` John G. Volan [this message]
1996-09-11  0:00 ` Thomas Kendelbacher
1996-09-12  0:00 ` Ken Garlington
replies disabled

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