agpl_1.0.0_b5da3320/src/agpl-chronos.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
with Agpl.Calendar.Format;
with Agpl.Trace; use Agpl.Trace;

package body Agpl.Chronos is

   use type Ada.Calendar.Time;

   ------------------------------------------------------------------------
   -- Reset                                                              --
   ------------------------------------------------------------------------
   procedure Reset (This : in out Object; Elapsed : Duration := 0.0) is
   begin
      This.Start := Ada.Calendar.Clock - Elapsed;
   end Reset;

   function Reset (Elapsed : Duration) return Object is
   begin
      return This : Object do
         This.Reset (Elapsed);
      end return;
   end Reset;

   ------------------------------------------------------------------------
   -- Elapsed                                                            --
   ------------------------------------------------------------------------
   function Elapsed (This : in Object) return Duration is
   begin
      return Ada.Calendar.Clock - This.Start;
   exception
      when E : others =>
         Log ("Chronos: " & Report (E), Error);
         Log ("Chronos: Why???", Error);
         raise;
         return -1.0; -- Something very strange is a-happening...
                      --  Everytime this has happened, a pointer had gone awry.
                      --  The error was totally unrelated to Chronos.
   end Elapsed;

   ------------------------------------------------------------------------
   -- Image                                                              --
   ------------------------------------------------------------------------
   function Image (This : in Object) return String is
   begin
      return Agpl.Calendar.Format.Image (Elapsed (This));
   end Image;

   -----------
   -- Clock --
   -----------

   function Clock return Object is
   begin
      return (Start => Ada.Calendar.Clock);
   end Clock;

   -----------
   -- Epoch --
   -----------

   function Epoch return Object is
      use Ada.Calendar;
   begin
      return (Start =>
                Time_Of
                  (Year_Number'First,
                   Month_Number'First,
                   Day_Number'First));
   end Epoch;

   -----------
   -- Value --
   -----------

   function Value (This : in Object) return Ada.Calendar.Time is
   begin
      return This.Start;
   end Value;

end Agpl.Chronos;