C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
pattern_rule_container.h
Go to the documentation of this file.
1/*
2 © 2023 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14// -*- C++ -*-
15
16#ifndef CPP_API_EXTENSIONS_SRC_SME_PATTERN_RULES_PATTERN_RULE_CONTAINER_H
17#define CPP_API_EXTENSIONS_SRC_SME_PATTERN_RULES_PATTERN_RULE_CONTAINER_H
18
19#include <string>
20#include <map>
21
22//#ifdef __GNUC__
23 #include <cstdint>
24//#endif
25
26#include "sme/aqpp/foundation/callables/action.hpp"
28#include "sme/aqpp/print/sme_print.hpp"
29
30namespace sme
31{
32
38{
39public:
40
46 {;}
47
53 {;}
54
64 bool add_rule( std::string _name, I_pattern_rule * _rule, bool _active = true)
65 {
66 if( find_rule( _name) == NULL)
67 {
68 _rule->m_is_active = _active;
69 if( _active) {
70 SIM_DEBUG( "Adding active rule '" << _name << "'");
71 m_active_rules[ _name] = _rule;
72 } else {
73 SIM_DEBUG( "Adding inactive rule '" << _name << "'");
74 m_inactive_rules[ _name] = _rule;
75 }
76 return( true);
77 }
78 SIM_ERROR( "Rule already exists with name '" << _name << "'");
79 return( false);
80 }
81
87 void deactivate_rule( std::string _name)
88 {
89 if( find_inactive_rule( _name) == NULL)
90 {
91 std::map< std::string, I_pattern_rule *>::iterator mit = m_active_rules.find( _name);
92 if( mit != m_active_rules.end())
93 {
94 I_pattern_rule * rule = mit->second;
95 rule->m_is_active = false;
96 m_inactive_rules[ _name] = rule;
97 m_active_rules.erase( _name);
98 }
99 }
100 }
101
107 void activate_rule( std::string _name)
108 {
109 if( find_active_rule( _name) == NULL)
110 {
111 std::map< std::string, I_pattern_rule *>::iterator mit = m_inactive_rules.find( _name);
112 if( mit != m_inactive_rules.end())
113 {
114 I_pattern_rule * rule = mit->second;
115 rule->m_is_active = true;
116 m_inactive_rules.erase( _name);
117 m_active_rules[ _name] = rule;
118 }
119 }
120 }
121
128 void process_active_rules( uint64_t _old_value, uint64_t _new_value)
129 {
130 std::map< std::string, I_pattern_rule *>::iterator it;
131 for( it = m_active_rules.begin(); it != m_active_rules.end(); it++)
132 {
133 it->second->process_rule( _old_value, _new_value);
134 }
135 }
136
143 I_pattern_rule * find_rule( std::string _name)
144 {
145 I_pattern_rule * rule = find_active_rule( _name);
146 if( rule != NULL)
147 return( rule);
148 return( find_inactive_rule( _name));
149 }
150
157 I_pattern_rule * find_active_rule( std::string _name)
158 {
159 std::map< std::string, I_pattern_rule *>::iterator mit = m_active_rules.find( _name);
160 if( mit != m_active_rules.end())
161 return( mit->second);
162 return( NULL);
163 }
164
171 I_pattern_rule * find_inactive_rule( std::string _name)
172 {
173 std::map< std::string, I_pattern_rule *>::iterator mit = m_inactive_rules.find( _name);
174 if( mit != m_inactive_rules.end())
175 return( mit->second);
176 return( NULL);
177 }
178
184 const std::map< std::string, I_pattern_rule *> & get_active_rules() const {
185 return( m_active_rules);
186 }
187
193 const std::map< std::string, I_pattern_rule *> & get_inactive_rules() const {
194 return( m_inactive_rules);
195 }
196
197protected:
202 std::map< std::string, I_pattern_rule *> m_active_rules;
203
208 std::map< std::string, I_pattern_rule *> m_inactive_rules;
209};
210
211}
212
213#endif /*PATTERN_RULE_CONTAINER_H_*/
#define NULL
Definition: _null.h:24
Interface and base class for all notification rule types.
Definition: I_pattern_rule.h:32
bool m_is_active
stores is active
Definition: I_pattern_rule.h:44
tracks all rules of a single type for a particular target.
Definition: pattern_rule_container.h:38
void activate_rule(std::string _name)
activate rule by name.
Definition: pattern_rule_container.h:107
const std::map< std::string, I_pattern_rule * > & get_inactive_rules() const
return const reference to 'inactive' string map of pattern rules.
Definition: pattern_rule_container.h:193
I_pattern_rule * find_active_rule(std::string _name)
find rule in active list by name.
Definition: pattern_rule_container.h:157
std::map< std::string, I_pattern_rule * > m_inactive_rules
map of string to inactive rules.
Definition: pattern_rule_container.h:208
pattern_rule_container()
Construct a new pattern rule container object.
Definition: pattern_rule_container.h:45
bool add_rule(std::string _name, I_pattern_rule *_rule, bool _active=true)
Adds a descendant of I_pattern_rule by name to this container.
Definition: pattern_rule_container.h:64
std::map< std::string, I_pattern_rule * > m_active_rules
map of string to active rules.
Definition: pattern_rule_container.h:202
virtual ~pattern_rule_container()
Destroy the pattern rule container object.
Definition: pattern_rule_container.h:52
void deactivate_rule(std::string _name)
deactivate rule by name.
Definition: pattern_rule_container.h:87
void process_active_rules(uint64_t _old_value, uint64_t _new_value)
processes all active rules.
Definition: pattern_rule_container.h:128
I_pattern_rule * find_rule(std::string _name)
find rule in active or inactive list by name.
Definition: pattern_rule_container.h:143
const std::map< std::string, I_pattern_rule * > & get_active_rules() const
return const reference to 'active' string map of pattern rules.
Definition: pattern_rule_container.h:184
I_pattern_rule * find_inactive_rule(std::string _name)
find rule in inactive list by name.
Definition: pattern_rule_container.h:171
Definition: expression_vector.h:25