Callback.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "Callback.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class CallbackType>
35 :
36  cbr_(cbr)
37 {
38  checkIn();
39 }
40 
41 
42 template<class CallbackType>
44 :
45  cbr_(cb.cbr_)
46 {
47  checkIn();
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
52 
53 template<class CallbackType>
55 {
56  checkOut();
57 }
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
62 template<class CallbackType>
64 {
66  {
67  cbr_.append(static_cast<CallbackType*>(this));
68  return true;
69  }
70 
71  return false;
72 }
73 
74 
75 template<class CallbackType>
77 {
79  {
80  CallbackType* ptr = cbr_.remove(static_cast<CallbackType*>(this));
81 
82  return ptr;
83  }
84 
85  return false;
86 }
87 
88 
89 // ************************************************************************* //
Foam::CallbackRegistry
Base class with which callbacks are registered.
Definition: CallbackRegistry.H:68
Foam::Callback::~Callback
virtual ~Callback()
Destructor.
Definition: Callback.C:54
Foam::Callback::checkIn
bool checkIn()
Register Callback with CallbackRegistry.
Definition: Callback.C:63
Callback.H
Foam::Callback::Callback
Callback(CallbackRegistry< CallbackType > &)
Construct and register with CallbackRegistry.
Definition: Callback.C:34
Foam::Callback::checkOut
bool checkOut()
Check-out Callback from CallbackRegistry.
Definition: Callback.C:76
Foam::Callback
Abstract class to handle automatic call-back registration with the CallbackRegistry....
Definition: Callback.H:53