Index: src/natools-s_expressions-enumeration_io.adb ================================================================== --- src/natools-s_expressions-enumeration_io.adb +++ src/natools-s_expressions-enumeration_io.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2015, Natacha Porté -- +-- Copyright (c) 2015-2019, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -58,9 +58,18 @@ function Value (Data : Atom) return Enum is begin return Enum'Value (To_Image (Data)); end Value; + + function Value (Data : Atom; Default : Enum) return Enum is + Img : constant String := To_Image (Data); + begin + return Enum'Value (Img); + exception + when Constraint_Error => + return Default; + end Value; end Typed_IO; end Natools.S_Expressions.Enumeration_IO; Index: src/natools-s_expressions-enumeration_io.ads ================================================================== --- src/natools-s_expressions-enumeration_io.ads +++ src/natools-s_expressions-enumeration_io.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2015, Natacha Porté -- +-- Copyright (c) 2015-2019, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -38,9 +38,13 @@ function Image (T : Enum) return Atom; -- Convert an enumeration value into an atom function Value (Data : Atom) return Enum; -- Convert an atom into an enumeration value + + function Value (Data : Atom; Default : Enum) return Enum; + -- Convert an atom into an enumeration value, + -- with a default value on invalid atom images end Typed_IO; end Natools.S_Expressions.Enumeration_IO;