* Сreate attributes.
@ 2018-12-22 5:37 eduardsapotski
2018-12-22 19:13 ` Brad Moore
0 siblings, 1 reply; 4+ messages in thread
From: eduardsapotski @ 2018-12-22 5:37 UTC (permalink / raw)
Sorry for the stupid question...
For example. I have type:
type Person is record
First_Name : Unbounded_String := Null_Unbounded_String;
Last_Name : Unbounded_String := Null_Unbounded_String;
end record;
There is a list:
package People_Package is new Ada.Containers.Vectors(Natural, Person);
People : People_Package.Vector;
Next, I want to display this list with headers:
----------------------------
| NAME | SURNAME |
----------------------------
| John | Smith |
| Ada | Lovelace |
...
----------------------------
Can I use attributes to display headers?
For example something like this:
People'First_Name_Header
How can this be implemented?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Сreate attributes.
2018-12-22 5:37 Сreate attributes eduardsapotski
@ 2018-12-22 19:13 ` Brad Moore
2018-12-28 9:26 ` eduardsapotski
0 siblings, 1 reply; 4+ messages in thread
From: Brad Moore @ 2018-12-22 19:13 UTC (permalink / raw)
On Friday, December 21, 2018 at 10:37:14 PM UTC-7, eduards...@gmail.com wrote:
> Sorry for the stupid question...
>
> For example. I have type:
>
> type Person is record
> First_Name : Unbounded_String := Null_Unbounded_String;
> Last_Name : Unbounded_String := Null_Unbounded_String;
> end record;
>
> There is a list:
>
> package People_Package is new Ada.Containers.Vectors(Natural, Person);
> People : People_Package.Vector;
>
> Next, I want to display this list with headers:
>
> ----------------------------
> | NAME | SURNAME |
> ----------------------------
> | John | Smith |
> | Ada | Lovelace |
> ...
> ----------------------------
>
> Can I use attributes to display headers?
> For example something like this:
>
> People'First_Name_Header
>
>
> How can this be implemented?
You could use a class-wide type or a type with discriminants such as;
type Person_Attribute_Kinds is (Name, Surname);
type Person_Attribute (Attribute_Name : Person_Attribute_Kinds
:= Person_Attribute_Kinds'First) is
record
case Attribute_Name is
when Name | Surname =>
Name_String : Unbounded_String := Null_Unbounded_String;
end case;
end record;
type Person is
record
First_Name : Person_Attribute(Name);
Last_Name : Person_Attribute(Surname);
end record;
X : Person;
begin
Put_Line ("| " & X.First_Name.Attribute_Name'Image &
" | " & X.Last_Name.Attribute_Name'Image & " |");
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Сreate attributes.
2018-12-22 19:13 ` Brad Moore
@ 2018-12-28 9:26 ` eduardsapotski
2019-01-01 18:47 ` Brad Moore
0 siblings, 1 reply; 4+ messages in thread
From: eduardsapotski @ 2018-12-28 9:26 UTC (permalink / raw)
Thank!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Сreate attributes.
2018-12-28 9:26 ` eduardsapotski
@ 2019-01-01 18:47 ` Brad Moore
0 siblings, 0 replies; 4+ messages in thread
From: Brad Moore @ 2019-01-01 18:47 UTC (permalink / raw)
On Friday, December 28, 2018 at 2:26:04 AM UTC-7, eduards...@gmail.com wrote:
> Thank!
You're welcome!
I think a slight improvement would be to make the Person_Attribute type non-mutable (i.e. remove the ":= Person_Attribute_Kinds'First" on the Attribute_Name discriminant), since I presume you'd want to constrain the First_Name component of the Person type to always be a Name, and constrain the Last_Name component to always be a Surname. In other words, you dont want to allow someone to assign a Surname to the First_Name, or a First_Name value to the Last_Name.
Brad
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-01-01 18:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-22 5:37 Сreate attributes eduardsapotski
2018-12-22 19:13 ` Brad Moore
2018-12-28 9:26 ` eduardsapotski
2019-01-01 18:47 ` Brad Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox