1. with Ada.Streams;                       use Ada.Streams; 
  2. with Objects;                           use Objects; 
  3.  
  4. private with Ada.Strings.Unbounded; 
  5.  
  6. package Values is 
  7.  
  8.     type Value is abstract new Object with private; 
  9.     type A_Value is access all Value'Class; 
  10.  
  11.     function Create_Value( val : Boolean ) return A_Value; 
  12.     pragma Postcondition( Create_Value'Result /= null ); 
  13.  
  14.     function Create_Value( val : Integer ) return A_Value; 
  15.     pragma Postcondition( Create_Value'Result /= null ); 
  16.  
  17.     function Create_Value( val : String ) return A_Value; 
  18.     pragma Postcondition( Create_Value'Result /= null ); 
  19.  
  20.     -- Raises INVALID_CONVERSION if the value can't be converted to a boolean. 
  21.     function As_Boolean( this : access Value ) return Boolean; 
  22.  
  23.     -- Raises INVALID_CONVERSION if the value can't be converted to an integer. 
  24.     function As_Integer( this : access Value ) return Integer; 
  25.  
  26.     -- Raises INVALID_CONVERSION if the value can't be converted to a string. 
  27.     function As_String( this : access Value ) return String; 
  28.  
  29.     function Object_Input( stream : access Root_Stream_Type'Class ) return Value is abstract; 
  30.  
  31.     function Copy( src : A_Value ) return A_Value; 
  32.     pragma Postcondition( Copy'Result /= src or else src = null ); 
  33.  
  34.     procedure Delete( this : in out A_Value ); 
  35.     pragma Postcondition( this = null ); 
  36.  
  37.     ---------------------------------------------------------------------------- 
  38.  
  39.     VALUE_NOT_FOUND, 
  40.     INVALID_CONVERSION : exception; 
  41.  
  42. private 
  43.  
  44.     use Ada.Strings.Unbounded; 
  45.  
  46.     type Value is abstract new Object with null record; 
  47.  
  48.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Value ); 
  49.     for Value'Read use Object_Read; 
  50.  
  51.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Value ); 
  52.     for Value'Write use Object_Write; 
  53.  
  54.     function A_Value_Input( stream : access Root_Stream_Type'Class ) return A_Value; 
  55.     for A_Value'Input use A_Value_Input; 
  56.  
  57.     procedure A_Value_Output( stream : access Root_Stream_Type'Class; obj : A_Value ); 
  58.     for A_Value'Output use A_Value_Output; 
  59.  
  60.     procedure A_Value_Read( stream : access Root_Stream_Type'Class; obj : out A_Value ); 
  61.     for A_Value'Read use A_Value_Read; 
  62.  
  63.     procedure A_Value_Write( stream : access Root_Stream_Type'Class; obj : A_Value ); 
  64.     for A_Value'Write use A_Value_Write; 
  65.  
  66.     ---------------------------------------------------------------------------- 
  67.  
  68.     type Val_Bool is new Value with 
  69.         record 
  70.             bool : Boolean; 
  71.         end record; 
  72.  
  73.     function As_Boolean( this : access Val_Bool ) return Boolean; 
  74.  
  75.     function As_Integer( this : access Val_Bool ) return Integer; 
  76.  
  77.     function As_String( this : access Val_Bool ) return String; 
  78.  
  79.     function Object_Input( stream : access Root_Stream_Type'Class ) return Val_Bool; 
  80.     for Val_Bool'Input use Object_Input; 
  81.  
  82.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Val_Bool ); 
  83.     for Val_Bool'Read use Object_Read; 
  84.  
  85.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Val_Bool ); 
  86.     for Val_Bool'Write use Object_Write; 
  87.  
  88.     ---------------------------------------------------------------------------- 
  89.  
  90.     type Val_Int is new Value with 
  91.         record 
  92.             int : Integer; 
  93.         end record; 
  94.  
  95.     function As_Boolean( this : access Val_Int ) return Boolean; 
  96.  
  97.     function As_Integer( this : access Val_Int ) return Integer; 
  98.  
  99.     function As_String( this : access Val_Int ) return String; 
  100.  
  101.     function Object_Input( stream : access Root_Stream_Type'Class ) return Val_Int; 
  102.     for Val_Int'Input use Object_Input; 
  103.  
  104.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Val_Int ); 
  105.     for Val_Int'Read use Object_Read; 
  106.  
  107.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Val_Int ); 
  108.     for Val_Int'Write use Object_Write; 
  109.  
  110.     ---------------------------------------------------------------------------- 
  111.  
  112.     type Val_String is new Value with 
  113.         record 
  114.             str : Unbounded_String; 
  115.         end record; 
  116.  
  117.     procedure Adjust( this : access Val_String ); 
  118.  
  119.     function As_String( this : access Val_String ) return String; 
  120.  
  121.     function Object_Input( stream : access Root_Stream_Type'Class ) return Val_String; 
  122.     for Val_String'Input use Object_Input; 
  123.  
  124.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Val_String ); 
  125.     for Val_String'Read use Object_Read; 
  126.  
  127.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Val_String ); 
  128.     for Val_String'Write use Object_Write; 
  129.  
  130. end Values;