Zigbee Protocol Controller 1.6.0
attribute_mapper_engine.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
22#ifndef ATTRIBUTE_MAPPER_ENGINE_H
23#define ATTRIBUTE_MAPPER_ENGINE_H
24
25#include "attribute.hpp"
28#include <map>
29#include <memory>
30
31// Sort priority from high to low.
33 bool operator()(const int &lhs, const int &rhs) const
34 {
35 return lhs > rhs;
36 }
37};
38
43 multimap<int, std::shared_ptr<ast::assignment>, scope_priority_compare>;
44
51 = std::map<std::tuple<attribute_store::attribute, char, int>,
53
60using assignment_properties_t = std::tuple<int, char, attribute_store_type_t>;
61
142{
143 public:
148 void reset();
149
157 bool load_path(const std::string &uam_path);
158
166 bool load_file(std::string uam_file_name);
167
175 bool add_expression(const std::string expression);
176
186
195
203
210
224
225 private:
236 attribute_store::attribute
237 get_destination_for_attribute(const attribute_store::attribute &endpoint,
238 const ast::attribute &attribute,
239 bool create_if_missing) const;
250 get_equivalent_assignments(std::shared_ptr<ast::assignment> assignment);
251
262 attribute_store::attribute get_assigment_potential_destination(
263 std::shared_ptr<ast::assignment> assignment,
264 attribute_store::attribute original_node);
265
275 bool
276 assignment_matches_destination(std::shared_ptr<ast::assignment> assignment,
277 attribute_store::attribute destination);
278
288 void run_assignments(equivalent_assignments_t assignments_to_check,
289 attribute_store::attribute assigment_destination,
290 attribute_store::attribute original_node);
300 bool run_assignment(std::shared_ptr<ast::assignment> assignment,
301 attribute_store::attribute assigment_destination,
302 attribute_store::attribute original_node);
303
316 bool
317 apply_regular_assignment(attribute_store::attribute common_parent,
318 attribute_store::attribute destination,
319 attribute_store::attribute original_node,
320 const ast::scope_settings_t &settings,
321 result_type_t evaluated_value,
322 std::shared_ptr<ast::assignment> assignment) const;
323
335 bool apply_instance_assignment(attribute_store::attribute common_parent,
336 float evaluated_value,
337 std::shared_ptr<ast::assignment> assignment,
338 bool chain_reaction);
339
349 bool apply_clearance_assignment(attribute_store::attribute common_parent,
350 float evaluated_value,
351 std::shared_ptr<ast::assignment> assignment);
352
353 //Lookup table for which assignments depend on which attributes
354 std::multimap<ast::attribute_dependency_t, std::shared_ptr<ast::assignment>>
356
357 /* Saves the scopes settings for an assignment.
358 e.g 'scope 2 chain_reaction(0) clear_desired(0) { assignment1 }' will associate
359 chain_reaction = 3 and clear_desired = 0 to assignment 1.
360 */
361 std::map<std::shared_ptr<ast::assignment>,
362 std::shared_ptr<ast::scope_settings_t>>
364
365 /* Stores properties associated to assignments. */
366 std::map<std::shared_ptr<ast::assignment>, assignment_properties_t>
368
369 // Default mapper configured comment parent attribute type.
371};
372
373#endif //ATTRIBUTE_MAPPER_ENGINE_H
374
attribute store C++ wrapper.
Mapper Engine.
Definition: attribute_mapper_engine.hpp:142
bool apply_instance_assignment(attribute_store::attribute common_parent, float evaluated_value, std::shared_ptr< ast::assignment > assignment, bool chain_reaction)
Applies an instance assigment, which will verify if an attribute path with a certain value exists.
bool load_path(const std::string &uam_path)
Load engine with all uam file in a given directory.
attribute_store_type_t common_parent_type
Definition: attribute_mapper_engine.hpp:370
void set_common_parent_type(attribute_store_type_t t)
Set the Common Attribute type which should be used as start context for all attribute evaluations.
bool load_file(std::string uam_file_name)
Load engine with single uam file.
void on_attribute_updated(attribute_store_node_t node, attribute_store_node_value_state_t state, attribute_store_change_t change)
Called when an attribute is updated.
void reset()
Reset the mapper engine and clear all releations.
bool assignment_matches_destination(std::shared_ptr< ast::assignment > assignment, attribute_store::attribute destination)
Checks if an assignment (lhs) path matches the attribute for a destination.
equivalent_assignments_t get_equivalent_assignments(std::shared_ptr< ast::assignment > assignment)
Checks if the engine has other assigments assigning the same attribute type / value type.
static MapperEngine & get_instance()
Get the singletron.
std::map< std::shared_ptr< ast::assignment >, std::shared_ptr< ast::scope_settings_t > > assignment_settings
Definition: attribute_mapper_engine.hpp:363
bool apply_clearance_assignment(attribute_store::attribute common_parent, float evaluated_value, std::shared_ptr< ast::assignment > assignment)
Applies a clearance assigment, which may undefine values.
bool add_expression(const std::string expression)
Add uam expression to the ast.
bool run_assignment(std::shared_ptr< ast::assignment > assignment, attribute_store::attribute assigment_destination, attribute_store::attribute original_node)
Runs a single assigment and verifies if a value was applied.
bool apply_regular_assignment(attribute_store::attribute common_parent, attribute_store::attribute destination, attribute_store::attribute original_node, const ast::scope_settings_t &settings, result_type_t evaluated_value, std::shared_ptr< ast::assignment > assignment) const
Applies a regular assigment.
void run_assignments(equivalent_assignments_t assignments_to_check, attribute_store::attribute assigment_destination, attribute_store::attribute original_node)
Takes a list of assignments with a possible destination, and run.
attribute_store::attribute get_destination_for_attribute(const attribute_store::attribute &endpoint, const ast::attribute &attribute, bool create_if_missing) const
Get the destination for attribute.
attribute_store::attribute get_assigment_potential_destination(std::shared_ptr< ast::assignment > assignment, attribute_store::attribute original_node)
Checks what would be the destination attribute affected by an assigment, if applied.
bool update_dependencies(const ast::ast_tree &ast)
Re-calculate dependencies of a the ast,.
std::map< std::shared_ptr< ast::assignment >, assignment_properties_t > assignment_properties
Definition: attribute_mapper_engine.hpp:367
std::multimap< ast::attribute_dependency_t, std::shared_ptr< ast::assignment > > relations
Definition: attribute_mapper_engine.hpp:355
bool has_unknown_functions_in_tree(const ast::ast_tree &ast)
Checks the AST for built-in function names and return true if one or more functions are unknown.
float result_type_t
Definition: attribute_mapper_ast.hpp:36
std::map< std::tuple< attribute_store::attribute, char, int >, equivalent_assignments_t > assignments_to_run_t
Map of equivalent assignments associated with a destination attributes. Associates an attribute and i...
Definition: attribute_mapper_engine.hpp:52
std::tuple< int, char, attribute_store_type_t > assignment_properties_t
assignment_properties_t keeps track of various
Definition: attribute_mapper_engine.hpp:60
std::multimap< int, std::shared_ptr< ast::assignment >, scope_priority_compare > equivalent_assignments_t
Set of unique assignments, sorted by their scope priority.
Definition: attribute_mapper_engine.hpp:43
attribute_store_change_t
Attribute Store type to indicate the modification type that triggered a callback.
Definition: attribute_store.h:112
attribute_store_node_value_state_t
This is the value state of a value.
Definition: attribute_store.h:121
#define ATTRIBUTE_STORE_INVALID_NODE
Special attribute_store_node_t value indicating that it does not exist.
Definition: attribute_store.h:106
Definition: attribute_mapper_ast.hpp:39
std::vector< scope_setting > scope_settings_t
Type for Scope settings list.
Definition: attribute_mapper_ast.hpp:226
Definition: attribute_mapper_ast.hpp:53
Attribute.
Definition: attribute_mapper_ast.hpp:177
Definition: attribute_mapper_engine.hpp:32
bool operator()(const int &lhs, const int &rhs) const
Definition: attribute_mapper_engine.hpp:33