neoGFX
Cross-platform C++ app/game engine
i_object.hpp
Go to the documentation of this file.
1 // i_object.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2018 Leigh Johnston. All Rights Reserved.
5 
6  This program is free software: you can redistribute it and / or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <neogfx/neogfx.hpp>
23 #include <type_traits>
24 
25 #include <neolib/i_lifetime.hpp>
26 
27 #include <neogfx/core/i_event.hpp>
29 
30 namespace neogfx
31 {
32  enum class object_type : uint64_t;
33 
34  class i_object : public i_property_owner
35  {
36  public:
39  public:
40  virtual ~i_object() = default;
41  public:
42  virtual neogfx::object_type object_type() const = 0;
43  };
44 
45  template <typename Object>
46  inline bool is_alive(Object& aObject)
47  {
48  if constexpr (std::is_base_of_v<neolib::i_lifetime, Object>)
49  return static_cast<neolib::i_lifetime&>(aObject).is_alive();
50  else
51  return dynamic_cast<neolib::i_lifetime&>(aObject).is_alive();
52  }
53 
54  template <typename Object, typename Handler>
55  inline auto destroying(Object& aObject, const Handler aHandler)
56  {
57  if constexpr (std::is_base_of_v<i_object, Object>)
58  return static_cast<i_object&>(aObject).destroying(aHandler);
59  else
60  return dynamic_cast<i_object&>(aObject).destroying(aHandler);
61  }
62 
63  template <typename Object, typename Handler>
64  inline auto destroyed(Object& aObject, const Handler aHandler)
65  {
66  if constexpr (std::is_base_of_v<i_object, Object>)
67  return static_cast<i_object&>(aObject).destroyed(aHandler);
68  else
69  return dynamic_cast<i_object&>(aObject).destroyed(aHandler);
70  }
71 }
bool is_alive(Object &aObject)
Definition: i_object.hpp:46
auto destroying(Object &aObject, const Handler aHandler)
Definition: i_object.hpp:55
auto destroyed(Object &aObject, const Handler aHandler)
Definition: i_object.hpp:64
#define declare_event(declName,...)