File: CallbackManager.cc

package info (click to toggle)
madlib 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,196 kB
  • sloc: cpp: 39,851; sh: 10,041; makefile: 473
file content (100 lines) | stat: -rw-r--r-- 3,124 bytes parent folder | download | duplicates (6)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Gaetan Compere, Jean-Francois Remacle
// -------------------------------------------------------------------

#include "CallbackManager.h"

using std::list;

namespace MAd {

  // -------------------------------------------------------------------
  void CallBackManager::initialize()
  {
  }

  // -------------------------------------------------------------------
  void CallBackManager::finalize()
  {
    CB.clear();
    CBMove.clear();
  }

  // -------------------------------------------------------------------
  void CallBackManager::registerCallBack(CBFunction CBFct, 
                                         void* userData)
  {
    CBStructure cb;
    cb.function = CBFct;
    cb.data = userData;
    CB.push_back(cb);
  }

  // -------------------------------------------------------------------
  void CallBackManager::registerCallBackMove(CBFunc_move CB_move, 
                                             void* userData_move)
  {
    CBStructureMove cbm;
    cbm.function = CB_move;
    cbm.data = userData_move;
    CBMove.push_back(cbm);
  }

  // -------------------------------------------------------------------
  void CallBackManager::unregisterCallBack(CBFunction CBFct, 
                                           void* userData)
  {
    CBStructure cb;
    cb.function = CBFct;
    cb.data = userData;
    CB.remove(cb);
  }

  // -------------------------------------------------------------------
  void CallBackManager::unregisterCallBackMove(CBFunc_move CB_move, 
                                               void* userData_move)
  {
    CBStructureMove cbm;
    cbm.function = CB_move;
    cbm.data = userData_move;
    CBMove.remove(cbm);
  }

  // -------------------------------------------------------------------
  void CallBackManager::callCallBacks(pPList before, pPList after,
                                      operationType type , pEntity ppp)
  {
    list<CBStructure>::const_iterator cbIter = CB.begin();
    list<CBStructure>::const_iterator cbLast = CB.end();

    for (; cbIter != cbLast; cbIter++) {
      CBFunction f = (*cbIter).function;
      void * userData = (*cbIter).data;
      f(before,after,userData,type,ppp);
    }
  }

  // -------------------------------------------------------------------
  void CallBackManager::callCallBackMoves(pVertex pv, double * xyz)
  {
    list<CBStructureMove>::const_iterator cbIterM = CBMove.begin();
    list<CBStructureMove>::const_iterator cbLastM = CBMove.end();

    for (; cbIterM != cbLastM; cbIterM++) {
      CBFunc_move fM = (*cbIterM).function;
      void * userDataM = (*cbIterM).data;
      fM(pv,xyz,userDataM);
    }
  }

  // -------------------------------------------------------------------

}