Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ParameterSchemaRegistry.cpp
Go to the documentation of this file.
2
3namespace Olympe
4{
6
9
15
18
19 void ParameterSchemaRegistry::UnregisterSchema(const std::string& componentName)
20 {
21 for (size_t i = 0; i < m_schemas.size(); ++i)
22 { if (m_schemas[i].componentName == componentName) { m_schemas.erase(m_schemas.begin() + i); break; } }
24 }
25
26 bool ParameterSchemaRegistry::HasSchema(const std::string& componentName) const
27 { return m_schemaIndex.find(componentName) != m_schemaIndex.end(); }
28
29 const ComponentSchema* ParameterSchemaRegistry::GetSchema(const std::string& componentName) const
30 {
31 auto it = m_schemaIndex.find(componentName);
32 if (it != m_schemaIndex.end()) { return &m_schemas[it->second]; }
33 return nullptr;
34 }
35
36 const std::vector<ComponentSchema>& ParameterSchemaRegistry::GetAllSchemas() const
37 { return m_schemas; }
38
39 void ParameterSchemaRegistry::LoadSchemasFromFile(const std::string& filePath) { (void)filePath; }
41
44
45 std::vector<std::string> ParameterSchemaRegistry::GetSchemaNames() const
46 { std::vector<std::string> names; for (size_t i = 0; i < m_schemas.size(); ++i) { names.push_back(m_schemas[i].componentName); } return names; }
47
48 std::vector<ComponentSchema> ParameterSchemaRegistry::GetSchemasByCategory(const std::string& category) const
49 { std::vector<ComponentSchema> result; for (size_t i = 0; i < m_schemas.size(); ++i) { if (m_schemas[i].category == category) { result.push_back(m_schemas[i]); } } return result; }
50
51 std::vector<ComponentSchema> ParameterSchemaRegistry::SearchSchemas(const std::string& query) const
52 { std::vector<ComponentSchema> result; for (size_t i = 0; i < m_schemas.size(); ++i) { if (m_schemas[i].componentName.find(query) != std::string::npos) { result.push_back(m_schemas[i]); } } return result; }
53
54 std::vector<std::string> ParameterSchemaRegistry::GetCategories() const
55 { std::vector<std::string> categories; for (auto it = m_categoryIndex.begin(); it != m_categoryIndex.end(); ++it) { categories.push_back(it->first); } return categories; }
56
57 std::vector<ComponentSchema> ParameterSchemaRegistry::GetSchemasInCategory(const std::string& category) const
58 { return GetSchemasByCategory(category); }
59
60 const ParameterDefinition* ParameterSchemaRegistry::GetParameterDefinition(const std::string& componentName, const std::string& parameterName) const
61 {
62 const ComponentSchema* schema = GetSchema(componentName);
63 if (schema != nullptr) { for (size_t i = 0; i < schema->parameters.size(); ++i) { if (schema->parameters[i].name == parameterName) { return &schema->parameters[i]; } } }
64 return nullptr;
65 }
66
67 std::vector<ParameterDefinition> ParameterSchemaRegistry::GetParametersForComponent(const std::string& componentName) const
68 {
69 const ComponentSchema* schema = GetSchema(componentName);
70 if (schema != nullptr) { return schema->parameters; }
71 return std::vector<ParameterDefinition>();
72 }
73
76
77 bool ParameterSchemaRegistry::ValidateParameter(const std::string& componentName, const std::string& parameterName, const std::string& value) const
78 { (void)componentName; (void)parameterName; (void)value; return true; }
79
81 { m_categoryIndex.clear(); for (size_t i = 0; i < m_schemas.size(); ++i) { m_categoryIndex[m_schemas[i].category].push_back(i); } }
82
84
85 size_t ParameterSchemaRegistry::GetSchemaCount() const { return m_schemas.size(); }
88 { size_t count = 0; for (size_t i = 0; i < m_schemas.size(); ++i) { count += m_schemas[i].parameters.size(); } return count; }
89
90 bool ParameterSchemaRegistry::IsSchemaDeprecated(const std::string& componentName) const
91 { const ComponentSchema* schema = GetSchema(componentName); if (schema != nullptr) { return schema->isDeprecated; } return false; }
92
93 std::vector<ComponentSchema> ParameterSchemaRegistry::GetDeprecatedSchemas() const
94 { std::vector<ComponentSchema> result; for (size_t i = 0; i < m_schemas.size(); ++i) { if (m_schemas[i].isDeprecated) { result.push_back(m_schemas[i]); } } return result; }
95
97 { m_schemaIndex.clear(); m_categoryIndex.clear(); for (size_t i = 0; i < m_schemas.size(); ++i) { m_schemaIndex[m_schemas[i].componentName] = i; m_categoryIndex[m_schemas[i].category].push_back(i); } }
98
99} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::vector< std::string > GetSchemaNames() const
bool IsSchemaDeprecated(const std::string &componentName) const
std::vector< ComponentSchema > SearchSchemas(const std::string &query) const
bool ValidateComponent(const ComponentData &component) const
void UnregisterSchema(const std::string &componentName)
bool ValidateParameter(const std::string &componentName, const std::string &parameterName, const std::string &value) const
std::map< std::string, size_t > m_schemaIndex
const ParameterDefinition * GetParameterDefinition(const std::string &componentName, const std::string &parameterName) const
std::vector< ComponentSchema > m_schemas
std::vector< std::string > GetCategories() const
static ParameterSchemaRegistry & Get()
std::map< std::string, std::vector< size_t > > m_categoryIndex
bool HasSchema(const std::string &componentName) const
std::vector< ComponentSchema > GetSchemasInCategory(const std::string &category) const
void RegisterSchema(const ComponentSchema &schema)
const std::vector< ComponentSchema > & GetAllSchemas() const
void LoadSchemasFromDirectory(const std::string &directoryPath)
static ParameterSchemaRegistry * s_instance
std::vector< ComponentSchema > GetSchemasByCategory(const std::string &category) const
const ComponentSchema * GetSchema(const std::string &componentName) const
std::vector< ParameterDefinition > GetParametersForComponent(const std::string &componentName) const
std::vector< ComponentSchema > GetDeprecatedSchemas() const
void LoadSchemasFromFile(const std::string &filePath)
< Provides AssetID and INVALID_ASSET_ID