Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryISafeRunnable.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef BERRYISAFERUNNABLE_H_
18 #define BERRYISAFERUNNABLE_H_
19 
20 #include <berryObject.h>
21 #include <berryMacros.h>
22 
24 
25 namespace berry
26 {
27 
41 {
42 
44 
45 
56  virtual void HandleException(const ctkException& exception) = 0;
57 
67  virtual void Run() = 0;
68 };
69 
70 template<typename R>
72 {
73  typedef void(R::*RunCallback)();
74  typedef void(R::*HandleExcCallback)(const std::exception&);
75 
76  SafeRunnableDelegate(R* runnable, RunCallback func, HandleExcCallback handleFunc = 0) :
77  m_Runnable(runnable), m_RunFunc(func), m_HandleExcFunc(handleFunc)
78  {
79  }
80 
81  void Run() override
82  {
83  m_Runnable->*m_RunFunc();
84  }
85 
86  void HandleException(const ctkException& exception) override
87  {
88  if (m_HandleExcFunc)
89  m_Runnable->*m_HandleExcFunc(exception);
90  }
91 
92 private:
93 
94  R* m_Runnable;
95  RunCallback m_RunFunc;
96  HandleExcCallback m_HandleExcFunc;
97 
98 };
99 
100 }
101 
102 #endif /* BERRYISAFERUNNABLE_H_ */
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
#define org_blueberry_core_runtime_EXPORT
#define berryObjectMacro(...)
Definition: berryMacros.h:37