Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: limited typ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 26 Topic 4222 of 5857
Post > Topic >>

Re: limited types (Was: Records that could be arrays)

by Matthew Heaney <matthewjheaney@[EMAIL PROTECTED] > Feb 25, 2006 at 02:21 AM

"Randy Brukardt" <randy@[EMAIL PROTECTED]
> writes:

> Of course, you often do need assignment. The containers are non-limited
so
> that they can be composed. And that's because it doesn't make sense to
have
> limited elements (as the elements have to be copied into the container).

On that subject, we recently had need of a bounded list (for restricted
runtimes, sans dynamic memory allocation), something like:

generic
  type ET is private;
  with "=" (L, R : ET) return Boolean is <>;

package Ada.Containers.Bounded_Lists is
  type List (Capacity : Count_Type) is tagged limited private;
  ... -- more or less same as Doubly_Linked_Lists
end;

That brings up the composability issue, since you'd like to be able to
create a
container whose elements are bounded lists.  I came up with something
like:

generic
  type ET is limited private;

package Ada.Containers.Limited_Bounded_Lists is
  type List (Capacity : Count_Type) is tagged limited private;

  function Element
    (Container : not null access List;
     Position  : Cursor)
    return not null access ET;

  function Constant_Element
    (Container : not null access constant List;
     Position  : Cursor)
    return not null access constant ET;

  function First_Element
    (Container : not null access List)
    return not null access ET;

  function Constant_First_Element
    (Container : not null access constant List)
    return not null access constant ET;

....
end;

Query_Element and Update_Element are still there, but it's awfully nice to
be
able to rename an element directly.  You can do something like:

procedure Op (L : in out List) is
begin
  L.Append (Initialize'Access);  -- init elem
  -- or: L.Append;               -- no init necessary
  -- or: L.Insert (Before => No_Element, Process => Initialize'Access);
  -- or: L.Insert (Before => No_Element);

  declare
    E : ET renames L.Last_Element;  -- implicit 'Access
  begin
    ... -- use E
  end;
end Op;


The only potential issue is that if you rename an active element, it can
subsequently become inactive (if you Delete it) in the scope of the
renaming.
If you were to subsequently manipulate it that would probably be bad, but
at
least the object doesn't disappear as it would in the unbounded case,
since the
object just moves onto an internal free list owned by the list.

Don't know if that's the right thing to do, though.  I haven't done
anything
with it yet so maybe I'll just get rid of those ops.  It's just that in
the
case of a limited element, it's OK to declare the element as aliased,
since
there's no issue (I think) about constraining an element object whose type
is a
discriminated record with default discriminant.

It was nice to be able to bounce ideas off of the ARG subcommittee.  We
ought
to set up a mailing list or something to discuss post-Ada 2005 container
issues.  We might be able to reuse the old mailing list at yahoo if it's
still
around.

-Matt
 




 26 Posts in Topic:
limited types (Was: Records that could be arrays)
Thierry Bernier <email  2006-02-24 16:51:03 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-24 15:57:46 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 02:21:13 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 03:38:59 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-25 12:06:20 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 15:05:02 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-25 19:01:06 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 10:00:07 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 18:20:39 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 21:52:32 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 22:07:00 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 10:11:28 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 15:34:58 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 17:05:47 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 08:52:23 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 21:21:08 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 22:40:18 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:38:31 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 15:00:29 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:39:20 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 09:24:35 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 20:06:50 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 11:58:11 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 22:03:37 
Re: limited types
Simon Wright <simon@[E  2006-02-28 21:51:52 
Re: limited types
Matthew Heaney <matthe  2006-03-01 01:59:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 4:29:55 CDT 2008.