1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Ada.Strings.Unbounded;             use Ada.Strings.Unbounded; 
  10. with Interfaces;                        use Interfaces; 
  11.  
  12. package Support is 
  13.  
  14.     function "*"( i : Integer; f : Float ) return Float; 
  15.  
  16.     function "*"( f : Float; i : Integer ) return Float; 
  17.  
  18.     function "/"( i : Integer; f : Float ) return Float; 
  19.  
  20.     function "/"( f : Float; i : Integer ) return Float; 
  21.  
  22.     function "-"( f : Float; i : Integer ) return Float; 
  23.  
  24.     function "-"( i : Integer; f : Float ) return Float; 
  25.  
  26.     function "+"( f : Float; i : Integer ) return Float; 
  27.  
  28.     function "+"( i : Integer; f : Float ) return Float; 
  29.  
  30.     function "**"( l, r : Long_Float ) return Long_Float; 
  31.  
  32.     function Constrain( val, min, max : Float ) return Float; 
  33.  
  34.     function Constrain( val, min, max : Integer ) return Integer; 
  35.  
  36.     function Div_Ceil( a, b : Integer ) return Integer; 
  37.  
  38.     function Floor( x : Float ) return Integer; 
  39.  
  40.     function Max( a, b : Integer ) return Integer; 
  41.  
  42.     function Max( a, b : Float ) return Float; 
  43.  
  44.     function Min( a, b : Integer ) return Integer; 
  45.  
  46.     function Min( a, b : Float ) return Float; 
  47.  
  48.     ---------------------------------------------------------------------------- 
  49.  
  50.     function "&"( l : String; r : Unbounded_String ) return String; 
  51.  
  52.     function "&"( l : Unbounded_String; r : String ) return String; 
  53.  
  54.     -- Capitalizes the words in the string using a set of delimiters. 
  55.     function Capitalize( str : String ) return String; 
  56.     pragma Postcondition( Capitalize'Result'Length = str'Length ); 
  57.  
  58.     -- Compares two strings; case insensitive. 
  59.     function Case_Eq( l, r : String ) return Boolean; 
  60.  
  61.     -- Compares two strings; case insensitive. 
  62.     function Case_Eq( l, r : Unbounded_String ) return Boolean; 
  63.  
  64.     -- Compares two strings; case insensitive. 
  65.     function Case_Eq( l : Unbounded_String; r : String ) return Boolean; 
  66.  
  67.     -- Compares two strings; case insensitive. 
  68.     function Case_Eq( l : String; r : Unbounded_String ) return Boolean; 
  69.  
  70.     -- Returns True if 'str' ends with 'ending'. Comparison is case sensitive. 
  71.     function Ends_With( str : String; ending : String ) return Boolean; 
  72.  
  73.     -- Iterate over words in a string separated by whitespace. 
  74.     procedure Iterate_Words( phrase  : String; 
  75.                              examine : access procedure( word : String ) ); 
  76.  
  77.     -- Replaces all 'from' characters in a string with 'to' characters. 
  78.     function Replace( str : String; from, to : Character ) return String; 
  79.  
  80.     ---------------------------------------------------------------------------- 
  81.  
  82.     -- Returns -1 if the file does not exist. 
  83.     function File_Length( path : String ) return Long_Integer; 
  84.     pragma Postcondition( File_Length'Result >= -1 ); 
  85.  
  86.     ---------------------------------------------------------------------------- 
  87.  
  88.     -- Extracts a readable Ada unit name from a source reference line. If the 
  89.     -- source reference doesn't contain symbols then an empty string will be 
  90.     -- returned because the unit name can't be determined. 
  91.     function Source_Ref_To_Unit_Name( ref : String ) return String; 
  92.  
  93.     ---------------------------------------------------------------------------- 
  94.  
  95.     -- Returns True if rectangle A contains point B. 
  96.     function Contains( ax1, ay1, ax2, ay2, bx, by : Integer ) return Boolean; 
  97.  
  98.     -- Returns the value of 'point' as it would be snapped to a grid of size 
  99.     -- 'gridSize'. If 'centered' is True, the snap will occur in the middle of 
  100.     -- the grid lines instead of on them. 
  101.     function Grid_Snap( point    : Integer; 
  102.                         gridSize : Positive; 
  103.                         centered : Boolean := False ) return Integer; 
  104.  
  105.     -- Returns True if rectangles A and B intersect. 
  106.     function Intersect( ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 : Integer ) return Boolean; 
  107.  
  108.     ---------------------------------------------------------------------------- 
  109.  
  110.     -- Returns a string representation of 'i' without whitespace. 
  111.     function Image( i : Integer ) return String; 
  112.     pragma Postcondition( Image'Result'Length > 0 ); 
  113.  
  114.     -- Returns a string representation of 'u' without whitespace. 
  115.     function Image( u : Unsigned_32 ) return String; 
  116.     pragma Postcondition( Image'Result'Length > 0 ); 
  117.  
  118.     -- Returns a string representation of 'u' without whitespace. 
  119.     function Image( u : Unsigned_64 ) return String; 
  120.     pragma Postcondition( Image'Result'Length > 0 ); 
  121.  
  122.     -- Returns a string image of a floating point number, where 'precision' is 
  123.     -- the number of places after the decimal to render. 
  124.     function Image( f : Float; precision : Natural := 3 ) return String; 
  125.     pragma Postcondition( Image'Result'Length > 0 ); 
  126.  
  127.     ---------------------------------------------------------------------------- 
  128.  
  129.     -- Returns a random unsigned 32-bit number. 
  130.     function Random_32 return Unsigned_32; 
  131.  
  132. private 
  133.  
  134.     -- A package for functions with OS-specific implementations 
  135.     package OS is 
  136.  
  137.         -- Returns the path of the directory where system-wide 
  138.         -- application-specific data files can be read and written. 
  139.         function App_Data_Directory return String; 
  140.  
  141.         -- Returns the file extension for executable files, not including a dot. 
  142.         function Executable_Extension return String; 
  143.  
  144.         -- Returns the path of the application's executable file. If the executable is 
  145.         -- in an app bundle on OS X, the bundle's Resources directory will be returned. 
  146.         function Executable_Path return String; 
  147.  
  148.         -- Returns the directory containing the executable file, or, if the executable is 
  149.         -- running on OS X inside an .app bundle, the bundle's Resources directory. 
  150.         function Execution_Directory return String; 
  151.  
  152.         -- Returns the path of the user's home directory. 
  153.         function Home_Directory return String; 
  154.  
  155.         -- Opens 'path' in the OS GUI and selects it if it points to an 
  156.         -- existing file. Nothing happens if the directory of 'path' does not 
  157.         -- exist. 
  158.         procedure Reveal_Path( path : String ); 
  159.  
  160.         -- Returns the directory for system fonts on the local machine. 
  161.         function System_Font_Directory return String; 
  162.  
  163.         -- Returns the current platform's temporary directory. 
  164.         function Temp_Directory return String; 
  165.  
  166.     end OS; 
  167.  
  168.     pragma Import( C, "**", "pow" ); 
  169.  
  170. end Support;