rxada_0.1.0_6ff779c7/src/body/rx-op-print.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
with Ada.Calendar.Formatting;

with Gnat.IO;

with Rx.Schedulers;

package body Rx.Op.Print is

   use Ada.Calendar;

   function Stamp return String is
      (Formatting.Image (Clock, Include_Time_Fraction => True) & ": ");

   type Op (Func : Operate.Typed.Actions.Func1Str) is new Operate.Operator with record
      With_Timestamp : Boolean := True;
   end record;

   overriding procedure On_Next (This : in out Op; V : Operate.T) is
      use Gnat.IO;
      use Operate.Typed.Actions;
   begin
      if This.Func /= null then
         Put_Line ((if This.With_Timestamp then Stamp else "") & This.Func (V));
      else
         Put_Line ((if This.With_Timestamp then Stamp else "") & Rx.Schedulers.Current_Thread_Id); -- Mmm
      end if;
      This.Get_Observer.On_Next (V);
   end On_Next;

   ------------
   -- Create --
   ------------

   function Create (Func : Operate.Typed.Actions.Func1Str := null; With_Timestamp : Boolean := True) return Operate.Operator'Class is
   begin
      return Op'(Operate.Operator
                             with Func => Func, With_Timestamp => With_Timestamp);
   end Create;

end Rx.Op.Print;