Scene Fusion 2 API Reference
ksEvent.h
1 /*************************************************************************
2  *
3  * KINEMATICOUP CONFIDENTIAL
4  * __________________
5  *
6  * Copyright (2016-2021) KinematicSoup Technologies Incorporated
7  * All Rights Reserved.
8  *
9  * NOTICE: All information contained herein is, and remains
10  * the property of KinematicSoup Technologies Incorporated and its
11  * suppliers, if any. The intellectual and technical concepts contained
12  * herein are proprietary to KinematicSoup Technologies Incorporated
13  * and its suppliers and may be covered by Canadian and Foreign Patents,
14  * patents in process, and are protected by trade secret or copyright law.
15  * Dissemination of this information or reproduction of this material
16  * is strictly forbidden unless prior written permission is obtained
17  * from KinematicSoup Technologies Incorporated.
18  */
19 #pragma once
20 
21 #include <memory>
22 #include <functional>
23 
24 namespace KS {
28  template<typename ...Arguments>
29  class ksEvent
30  {
31  public:
32  typedef std::function<void(Arguments...)> Handler;
33  typedef std::shared_ptr<ksEvent<Arguments...>> SPtr;
34  typedef std::weak_ptr<ksEvent<Arguments...>> WPtr;
35 
42  static SPtr CreateSPtr(Handler callback)
43  {
44  return std::make_shared<ksEvent<Arguments...>>(callback);
45  }
46 
52  ksEvent(Handler callback)
53  : m_callback{ callback }
54  {
55  }
56 
60  virtual ~ksEvent()
61  {
62  }
63 
69  bool IsExpired()
70  {
71  return (m_callback == nullptr);
72  }
73 
74  private:
75  Handler m_callback;
76  template<typename ...T> friend class EventSystem;
77 
82  void Reset()
83  {
84  m_callback = nullptr;
85  }
86 
92  void operator()(Arguments&&... args)
93  {
94  if (m_callback) {
95  m_callback(std::forward<Arguments>(args)...);
96  }
97  }
98  };
99 } // KS
Definition: ksEvent.h:30
ksEvent(Handler callback)
Definition: ksEvent.h:52
bool IsExpired()
Definition: ksEvent.h:69
virtual ~ksEvent()
Definition: ksEvent.h:60
static SPtr CreateSPtr(Handler callback)
Definition: ksEvent.h:42
Definition: sfDictionaryProperty.h:24