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 SIM_DEBUG_NO_NEWLINE( "rule " << it->first);
134 it->second->process_rule( _old_value, _new_value);
135 }
136 }
137
144 I_pattern_rule * find_rule( std::string _name)
145 {
146 I_pattern_rule * rule = find_active_rule( _name);
147 if( rule != NULL)
148 return( rule);
149 return( find_inactive_rule( _name));
150 }
151
158 I_pattern_rule * find_active_rule( std::string _name)
159 {
160 std::map< std::string, I_pattern_rule *>::iterator mit = m_active_rules.find( _name);
161 if( mit != m_active_rules.end())
162 return( mit->second);
163 return( NULL);
164 }
165
172 I_pattern_rule * find_inactive_rule( std::string _name)
173 {
174 std::map< std::string, I_pattern_rule *>::iterator mit = m_inactive_rules.find( _name);
175 if( mit != m_inactive_rules.end())
176 return( mit->second);
177 return( NULL);
178 }
179
185 const std::map< std::string, I_pattern_rule *> & get_active_rules() const {
186 return( m_active_rules);
187 }
188
194 const std::map< std::string, I_pattern_rule *> & get_inactive_rules() const {
195 return( m_inactive_rules);
196 }
197
198protected:
203 std::map< std::string, I_pattern_rule *> m_active_rules;
204
209 std::map< std::string, I_pattern_rule *> m_inactive_rules;
210};
211
212}
213
214#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:38
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:194
I_pattern_rule * find_active_rule(std::string _name)
find rule in active list by name.
Definition: pattern_rule_container.h:158
std::map< std::string, I_pattern_rule * > m_inactive_rules
map of string to inactive rules.
Definition: pattern_rule_container.h:209
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:203
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:144
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:185
I_pattern_rule * find_inactive_rule(std::string _name)
find rule in inactive list by name.
Definition: pattern_rule_container.h:172
Definition: expression_vector.h:25