scc 2025.09
SystemC components library
cci_param_restricted.h
1/*******************************************************************************
2 * Copyright 2024 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16#ifndef _SCC_CCI_PARAM_RESTRICTED_H_
17#define _SCC_CCI_PARAM_RESTRICTED_H_
18
19#include <cci_configuration>
20#include <unordered_set>
21
22namespace scc {
24template <typename T> struct _min_max_restriction {
25 _min_max_restriction(T min, T max)
26 : min(min)
27 , max(max) {}
28
29 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value >= min && ev.new_value <= max; }
30 T const min;
31 T const max;
32};
33
34template <typename T> struct _min_max_excl_restriction {
35 _min_max_excl_restriction(T min, T max)
36 : min(min)
37 , max(max) {}
38
39 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value > min && ev.new_value < max; }
40 T const min;
41 T const max;
42};
43
44template <typename T> struct _min_restriction {
45 _min_restriction(T min)
46 : min(min) {}
47
48 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value >= min; }
49 T const min;
50};
51
52template <typename T> struct _min_excl_restriction {
53 _min_excl_restriction(T min)
54 : min(min) {}
55
56 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value > min; }
57 T const min;
58};
59
60template <typename T> struct _max_restriction {
61 _max_restriction(T max)
62 : max(max) {}
63
64 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value <= max; }
65 T const max;
66};
67
68template <typename T> struct _max_excl_restriction {
69 _max_excl_restriction(T max)
70 : max(max) {}
71
72 bool operator()(cci::cci_param_write_event<T> const& ev) const { return ev.new_value < max; }
73 T const max;
74};
75
76template <typename T> struct _discrete_restriction {
77 template <typename COLLECTION_TYPE>
78 _discrete_restriction(COLLECTION_TYPE values)
79 : values(std::begin(values), std::end(values)) {}
80
81 bool operator()(cci::cci_param_write_event<T> const& ev) const { return values.count(ev.new_value) > 0; }
82 std::unordered_set<T> const values;
83};
85
93template <typename T> inline _min_max_restriction<T> min_max_restriction(T min, T max) { return _min_max_restriction<T>(min, max); }
95template <typename T> inline _min_max_restriction<T> gte_lte_restriction(T min, T max) { return _min_max_restriction<T>(min, max); }
104template <typename T> inline _min_max_excl_restriction<T> min_max_excl_restriction(T min, T max) {
105 return _min_max_excl_restriction<T>(min, max);
106}
107
108template <typename T> inline _min_max_excl_restriction<T> gt_lt_restriction(T min, T max) { return _min_max_excl_restriction<T>(min, max); }
116template <typename T> inline _min_restriction<T> min_restriction(T min) { return _min_restriction<T>(min); }
118template <typename T> inline _min_restriction<T> gte_restriction(T min) { return _min_restriction<T>(min); }
126template <typename T> inline _min_excl_restriction<T> min_excl_restriction(T min) { return _min_excl_restriction<T>(min); }
128template <typename T> inline _min_excl_restriction<T> gt_restriction(T min) { return _min_excl_restriction<T>(min); }
136template <typename T> inline _max_restriction<T> max_restriction(T max) { return _max_restriction<T>(max); }
138template <typename T> inline _max_restriction<T> lte_restriction(T max) { return _max_restriction<T>(max); }
146template <typename T> inline _max_excl_restriction<T> max_excl_restriction(T max) { return _max_excl_restriction<T>(max); }
148template <typename T> inline _max_excl_restriction<T> lt_excl_restriction(T max) { return _max_excl_restriction<T>(max); }
156template <typename T> inline _discrete_restriction<T> discrete_restriction(std::initializer_list<T> values) {
157 return _discrete_restriction<T>(values);
158}
159
167template <typename T, size_t SZ> inline _discrete_restriction<T> discrete_restriction(std::array<T, SZ> values) {
168 return _discrete_restriction<T>(values);
169}
170
177template <typename T> inline _discrete_restriction<T> discrete_restriction(std::vector<T> values) {
178 return _discrete_restriction<T>(values);
179}
180
196template <typename T, cci::cci_param_mutable_type TM = cci::CCI_MUTABLE_PARAM> struct cci_param_restricted : public cci::cci_param<T, TM> {
197
200
211 template <typename RESTR>
212 cci_param_restricted(const std::string& name, const T& default_value, RESTR const& restr, const std::string& desc = "",
213 cci::cci_name_type name_type = cci::CCI_RELATIVE_NAME,
214 const cci::cci_originator& originator = sc_core::sc_get_current_object() ? cci::cci_originator()
215 : cci::cci_originator("sc_main"))
216 : cci::cci_param<T, TM>(name, default_value, desc, name_type, originator) {
217 this->register_pre_write_callback(restr);
218 this->reset();
219 }
220
233 template <typename RESTR>
234 cci_param_restricted(const std::string& name, const T& default_value, RESTR const& restr, cci::cci_broker_handle private_broker,
235 const std::string& desc = "", cci::cci_name_type name_type = cci::CCI_RELATIVE_NAME,
236 const cci::cci_originator& originator = sc_core::sc_get_current_object() ? cci::cci_originator()
237 : cci::cci_originator("sc_main"))
238 : cci::cci_param<T, TM>(name, default_value, desc, name_type, originator) {
239 this->register_pre_write_callback(restr);
240 this->reset();
241 }
242
243};
244} // namespace scc
245#endif /* _SCC_CCI_PARAM_RESTRICTED_H_ */
SCC TLM utilities.
_min_max_excl_restriction< T > gt_lt_restriction(T min, T max)
alias for min_max_excl_restriction(T min, T max)
_min_restriction< T > gte_restriction(T min)
alias for min_restriction(T min)
_min_excl_restriction< T > min_excl_restriction(T min)
creates a minimum restriction excluding the minimum value
_min_max_restriction< T > gte_lte_restriction(T min, T max)
alias for min_max_restriction(T min, T max)
_discrete_restriction< T > discrete_restriction(std::initializer_list< T > values)
creates a restriction for a discrete values set
_min_max_excl_restriction< T > min_max_excl_restriction(T min, T max)
creates a min/max restriction with excluding the limits
_max_excl_restriction< T > max_excl_restriction(T max)
creates a maximum restriction excluding the maximum value
_min_excl_restriction< T > gt_restriction(T min)
alias for min_excl_restriction(T min)
_max_restriction< T > lte_restriction(T max)
alias for max_restriction(T max)
_max_excl_restriction< T > lt_excl_restriction(T max)
alias for max_excl_restriction(T max)
_max_restriction< T > max_restriction(T max)
creates a maximum restriction including the maximum value
_min_restriction< T > min_restriction(T min)
creates a minimum restriction including the minimum value
_min_max_restriction< T > min_max_restriction(T min, T max)
creates a min/max restriction with including the limits
cci_param_restricted(const std::string &name, const T &default_value, RESTR const &restr, cci::cci_broker_handle private_broker, const std::string &desc="", cci::cci_name_type name_type=cci::CCI_RELATIVE_NAME, const cci::cci_originator &originator=sc_core::sc_get_current_object() ? cci::cci_originator() :cci::cci_originator("sc_main"))
cci_param_restricted(const std::string &name, const T &default_value, RESTR const &restr, const std::string &desc="", cci::cci_name_type name_type=cci::CCI_RELATIVE_NAME, const cci::cci_originator &originator=sc_core::sc_get_current_object() ? cci::cci_originator() :cci::cci_originator("sc_main"))