--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Interfaces; use Interfaces;
package Support is
function "*"( i : Integer; f : Float ) return Float;
function "*"( f : Float; i : Integer ) return Float;
function "/"( i : Integer; f : Float ) return Float;
function "/"( f : Float; i : Integer ) return Float;
function "-"( f : Float; i : Integer ) return Float;
function "-"( i : Integer; f : Float ) return Float;
function "+"( f : Float; i : Integer ) return Float;
function "+"( i : Integer; f : Float ) return Float;
function "**"( l, r : Long_Float ) return Long_Float;
function Constrain( val, min, max : Float ) return Float;
function Constrain( val, min, max : Integer ) return Integer;
function Div_Ceil( a, b : Integer ) return Integer;
function Floor( x : Float ) return Integer;
function Max( a, b : Integer ) return Integer;
function Max( a, b : Float ) return Float;
function Min( a, b : Integer ) return Integer;
function Min( a, b : Float ) return Float;
----------------------------------------------------------------------------
function "&"( l : String; r : Unbounded_String ) return String;
function "&"( l : Unbounded_String; r : String ) return String;
-- Capitalizes the words in the string using a set of delimiters.
function Capitalize( str : String ) return String;
pragma Postcondition( Capitalize'Result'Length = str'Length );
-- Compares two strings; case insensitive.
function Case_Eq( l, r : String ) return Boolean;
-- Compares two strings; case insensitive.
function Case_Eq( l, r : Unbounded_String ) return Boolean;
-- Compares two strings; case insensitive.
function Case_Eq( l : Unbounded_String; r : String ) return Boolean;
-- Compares two strings; case insensitive.
function Case_Eq( l : String; r : Unbounded_String ) return Boolean;
-- Returns True if 'str' ends with 'ending'. Comparison is case sensitive.
function Ends_With( str : String; ending : String ) return Boolean;
-- Iterate over words in a string separated by whitespace.
procedure Iterate_Words( phrase : String;
examine : access procedure( word : String ) );
-- Replaces all 'from' characters in a string with 'to' characters.
function Replace( str : String; from, to : Character ) return String;
----------------------------------------------------------------------------
-- Returns -1 if the file does not exist.
function File_Length( path : String ) return Long_Integer;
pragma Postcondition( File_Length'Result >= -1 );
----------------------------------------------------------------------------
-- Extracts a readable Ada unit name from a source reference line. If the
-- source reference doesn't contain symbols then an empty string will be
-- returned because the unit name can't be determined.
function Source_Ref_To_Unit_Name( ref : String ) return String;
----------------------------------------------------------------------------
-- Returns True if rectangle A contains point B.
function Contains( ax1, ay1, ax2, ay2, bx, by : Integer ) return Boolean;
-- Returns the value of 'point' as it would be snapped to a grid of size
-- 'gridSize'. If 'centered' is True, the snap will occur in the middle of
-- the grid lines instead of on them.
function Grid_Snap( point : Integer;
gridSize : Positive;
centered : Boolean := False ) return Integer;
-- Returns True if rectangles A and B intersect.
function Intersect( ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 : Integer ) return Boolean;
----------------------------------------------------------------------------
-- Returns a string representation of 'i' without whitespace.
function Image( i : Integer ) return String;
pragma Postcondition( Image'Result'Length > 0 );
-- Returns a string representation of 'u' without whitespace.
function Image( u : Unsigned_32 ) return String;
pragma Postcondition( Image'Result'Length > 0 );
-- Returns a string representation of 'u' without whitespace.
function Image( u : Unsigned_64 ) return String;
pragma Postcondition( Image'Result'Length > 0 );
-- Returns a string image of a floating point number, where 'precision' is
-- the number of places after the decimal to render.
function Image( f : Float; precision : Natural := 3 ) return String;
pragma Postcondition( Image'Result'Length > 0 );
----------------------------------------------------------------------------
-- Returns a random unsigned 32-bit number.
function Random_32 return Unsigned_32;
private
-- A package for functions with OS-specific implementations
package OS is
-- Returns the path of the directory where system-wide
-- application-specific data files can be read and written.
function App_Data_Directory return String;
-- Returns the file extension for executable files, not including a dot.
function Executable_Extension return String;
-- Returns the path of the application's executable file. If the executable is
-- in an app bundle on OS X, the bundle's Resources directory will be returned.
function Executable_Path return String;
-- Returns the directory containing the executable file, or, if the executable is
-- running on OS X inside an .app bundle, the bundle's Resources directory.
function Execution_Directory return String;
-- Returns the path of the user's home directory.
function Home_Directory return String;
-- Opens 'path' in the OS GUI and selects it if it points to an
-- existing file. Nothing happens if the directory of 'path' does not
-- exist.
procedure Reveal_Path( path : String );
-- Returns the directory for system fonts on the local machine.
function System_Font_Directory return String;
-- Returns the current platform's temporary directory.
function Temp_Directory return String;
end OS;
pragma Import( C, "**", "pow" );
end Support;