aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/ScheduleWrapper.cc
blob: 624dacbf9c4dac66977e00a382ca774b9c41adc2 (plain)
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
#include <cassert>
#include <list>

#include <cctk.h>
#include <cctk_Arguments.h>

#include <carpet.hh>



namespace Carpet {
  
  using namespace std;
  
  
  
  typedef CCTK_INT (* func) (CCTK_POINTER_TO_CONST cctkGH,
                             CCTK_POINTER          function,
                             CCTK_POINTER          attribute,
                             CCTK_POINTER          data);
  typedef list <func> flist;
  
  static flist func_befores, func_afters;
  
  
  
  extern "C"
  CCTK_INT
  Carpet_RegisterScheduleWrapper (func const func_before,
                                  func const func_after)
  {
    // Add functions
    if (func_before) func_befores.push_back  (func_before);
    if (func_after ) func_afters .push_front (func_after );
    return 0;
  }
  
  extern "C"
  CCTK_INT
  Carpet_UnRegisterScheduleWrapper (func const func_before,
                                    func const func_after)
  {
    // Remove functions
    if (func_before) func_befores.remove (func_before);
    if (func_after ) func_afters .remove (func_after );
    return 0;
  }
  
  
  
  void
  CallBeforeRoutines (cGH const * const cctkGH,
                      void * const function,
                      cFunctionData * const attribute,
                      void * const data)
  {
    for (flist::const_iterator
           fli = func_befores.begin(); fli != func_befores.end(); ++ fli)
    {
      (* fli) (cctkGH, function, attribute, data);
    }
  }
  
  void
  CallAfterRoutines (cGH const * const cctkGH,
                     void * const function,
                     cFunctionData * const attribute,
                     void * const data)
  {
    for (flist::const_iterator
           fli = func_afters.begin(); fli != func_afters.end(); ++ fli)
    {
      (* fli) (cctkGH, function, attribute, data);
    }
  }
  
} // namespace Carpet