with Ada.Streams; use Ada.Streams;
with Interfaces; use Interfaces;
private with Ada.Finalization;
package Values is
type Value_Type is
(
V_NULL,
V_BOOLEAN,
V_NUMBER,
V_STRING,
V_ID,
V_LIST,
V_ASSOCIATION,
V_ERROR
);
type Value is abstract tagged private;
type Value_Ptr is tagged private;
function Clone( this : access Value ) return Value_Ptr'Class is abstract;
function Compare( this : Value; other : Value'Class ) return Integer is abstract;
function Compare( this : Value'Class; other : access Value'Class ) return Integer;
function Get_Type( this : Value ) return Value_Type is abstract;
function Image( this : Value ) return String is abstract;
function Value_Input( stream : access Root_Stream_Type'Class ) return Value is abstract;
procedure Value_Read( stream : access Root_Stream_Type'Class; obj : out Value ) is abstract;
procedure Value_Write( stream : access Root_Stream_Type'Class; obj : Value ) is abstract;
overriding
function "="( this : Value; other : Value ) return Boolean;
function "<"( this : Value'Class; other : Value'Class ) return Boolean;
function ">"( this : Value'Class; other : Value'Class ) return Boolean;
function "<="( this : Value'Class; other : Value'Class ) return Boolean;
function ">="( this : Value'Class; other : Value'Class ) return Boolean;
function To_Ptr( val : access Value'Class ) return Value_Ptr;
function Clone( this : Value_Ptr'Class ) return Value_Ptr;
function Get( this : Value_Ptr ) return access Value'Class;
pragma Inline( Get );
function Refcount( this : Value_Ptr'Class ) return Natural;
function Image( this : Value_Ptr'Class ) return String;
function Is_Null( this : Value_Ptr'Class ) return Boolean;
function Not_Null( this : Value_Ptr'Class ) return Boolean;
procedure Set( this : in out Value_Ptr; target : access Value'Class );
function Value_Ptr_Input( stream : access Root_Stream_Type'Class ) return Value_Ptr;
procedure Value_Ptr_Output( stream : access Root_Stream_Type'Class; this : Value_Ptr );
function "="( l, r : Value_Ptr ) return Boolean;
function "<"( l, r : Value_Ptr ) return Boolean;
function ">"( l, r : Value_Ptr ) return Boolean;
function "<="( l, r : Value_Ptr ) return Boolean;
function ">="( l, r : Value_Ptr ) return Boolean;
Nul : constant Value_Ptr;
Cast_Exception : exception;
private
use Ada.Finalization;
function "<"( l, r : Value_Type ) return Boolean;
type Value is abstract tagged
record
refs : aliased Integer_32 := 0;
end record;
type A_Naked_Value is access all Value'Class;
procedure Delete( this : in out Value ) is null;
type Value_Ptr is new Ada.Finalization.Controlled with
record
target : A_Naked_Value := null;
end record;
for Value_Ptr'Input use Value_Ptr_Input;
for Value_Ptr'Output use Value_Ptr_Output;
overriding
procedure Adjust( this : in out Value_Ptr );
overriding
procedure Finalize( this : in out Value_Ptr );
procedure Value_Ptr_Read( stream : access Root_Stream_Type'Class; this : out Value_Ptr );
for Value_Ptr'Read use Value_Ptr_Read;
procedure Value_Ptr_Write( stream : access Root_Stream_Type'Class; this : Value_Ptr );
for Value_Ptr'Write use Value_Ptr_Write;
Nul : constant Value_Ptr := (Controlled with target => null);
end Values;