neoGFX
Cross-platform C++ app/game engine
i_component.hpp
Go to the documentation of this file.
1 // i_component.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 #pragma once
20 
21 #include <neogfx/neogfx.hpp>
22 #include <neolib/string.hpp>
23 #include <neogfx/game/ecs_ids.hpp>
25 
26 namespace neogfx::game
27 {
28  class i_ecs;
29 
31  {
32  public:
33  virtual ~i_component_base() = default;
34  public:
35  virtual game::i_ecs& ecs() const = 0;
36  virtual const component_id& id() const = 0;
37  public:
38  virtual bool is_data_optional() const = 0;
39  virtual const i_string& name() const = 0;
40  virtual uint32_t field_count() const = 0;
41  virtual component_data_field_type field_type(uint32_t aFieldIndex) const = 0;
42  virtual neolib::uuid field_type_id(uint32_t aFieldIndex) const = 0;
43  virtual const i_string& field_name(uint32_t aFieldIndex) const = 0;
44  };
45 
47  {
48  public:
49  virtual void* populate(const std::string& aName, const void* aComponentData, std::size_t aComponentDataSize) = 0;
50  template <typename ComponentData>
51  void* populate(const std::string& aName, ComponentData&& aComponentData)
52  {
53  return populate(aName, &std::forward<ComponentData>(aComponentData), sizeof(ComponentData));
54  }
55  };
56 
58  {
59  public:
60  virtual bool has_entity_record(entity_id aEntity) const = 0;
61  virtual void destroy_entity_record(entity_id aEntity) = 0;
62  public:
63  virtual void* populate(entity_id aEntity, const void* aComponentData, std::size_t aComponentDataSize) = 0;
64  template <typename ComponentData>
65  void* populate(entity_id aEntity, ComponentData&& aComponentData)
66  {
67  return populate(aEntity, &std::forward<ComponentData>(aComponentData), sizeof(ComponentData));
68  }
69  };
70 
71  template <typename ComponentData>
72  class static_component;
73 
74  template <typename ComponentData>
76 }
void * populate(const std::string &aName, ComponentData &&aComponentData)
Definition: i_component.hpp:51
virtual component_data_field_type field_type(uint32_t aFieldIndex) const =0
virtual const i_string & field_name(uint32_t aFieldIndex) const =0
virtual bool is_data_optional() const =0
virtual game::i_ecs & ecs() const =0
virtual const i_string & name() const =0
virtual const component_id & id() const =0
virtual neolib::uuid field_type_id(uint32_t aFieldIndex) const =0
void * populate(entity_id aEntity, ComponentData &&aComponentData)
Definition: i_component.hpp:65
virtual ~i_component_base()=default
id_t entity_id
Definition: ecs_ids.hpp:34
virtual uint32_t field_count() const =0