neoGFX
Cross-platform C++ app/game engine
object.hpp
Go to the documentation of this file.
1 // 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 <neolib/lifetime.hpp>
24 
25 #include <neogfx/core/event.hpp>
26 #include <neogfx/core/i_object.hpp>
29 
30 namespace neogfx
31 {
32  template <typename... Bases>
33  class object : public neolib::lifetime, public i_object, public i_properties, public Bases...
34  {
35  public:
36  define_declared_event(Destroying, destroying);
37  define_declared_event(Destroyed, destroyed);
38  public:
40  neolib::lifetime{ aState }
41  {
42  }
44  {
45  set_destroyed();
46  }
47  // type
48  public:
50  {
51  return neogfx::object_type{};
52  }
53  // i_lifetime
54  public:
55  void set_destroying() override
56  {
57  if (is_alive())
58  {
59  Destroying.trigger();
61  }
62  }
63  void set_destroyed() override
64  {
65  if (!is_destroyed())
66  {
67  Destroyed.trigger();
69  }
70  }
71  // i_object
72  public:
73  void property_changed(i_property&) override
74  {
75  // default is to do nothing
76  }
77  public:
78  const i_properties& properties() const override
79  {
80  return *this;
81  }
83  {
84  return *this;
85  }
86  // i_properties
87  public:
88  void register_property(i_property& aProperty) override
89  {
90  iProperties.emplace(aProperty.name(), &aProperty);
91  }
92  const neogfx::property_map& property_map() const override
93  {
94  return iProperties;
95  }
96  // state
97  private:
98  neogfx::property_map iProperties;
99  };
100 }
virtual const i_string & name() const =0
lifetime_state
Definition: i_lifetime.hpp:66
i_properties & properties() override
Definition: object.hpp:82
bool is_destroyed() const final
Definition: lifetime.inl:199
multi_threaded_lifetime lifetime
Definition: lifetime.hpp:135
const neogfx::property_map & property_map() const override
Definition: object.hpp:92
void set_destroying() override
Definition: lifetime.inl:216
bool is_alive() const final
Definition: lifetime.inl:187
std::map< std::string, i_property * > property_map
void set_destroyed() override
Definition: object.hpp:63
define_declared_event(Destroying, destroying)
void register_property(i_property &aProperty) override
Definition: object.hpp:88
void property_changed(i_property &) override
Definition: object.hpp:73
neogfx::object_type object_type() const override
Definition: object.hpp:49
void set_destroyed() override
Definition: lifetime.inl:230
const i_properties & properties() const override
Definition: object.hpp:78
auto destroying(Object &aObject, const Handler aHandler)
Definition: i_object.hpp:55
auto destroyed(Object &aObject, const Handler aHandler)
Definition: i_object.hpp:64
void set_destroying() override
Definition: object.hpp:55
object(neolib::lifetime_state aState=neolib::lifetime_state::Creating)
Definition: object.hpp:39