comp.lang.ada
 help / color / mirror / Atom feed
* Re: Tagged Types
@ 2004-09-13  4:08 David C. Hoos
  0 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos @ 2004-09-13  4:08 UTC (permalink / raw)
  To: comp.lang.ada

Zero-based strings are _not_ legal, because the declaration
of String allows only _Positive_ array indices.

Other array types can be declared allowing other
types for the array indices -- in fact, any
_discrete_ type can be so used.


"Patrice Freydiere" <frett27@free.fr> wrote in message 
news:pan.2004.09.12.19.29.12.644532@free.fr...
>> --- Patrice Freydiere <frett27@free.fr> wrote:
>> > Jeff, I pointed out the problem ..
>> > i was converting a stream_element_array in a string,
>> > using the
>> > stream_element_array bounds ... the array was
>> > starting at 0. So at runtime,
>> > an index out of bounds was raised because strings
>> > starting to 0 are not
>> > allowed...
>> >
>> > i can't get a stream_element_array formal
>> > description to check if zero base
>> > array is valid ??
>>
>> I don't understand what you mean by this. Why can you
>> not get the formal description for this. You are using
>> GNAT? it is in a-stream.ads
>>
>> Yes it is legal to start at 0 (or even negative
>> values).
>>
>> Can you post (either here or comp.lang.ada) just the
>> snippet of code from the declare block that you are
>> talking about or is it too proprietary.
>>
>>
>
> Here is the involve code :
>
>                  begin
>                     Ais.Log.Log("Image retreived - " &
> Image.Get_Name(Im.all));
>                     if Im=null then
>                        Ais.Log.Log("null address  ");
>                     end if;
>                     declare
>                        Ba : Ada.Streams.Stream_Element_Array
>                            := Ais.image.Create_Thumbnail(ic);
>                     begin
>                        declare
>                           S : String( 1 .. Natural(Ba'Length) );
> --&&&&&&&&&&&&& when i used a 0 based string, it hang with a (null): Bad
> address
> -- &&&&&&&&&&&&&& with a 1 based string, OK
> -- &&&&&&&&&&&&&& with using Get_Content for retrieving the
> Stream_Element_Array, it 's OK  ?????
>                        begin
>                           for J in Ba'Range loop
>                             S(Integer(J-Ba'first)+S'first) :=
>
> Character'Val(Ada.Streams.Stream_Element'pos(Ba(J)));
>                              null;
>                           end loop;
>                           As(I) :=
>
> Client.Base64_Data(To_String(AIS.Image.Get_Name(Im.all)),
> 
> Aws.Translator.Base64_Encode(
> S ));
>                        end;
>
>
> tell me if you wanna have more code,
> or you can get the entier code from imgsvr.org cvs repository
>
> Cheers,
> Patrice
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: Tagged Types
@ 2004-09-12 19:29 Patrice Freydiere
  0 siblings, 0 replies; 5+ messages in thread
From: Patrice Freydiere @ 2004-09-12 19:29 UTC (permalink / raw)


> --- Patrice Freydiere <frett27@free.fr> wrote:
> > Jeff, I pointed out the problem ..
> > i was converting a stream_element_array in a string,
> > using the
> > stream_element_array bounds ... the array was
> > starting at 0. So at runtime,
> > an index out of bounds was raised because strings
> > starting to 0 are not
> > allowed...
> >
> > i can't get a stream_element_array formal
> > description to check if zero base
> > array is valid ??
>
> I don't understand what you mean by this. Why can you
> not get the formal description for this. You are using
> GNAT? it is in a-stream.ads
>
> Yes it is legal to start at 0 (or even negative
> values).
>
> Can you post (either here or comp.lang.ada) just the
> snippet of code from the declare block that you are
> talking about or is it too proprietary.
>
>

Here is the involve code :

                  begin
                     Ais.Log.Log("Image retreived - " & 
Image.Get_Name(Im.all));
                     if Im=null then
                        Ais.Log.Log("null address  ");
                     end if;
                     declare
                        Ba : Ada.Streams.Stream_Element_Array
                            := Ais.image.Create_Thumbnail(ic); 
                     begin
                        declare
                           S : String( 1 .. Natural(Ba'Length) );  
--&&&&&&&&&&&&& when i used a 0 based string, it hang with a (null): Bad 
address
-- &&&&&&&&&&&&&& with a 1 based string, OK
-- &&&&&&&&&&&&&& with using Get_Content for retrieving the 
Stream_Element_Array, it 's OK  ?????
                        begin
                           for J in Ba'Range loop
                             S(Integer(J-Ba'first)+S'first) :=
                                
Character'Val(Ada.Streams.Stream_Element'pos(Ba(J)));
                              null;
                           end loop;
                           As(I) :=
                             
Client.Base64_Data(To_String(AIS.Image.Get_Name(Im.all)),
                                                Aws.Translator.Base64_Encode( 
S ));
                        end;


tell me if you wanna have more code, 
or you can get the entier code from imgsvr.org cvs repository

Cheers, 
Patrice 




^ permalink raw reply	[flat|nested] 5+ messages in thread
* tagged types
@ 2002-05-30 15:30 Sami Evangelista
  2002-05-30 19:11 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Sami Evangelista @ 2002-05-30 15:30 UTC (permalink / raw)


i have declared an abstract type with two derived types like this

type father is null record;
type son1 is new father with record
	son1_field : integer;
end record;
type son2 is new father with record
	son2_field : boolean;
end record;
type access_son1 is access son1;
type access_son2 is access son2;

then i introduced a list of these elements and a procedure to add an 
element to the list like this:

type access_father_class is access all father'class;
type list;
type access_list is access list;
type list is record
	element : access_father_class;
	next : access_list;
end record;

procedure add(The_list : in out access_list;
               The_Element : access_father_class) is
begin
       if The_list = null then
          The_list := new list;
          The_list.element := The_Element;
          The_list.next := null;
       else
          add(The_list.next, The_element);
       end if;
end

until there no problem. but how is it possible to add a son1 object to a 
list. I have tried this:

my_object : access_son1 := new son1;
my_object.son1.field := 0;
my_list : access_list;
...
add(my_list, my_object);

and it gives me the following error message:

expected type "access_father"
found type "access_son"

Thanks for any help

Sami Evangelista




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-09-13  4:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13  4:08 Tagged Types David C. Hoos
  -- strict thread matches above, loose matches on Subject: below --
2004-09-12 19:29 Patrice Freydiere
2002-05-30 15:30 tagged types Sami Evangelista
2002-05-30 19:11 ` Stephen Leake
2002-05-31 13:13   ` Stephen Leake

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