CORGI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
default_entity_factory.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DEFAULT_ENTITY_FACTORY_H_
16 #define DEFAULT_ENTITY_FACTORY_H_
17 
18 #include <set>
19 #include <string>
20 #include <vector>
21 
22 #include "corgi/entity_manager.h"
25 #include "flatbuffers/flatbuffers.h"
26 #include "fplbase/utilities.h"
27 
28 namespace corgi {
29 namespace component_library {
30 
31 /// @file
32 /// @addtogroup corgi_component_library
33 /// @{
34 ///
35 /// @class DefaultEntityFactory
36 ///
37 /// @brief Implementations of DefaultEntityFactory can be found in
38 /// `default_entity_factory.inc`.
40  public:
41  /// @brief Destructor for DefaultEntityFactory.
42  virtual ~DefaultEntityFactory() {}
43 
44  /// @brief Handles reading an Entity list and extracting the individual
45  /// Entity data definitions.
46  ///
47  /// @param[in] entity_list A const void pointer to the start of the list
48  /// of Entities.
49  /// @param[out] entity_defs A vector that captures the output of the
50  /// extracted Entity data definitions.
51  ///
52  /// @return returns `true` if the list was parsed successfully. Otherwise it
53  /// returns `false`.
54  virtual bool ReadEntityList(const void* entity_list,
55  std::vector<const void*>* entity_defs);
56 
57  /// @brief Handles reading an Entity definition and extracting the individual
58  /// Component data definitions.
59  ///
60  /// @param[in] entity_definition A const void pointer to the Entity definition
61  /// whose Component data definitions should be extracted.
62  /// @param[out] component_defs A vector that captures the output of
63  /// the extracted Component data definitions.
64  ///
65  /// @return Returns `true` if the `entity_definition` was parsed successfully.
66  /// Otherwise it returns `false`.
67  virtual bool ReadEntityDefinition(const void* entity_definition,
68  std::vector<const void*>* component_defs);
69 
70  /// @brief Creates an Entity list that contains a single Entity definition,
71  /// which contains a single Component definition (a `MetaDef` with `prototype`
72  /// set to the requested prototype name).
73  ///
74  /// @param[in] prototype_name A C-string name of the prototype, which is used
75  /// to set the `prototype` field in the MetaComponent.
76  /// @param[out] request A vector of bytes to capture the output of the
77  /// prototype request FlatBuffer data.
78  ///
79  /// @return Returns `true` if the request was created successfully. Otherwise
80  /// it returns `false`.
81  virtual bool CreatePrototypeRequest(const char* prototype_name,
82  std::vector<uint8_t>* request);
83 
84  /// @brief Handles building a single Entity definition flatbuffer from a list
85  /// of an Entity's Component definitions.
86  ///
87  /// @param[in] component_data A const reference to a std::vector that contains
88  /// the list of the Entity's Component definitions, which can be indexed by
89  /// Component ID.
90  /// @param[out] entity_definition A vector of bytes to capture the output of
91  /// the Entity definition FlatBuffer data.
92  ///
93  /// @return Returns `true` if the Entity definition was successfully created.
94  /// Otherwise, it returns `false`.
95  virtual bool CreateEntityDefinition(
96  const std::vector<const void*>& component_data,
97  std::vector<uint8_t>* entity_definition);
98 
99  /// @brief Handles building an Entity list flatbuffer from a collection of
100  /// individual Entity flatbuffers.
101  ///
102  /// @param[in] entity_defs A const reference to a std::vector that contains
103  /// all the Entity flatbuffers.
104  /// @param[out] entity_list A vector of bytes to capture the output of the
105  /// Entity list FlatBuffer data.
106  ///
107  /// @return Returns `true` if the Entity list was successfully created.
108  /// Otherwise, it returns `false`.
109  virtual bool CreateEntityList(const std::vector<const void*>& entity_defs,
110  std::vector<uint8_t>* entity_list);
111 };
112 /// @}
113 
114 } // namespace component_library
115 } // namespace corgi
116 
117 #endif // DEFAULT_ENTITY_FACTORY_H_
virtual bool CreateEntityDefinition(const std::vector< const void * > &component_data, std::vector< uint8_t > *entity_definition)
Handles building a single Entity definition flatbuffer from a list of an Entity's Component definitio...
Implementations of DefaultEntityFactory can be found in default_entity_factory.inc.
Definition: default_entity_factory.h:39
virtual bool ReadEntityList(const void *entity_list, std::vector< const void * > *entity_defs)
Handles reading an Entity list and extracting the individual Entity data definitions.
An EntityFactory builds Entities based on prototypes, using FlatBuffers to specify the raw data for E...
Definition: entity_factory.h:37
virtual bool CreateEntityList(const std::vector< const void * > &entity_defs, std::vector< uint8_t > *entity_list)
Handles building an Entity list flatbuffer from a collection of individual Entity flatbuffers...
virtual bool ReadEntityDefinition(const void *entity_definition, std::vector< const void * > *component_defs)
Handles reading an Entity definition and extracting the individual Component data definitions...
virtual ~DefaultEntityFactory()
Destructor for DefaultEntityFactory.
Definition: default_entity_factory.h:42
virtual bool CreatePrototypeRequest(const char *prototype_name, std::vector< uint8_t > *request)
Creates an Entity list that contains a single Entity definition, which contains a single Component de...