Ada Programming/Attributes/'Value
< Ada Programming < AttributesComputing » Computer Science » Computer Programming » Ada Programming

Description
The 'Value attribute is defined for any scalar type. This attribute is a function that parses the string and returns the corresponding type value, if it exists. Leading and trailing spaces are trimmed.
function S'Value (Arg: String) return S'Base;
If the string does not correspond to any value of the type, then the Constraint_Error exception is raised.
There are corresponding attributes for Wide_String and Wide_Wide_String.
Don't confuse this attribute with the Ada Programming/Attributes/'Val attribute.
Example
type My_Enum is (Enum1, Enum2, Enum3); pragma Assert (My_Enum'Value ("ENUM1") = Enum1); -- OK pragma Assert (My_Enum'Value (" ENUM1 ") = Enum1); -- OK pragma Assert (My_Enum'Value ("ZOWIE!") = Enum1); -- Wrong! Constraint_Error is raised
See also
Wikibook
Ada Reference Manual
- 13.3 Operational and Representation Attributes (Annotated)
- Annex K Language-Defined Attributes (Annotated)
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.