1package body agar.gui.unit is 2 3 package cbinds is 4 function find (key : cs.chars_ptr) return unit_const_access_t; 5 pragma import (c, find, "AG_FindUnit"); 6 7 function best 8 (unit_group : unit_const_access_t; 9 n : c.double) return unit_const_access_t; 10 pragma import (c, best, "AG_BestUnit"); 11 12 function unit_to_base 13 (n : c.double; 14 unit_group : unit_const_access_t) return c.double; 15 pragma import (c, unit_to_base, "agar_unit2base"); 16 17 function base_to_unit 18 (n : c.double; 19 unit_group : unit_const_access_t) return c.double; 20 pragma import (c, base_to_unit, "agar_base2unit"); 21 22 function unit_to_unit 23 (n : c.double; 24 unit_from : unit_const_access_t; 25 unit_to : unit_const_access_t) return c.double; 26 pragma import (c, unit_to_unit, "agar_unit2unit"); 27 end cbinds; 28 29 function find (key : string) return unit_const_access_t is 30 ca_key : aliased c.char_array := c.to_c (key); 31 begin 32 return cbinds.find (cs.to_chars_ptr (ca_key'unchecked_access)); 33 end find; 34 35 function best 36 (unit_group : unit_const_access_t; 37 n : long_float) return unit_const_access_t is 38 begin 39 return cbinds.best (unit_group, c.double (n)); 40 end best; 41 42 function abbreviation (unit : unit_const_access_t) return string is 43 begin 44 return cs.value (abbreviation (unit)); 45 end abbreviation; 46 47 function unit_to_base 48 (n : long_float; 49 unit_group : unit_const_access_t) return long_float 50 is 51 ret : constant c.double := cbinds.unit_to_base (c.double (n), unit_group); 52 begin 53 return long_float (ret); 54 end unit_to_base; 55 56 function base_to_unit 57 (n : long_float; 58 unit_group : unit_const_access_t) return long_float 59 is 60 ret : constant c.double := cbinds.base_to_unit (c.double (n), unit_group); 61 begin 62 return long_float (ret); 63 end base_to_unit; 64 65 function unit_to_unit 66 (n : long_float; 67 unit_from : unit_const_access_t; 68 unit_to : unit_const_access_t) return long_float 69 is 70 ret : constant c.double := cbinds.unit_to_unit (c.double (n), unit_from, unit_to); 71 begin 72 return long_float (ret); 73 end unit_to_unit; 74 75end agar.gui.unit; 76