21#include "sparta/utils/Utils.hpp"
25#include "sparta/utils/KeyValue.hpp"
29#include "sparta/utils/VectorUtils.hpp"
50 bool allow_recursion=
true,
51 bool allow_prefix=
true);
175 return (idx_ == rhp.idx_) && (p_ == rhp.p_);
187 return !(*
this == rhp);
247 const std::string & desc) :
350 bool peek=
false)
const = 0;
409 bool peek=
false)
const = 0;
513 const std::string& str) = 0;
588 const std::string& str);
623 virtual std::string
stringize(
bool pretty=
false)
const override {
625 std::stringstream ss;
658 std::string& err_names)
const = 0;
683 const sparta::SpartaHandler& modifier_callback);
782 const std::string& str) = 0;
879 <<
" after reading it unless it is a volatile parameter";
885 <<
getLocation() <<
" because it is already finalized";
959 mutable uint32_t reads_;
964 std::vector<const ParameterBase *> associated_params_;
992 template<
class ValueType>
1002 template<
class T,
bool (T::*TMethod)(ValueType&, const sparta::TreeNode*)>
1004 const std::string& name)
1008 vcc.callback_ = std::bind(TMethod, obj, std::placeholders::_1, std::placeholders::_2);
1039 const std::string& name) :
1040 callback_(std::
bind(method, std::placeholders::_1, std::placeholders::_2)),
1049 name_(
"<uninitialized>")
1064 callback_(rhp.callback_),
1072 callback_ = rhp.callback_;
1076 std::string getName()
const
1084 return callback_(val, node);
1091 if(nm.find(
',') != std::string::npos){
1093 ex << nm <<
"\" contains a comma, which is not permitted";
1101 static bool doNothing_(ValueType& val,
const TreeNode* node)
1117 template <
typename ValueType>
1140 std::vector<ValidationCheckCallback<ValueType> > bounds_;
1141 std::vector<ValidationCheckCallback<ValueType> > dependencies_;
1146 using value_type = ValueType;
1161 const ValueType& def,
1162 const std::string& doc,
1163 bool isvolatile =
false) :
1167 disp_base_(
sparta::utils::BASE_DEC)
1184 const ValueType& def,
1185 const std::string& doc,
1187 bool isvolatile =
false) :
1190 sparta_assert(ps,
"Must construct parameter " << name <<
" with valid ParameterSet");
1195 const ValueType& def,
1196 const std::string& doc,
1199 bool isvolatile =
false) :
1202 sparta_assert(ps,
"Must construct parameter " << name <<
" with valid ParameterSet");
1204 if(param_attr_ == ParameterAttribute::HIDDEN) {
1230 template<
class T,
bool (T::*TMethod)(ValueType&, const sparta::TreeNode*)>
1260 const std::string& name)
1271 return Parameter::template getTypeName_<ValueType>();
1287 return sparta::utils::stringize_value(def_val_, disp_base_,
string_quote_);
1299 return sparta::utils::stringize_value(val_, disp_base_,
"\"");
1301 return sparta::utils::stringize_value(val_, disp_base_,
string_quote_);
1313 return Parameter::template getValueAsStringAt_<ValueType, ValueType>(idx, peek);
1322 bool peek=
false) const override final {
1323 if(indices.size() == 0){
1325 return getFinalVectorItemValueFromString_(val_, indices, 0, peek);
1329 return getVectorItemValueFromString_(val_, indices, 0, peek);
1339 bool peek=
false) const override final {
1340 if(indices.size() == 0){
1342 return getFinalVectorSize_(val_, indices, 0, peek);
1346 return getVectorSize_(val_, indices, 0, peek);
1353 operator const ValueType&()
const {
1428 return getDoubleValue_<ValueType>();
1439 return Parameter::template getNumValues_<ValueType, ValueType>(peek);
1452 return Dimensionality<ValueType>::value;
1524 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1526 return getValue() == (ValueType)rhp;
1531 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1533 return getValue() != (ValueType)rhp;
1538 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1540 return getValue() > (ValueType)rhp;
1545 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1547 return getValue() >= (ValueType)rhp;
1552 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1554 return getValue() < (ValueType)rhp;
1559 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1561 return getValue() <= (ValueType)rhp;
1591 checkModificationPermission_();
1597 static bool been_warned =
false;
1599 std::cout <<
"WARNING: A simulator override for parameter " <<
getLocation()
1600 <<
" (using operator=) was performed and ignored. This is because"
1601 <<
" the simulator is using --read-final-config. This is your"
1602 <<
" first and last warning." << std::endl;
1609 ValueType old_val = val_;
1622 return default_override_;
1626 Parameter::template overrideDefaultFromString_<ValueType, ValueType>(str);
1628 "Cannot override default on parameter if read count is > 0. "
1630 default_override_ =
true;
1634 Parameter::template overrideDefaultFromStringVector_<ValueType, ValueType>(vec);
1636 "Cannot override default on parameter if read count is > 0. "
1638 default_override_ =
true;
1642 const std::string& str)
override final {
1643 if(indices.size() == 0){
1645 Parameter::template overrideDefaultFromString_<ValueType, ValueType>(str);
1648 const bool incr_write_count =
false;
1649 setVectorItemValueFromString_(def_val_, indices, 0, str, incr_write_count);
1651 default_override_ =
true;
1655 if(indices.size() == 0){
1659 resizeVectorsFromString_(def_val_, indices, 0);
1663 clearVectorValue_(def_val_);
1668 checkModificationPermission_();
1670 "Parameter " <<
getLocation() <<
" must not have been read when restoring "
1671 "a value from the default. This is a write");
1683 if(indices.size() == 0){
1687 resizeVectorsFromString_(val_, indices, 0);
1691 clearVectorValue_(val_);
1699 checkModificationPermission_();
1735 bool success =
true;
1738 if(!vcb(val, node)){
1739 err_names += vcb.getName() +
",";
1760 return Parameter::template operator_insert_<U, ValueType>(e);
1769 return ((param_attr_ == ParameterAttribute::HIDDEN) and
1775 template <
class U,
class C1>
1777 operator_insert_(U e) {
1778 checkModificationPermission_();
1780 val_.push_back((
typename ValueType::value_type) e);
1785 Parameter::template setValueFromString_<ValueType, ValueType>(str, poke);
1789 Parameter::template setValueFromStringVector_<ValueType, ValueType>(vec, poke);
1793 const std::string& str)
override final {
1794 if(indices.size() == 0){
1796 Parameter::template setValueFromString_<ValueType, ValueType>(str);
1799 const bool incr_write_count =
true;
1800 setVectorItemValueFromString_(val_, indices, 0, str, incr_write_count);
1809 template <
typename T>
1810 typename std::enable_if<std::is_arithmetic<T>::value,
double>
::type
1811 getDoubleValue_()
const {
1815 template <
typename T>
1816 typename std::enable_if<!std::is_arithmetic<T>::value,
double>
::type
1817 getDoubleValue_()
const {
1818 throw SpartaException(
"Cannot get 'double' type value from parameter ")
1827 void checkModificationPermission_()
const{
1829 param_attr_ != ParameterAttribute::DEFAULT){
1830 throw ParameterException(
"Modifying special parameters after Lockdown phase is disallowed.");
1855 template <
typename T>
1856 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1857 setVectorItemValueFromString_(T& vec,
1858 const std::vector<uint32_t>& indices,
1859 uint32_t index_level,
1860 const std::string& str,
1861 bool increment_write_count) {
1862 checkModificationPermission_();
1863 assert(indices.size() > 0);
1865 uint32_t idx = indices.at(index_level);
1866 if(idx >= vec.size()){
1870 if(indices.size() - 1 == index_level){
1873 typename T::reference to_set = vec.at(idx);
1874 setFinalVectorItemValueFromString_(to_set, indices, index_level, str);
1875 if(increment_write_count){
1881 typename T::reference next_vec = vec.at(idx);
1882 setVectorItemValueFromString_(next_vec, indices, index_level+1, str, increment_write_count);
1891 template <
typename T>
1892 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
1893 setVectorItemValueFromString_(T& vec,
1894 const std::vector<uint32_t>& indices,
1895 uint32_t index_level,
1896 const std::string& str,
1897 bool increment_write_count) {
1898 checkModificationPermission_();
1902 (void) increment_write_count;
1904 throw ParameterException(
"Cannot set value from string on parameter \"")
1905 <<
getName() <<
"\" which is of type \""
1906 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
1907 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
1916 template <
typename T>
1917 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1918 setFinalVectorItemValueFromString_(T& to_set,
1919 const std::vector<uint32_t>& indices,
1920 uint32_t index_level,
1921 const std::string& str) {
1922 checkModificationPermission_();
1926 throw ParameterException(
"Cannot set value from string on parameter \"")
1927 <<
getName() <<
"\" which is of type \""
1928 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
1929 <<
" levels)" <<
" because this type has more than " << index_level <<
" dimensions";
1945 template <
typename T>
1946 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
1947 setFinalVectorItemValueFromString_(T& to_set,
1948 const std::vector<uint32_t>& indices,
1949 uint32_t index_level,
1950 const std::string& str) {
1951 checkModificationPermission_();
1952 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
1955 to_set = smartLexicalCast<typename bit_reference_to_bool<T>::type>(
this, str, end_pos);
1977 template <
typename T>
1978 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1979 resizeVectorsFromString_(T& vec,
1980 const std::vector<uint32_t>& indices,
1981 uint32_t index_level) {
1982 checkModificationPermission_();
1983 if(index_level == indices.size()){
1987 uint32_t idx = indices.at(index_level);
1988 if(idx >= vec.size()){
1992 if(index_level < indices.size()){
1994 typename T::reference next_vec = vec.at(idx);
1995 resizeVectorsFromString_(next_vec, indices, index_level+1);
2005 template <
typename T>
2006 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
2007 resizeVectorsFromString_(T& vec,
2008 const std::vector<uint32_t>& indices,
2009 uint32_t index_level) {
2010 checkModificationPermission_();
2014 throw ParameterException(
"Cannot resize a vector in parameter \"")
2015 <<
getName() <<
"\" which is of type \""
2016 <<
getTypeName() <<
"\" to contain indices: " << indices <<
" (" << indices.size()
2018 <<
" dimensions. Therefore this index "
2019 "would be within a vector of scalars and this method has no idea with what "
2020 "value to initialize the new elements of said vector. Ues an indices vector "
2033 template <
typename T>
2035 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
2036 clearVectorValue_(T& vec) {
2046 template <
typename T>
2048 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
2049 clearVectorValue_(T& vec) {
2073 template <
typename T>
2074 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2075 getVectorItemValueFromString_(
const T& vec,
2076 const std::vector<uint32_t>& indices,
2077 uint32_t index_level,
2079 assert(indices.size() > 0);
2081 uint32_t idx = indices.at(index_level);
2082 if(idx >= vec.size()){
2083 throw ParameterException(
"Cannot get item from parameter \"")
2084 <<
getName() <<
"\" as a vector which is of type \""
2085 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2086 <<
" levels)" <<
" because this type has only " << vec.size()
2087 <<
" elements at the vector located by indices[" << index_level <<
"]";
2090 if(indices.size() - 1 == index_level){
2093 typename T::const_reference to_get = vec.at(idx);
2094 return getFinalVectorItemValueFromString_(to_get, indices, index_level, peek);
2097 typename T::const_reference next_vec = vec.at(idx);
2098 return getVectorItemValueFromString_(next_vec, indices, index_level+1, peek);
2107 template <
typename T>
2108 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2109 getVectorItemValueFromString_(
const T& vec,
2110 const std::vector<uint32_t>& indices,
2111 uint32_t index_level,
2117 throw ParameterException(
"Cannot get item from parameter \"")
2118 <<
getName() <<
"\" which is of type \""
2119 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2120 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
2129 template <
typename T>
2130 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2131 getFinalVectorItemValueFromString_(
const T& to_get,
2132 const std::vector<uint32_t>& indices,
2133 uint32_t index_level,
2138 throw ParameterException(
"Cannot get value from string on parameter \"")
2139 <<
getName() <<
"\" which is of type \""
2140 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2141 <<
" levels)" <<
" because this type has more than " << index_level <<
" dimensions";
2158 template <
typename T>
2159 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2160 getFinalVectorItemValueFromString_(
const T& to_get,
2161 const std::vector<uint32_t>& indices,
2162 uint32_t index_level,
2164 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
2194 template <
typename T>
2195 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2196 getVectorSize_(
const T& vec,
2197 const std::vector<uint32_t>& indices,
2198 uint32_t index_level,
2203 uint32_t idx = indices.at(index_level);
2204 if(idx >= vec.size()){
2205 throw ParameterException(
"Cannot get size of vector from parameter \"")
2206 <<
getName() <<
"\" as a vector which is of type \""
2207 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2208 <<
" levels)" <<
" because this type has only " << vec.size()
2209 <<
" elements at the vector located by indices[" << index_level <<
"]";
2212 if(indices.size() - 1 == index_level){
2215 typename T::const_reference to_get = vec.at(idx);
2216 return getFinalVectorSize_(to_get, indices, index_level, peek);
2219 typename T::const_reference next_vec = vec.at(idx);
2220 return getVectorSize_(next_vec, indices, index_level+1, peek);
2229 template <
typename T>
2230 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2231 getVectorSize_(
const T& vec,
2232 const std::vector<uint32_t>& indices,
2233 uint32_t index_level,
2239 throw ParameterException(
"Cannot get size of vector from parameter \"")
2240 <<
getName() <<
"\" which is of type \""
2241 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2242 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
2250 template <
typename T>
2251 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2252 getFinalVectorSize_(
const T& to_get,
2253 const std::vector<uint32_t>& indices,
2254 uint32_t index_level,
2259 throw ParameterException(
"Cannot get size of vector from parameter \"")
2260 <<
getName() <<
"\" which is of type \""
2261 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2262 <<
" levels)" <<
" because the in dimension " << index_level
2263 <<
" is a a scalar (not a vector)";
2277 template <
typename T>
2278 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2279 getFinalVectorSize_(
const T& to_get,
2280 const std::vector<uint32_t>& indices,
2281 uint32_t index_level,
2284 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
2290 return to_get.size();
2297 typename std::enable_if<is_vector<T>::value, std::string>
::type
2298 getTypeName_()
const {
2299 std::stringstream ss;
2300 ss <<
"std::vector<";
2301 ss << getTypeName_<typename T::value_type>();
2307 typename std::enable_if<!is_vector<T>::value, std::string>
::type
2308 getTypeName_()
const {
2318 template <
class T,
class C1>
2319 typename std::enable_if<is_vector<C1>::value >
::type
2320 setValueFromString_(
const std::string& str,
bool poke=
false) {
2321 checkModificationPermission_();
2324 throw ParameterException(
"Cannot set value from string on parameter \"")
2325 <<
getName() <<
"\" which is a vector type \""
2330 template <
class T,
class C1>
2331 typename std::enable_if<!is_vector<C1>::value >
::type
2332 setValueFromString_(
const std::string& str,
bool poke=
false) {
2333 checkModificationPermission_();
2343 ValueType old_val = val_;
2356 template <
class T,
class C1>
2357 typename std::enable_if<is_vector<C1>::value >
::type
2358 overrideDefaultFromString_(
const std::string& str) {
2359 checkModificationPermission_();
2361 throw ParameterException(
"Cannot set default from string on parameter \"")
2362 <<
getName() <<
"\" which is a vector type \""
2367 template <
class T,
class C1>
2368 typename std::enable_if<!is_vector<C1>::value >
::type
2369 overrideDefaultFromString_(
const std::string& str) {
2370 checkModificationPermission_();
2381 template <
class T,
class C1>
2382 typename std::enable_if<!is_vector<C1>::value >
::type
2383 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2384 checkModificationPermission_();
2387 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2388 <<
getName() <<
"\" which is a scalar (or string) type \""
2392 template <
class T,
class C1>
2394 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2395 checkModificationPermission_();
2397 for(
const std::string& s : vec){
2404 ValueType old_val = val_;
2415 template <
class T,
class C1>
2417 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2418 checkModificationPermission_();
2421 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2423 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2429 template <
class T,
class C1>
2430 typename std::enable_if<!is_vector<C1>::value >
::type
2431 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2432 checkModificationPermission_();
2435 throw ParameterException(
"Cannot directly override default value from string vector on parameter \"")
2436 <<
getName() <<
"\" which is a scalar (or string) type \""
2440 template <
class T,
class C1>
2442 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2443 checkModificationPermission_();
2445 for(
const std::string& s : vec){
2452 template <
class T,
class C1>
2454 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2455 checkModificationPermission_();
2458 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2460 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2466 template <
class T,
class C1>
2467 typename std::enable_if<!is_vector<C1>::value, std::string>
::type
2468 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2470 ParameterException ex(
"Cannot get value as string at index other than 0 on parameter \"");
2471 ex <<
getName() <<
"\" which is a scalar (or string) type \""
2481 template <
class T,
class C1>
2482 typename std::enable_if<is_vector<C1>::value, std::string>
::type
2483 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2493 template <
class T,
class C1>
2494 typename std::enable_if<!is_vector<C1>::value,
size_t>
::type
2495 getNumValues_(
bool peek)
const {
2502 template <
class T,
class C1>
2503 typename std::enable_if<is_vector<C1>::value,
size_t>
::type
2504 getNumValues_(
bool peek)
const {
2518 template<
typename T,
typename Enable =
void>
2519 struct Dimensionality {
2527 template<
typename T>
2528 struct Dimensionality<T, typename std::enable_if<is_vector<T>::value>
::type> {
2529 enum { value = Dimensionality<typename T::value_type>::value + 1};
2535 template<
typename T>
2536 struct Dimensionality<T, typename std::enable_if<!is_vector<T>::value>
::type> {
2551 <<
" because it is internally a " <<
getTypeName()
2552 <<
". getValueAs must be exact";
2557 template <
typename T>
2559 const std::string& s,
2561 bool allow_recursion,
2565 return utils::smartLexicalCast<T>(s, end_pos, allow_recursion, allow_prefix);
String-to-value helpers and string formatting helpers.
Basic Node framework in sparta device tree composite pattern.
Helpers for printing and populating vectors.
std::string stringize_value(const std::vector< T > &v, DisplayBase base=BASE_DEC, const std::string &string_quote="")
Converting a vector of intrinsic types (and std::string) to a string.
DisplayBase
Numeric display options used by Parameter printing routines.
Smart lexical casting supporting prefixes, separator ignoring, and suffixes.
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
File that contains the macro used to generate the class callbacks.
Basic Node framework in sparta device tree composite pattern.
static const std::string & lookupTypeName()
Determines if there is a known compiler-independent typename for type T.
static bool hasTypeNameFor()
Determines if there is a known compiler-independent typename for type T.
Boolean with a default capable of being changed to the opposite value only. it can never set to the d...
Generic value iterator for a SINGLE parameter which represents values ONLY as std::string.
bool operator!=(const ParameterValueIterator &rhp)
Inequality test.
bool operator==(const ParameterValueIterator &rhp)
Equality test.
ParameterValueIterator(const ParameterBase *pb, size_t idx)
Full Constructor.
ParameterValueIterator(const ParameterValueIterator &rhp)
Copy Constructor.
const std::string operator*() const
Dereference operator.
const ParameterValueIterator & operator++()
Preincrement operator.
const ParameterValueIterator operator++(int i)
Postincrement operator.
Non-templated base class for generic parameter access and iteration.
virtual void overrideDefaultFromStringVector(const std::vector< std::string > &val)=0
Sets the default value of this vector parameter for architecture baseline configuration purposes.
void resetReadCount_() const
Resets the number of reads that wil be reported by getReadCount.
void restoreValueFromDefault()
Attempts to restore the devalue value of this parameter.
virtual std::string stringize(bool pretty=false) const override
Render description of this parameter as a string.
void incrementReadCount_() const
Increment the number of reads that will be reported by getReadCount.
virtual std::string getItemValueFromString(const std::vector< uint32_t > &indices, bool peek=false) const =0
Gets the current value of a single element within this parameter of the parameter as if this paramete...
friend class detail::ExtensionsBase
incrementReadCount_() needed by TreeNode::ExtensionsBase
virtual bool isVector() const =0
Determines whether this Parameter is a vector or a scalar Parameter.
virtual void clearVectorValue()=0
If the parameter is a vector type, clears the value so that it becomes an empty vector (regardless of...
virtual size_t getNumValues(bool peek=false) const =0
Gets the number of elements contained in this Parameter as a Vector.
virtual bool supportsCompression() const
Scalar parameters may compress well, but we cannot really make a strong enough determination without ...
bool isVolatile() const
Is this a volatile parmaeter?
virtual void resizeVectorsFromString(const std::vector< uint32_t > &indices)=0
Attempt to resize a vector nested within this parameter to contain the vector indicated by indices.
const T getValueAs() const
Gets the value of this ParameterBase as a templated type T if this parameter actually contains a valu...
std::string peekItemValueFromString(const std::vector< uint32_t > &indices) const
Wrapper for getItemValueFromString with peek=true.
static void logCurrentBackTrace_()
Log the current backtrace to the global parameters logger.
virtual void overrideDefaultClearVectorValue()=0
If the parameter is a vector type, clears the default value so that it becomes an empty vector (regar...
virtual std::string getValueAsStringAt(size_t idx, bool peek=false) const =0
Gets the current value of this Parameter as a string at a particular index as if this Parameter were ...
virtual void restoreValueFromDefaultImpl_()=0
Implements restoreValueFromDefault.
void setValueFromString(const std::string &str, bool poke=false)
Attempts to assign a value to this non-vector Parameter from a string.
uint32_t getWriteCount() const
Number of times this Parameter has been written after initialization.
size_t peekNumValues() const
Wrapper for getNumValues with peek=true.
virtual bool equals(const ParameterBase &other)=0
Returns true if the value of this equals other.
virtual double getDoubleValue() const =0
Gets the value of this parameter as a double. \thwo Exception if underlying parameter type is not num...
void associateParametersForModification(std::vector< const ParameterBase * > params, const sparta::SpartaHandler &modifier_callback)
Associate a parameter with this parameter for future modification.
void setItemValueFromString(const std::vector< uint32_t > &indices, const std::string &str)
Attempts to assign a value to this nested vector Parameter from a string at a position within the vec...
virtual const_iterator begin() const =0
Gets a beginning const_iterator for values of this Parameter.
virtual uint32_t getDimensionality() const =0
Determines the number of dimensions of this Parameter. A scalar has 0 dimensions. A parameter of type...
void incrementWriteCount_()
Increments the number of writes that will be reported by getWriteCount.
virtual bool isDefaultOverridden() const =0
Has the default value (NOT the current value) for parameter been overridden in any way (including par...
bool isReadOrIgnored() const
Is this parameter ignored or read at least once (barring any reset of the read count or ignore flag)
virtual ~ParameterBase()
Destructor.
virtual bool validateIndependently(std::string &err_names) const =0
Performs validation independently of all other Parameters.
virtual bool isVisibilityAllowed() const =0
Query if this parameter is safe to be displayed via prints, dumps. A parameter should not be displaye...
virtual std::string getDefaultAsString() const =0
Gets the default value of this Parameter as a string.
sparta::SpartaHandler modifier_callback_
Modifier callback called when the parameter is written.
virtual void setValueFromStringVectorImpl_(const std::vector< std::string > &str, bool poke=false)=0
Implements setValueFromStringVectorImpl_.
void setIsVolatile()
Set volatile flag (allows write after read)
void resetWriteCount_()
Resets the number of writes that wil be reported by getWriteCount.
ParameterBase(const std::string &name, const std::string &desc)
Constructor.
virtual void overrideDefaultFromString(const std::string &val)=0
Sets the default value of this non-vector parameter for architecture baseline configuration purposes.
void logLoadedDefaultValue_() const
Log the default loaded to this parameter to the global parameters logger for debugging.
virtual void overrideDefaultItemValueFromString(const std::vector< uint32_t > &indices, const std::string &str)=0
Partially override the default default value in some element at an n-dimensional array specified.
bool isIgnored() const
Has this parameter been ignored (without having read count reset after)
void unread_() const
Mark this parameter as unread and unignored This is used or preloading defaults to parameters and the...
virtual uint32_t getVectorSizeAt(const std::vector< uint32_t > &indices, bool peek=false) const =0
Determines the size of a vector contained by this parameter at the location specified by indices.
virtual void setValueFromStringImpl_(const std::string &s, bool poke=false)=0
Implements setValueFromString.
virtual void overrideDefaultResizeVectorsFromString(const std::vector< uint32_t > &indices)=0
Override the default value by clearing the possibly-nested vector (if this parameter is a vector)....
void logAssignedValue_() const
Log the most recently assigned value given to this parameter to the global parameters logger for debu...
void setValueFromStringVector(const std::vector< std::string > &str, bool poke=false)
Attempts to assign a value to this vector Parameter from a string.
virtual bool validateDependencies(const TreeNode *node, std::string &err_names) const =0
Performs validation based on other Parameters in the Device Tree.
bool usingFinalConfig_()
Ask the simulator if we are using a final config.
void invokeModifierCB_()
Invoke any register callbacks for this parameter. These callbacks are used by Parameters to make modi...
uint32_t peekVectorSizeAt(const std::vector< uint32_t > &indices) const
Wrapper of getVectorSizeAt with peek=true.
std::string string_quote_
The quote sequence for printing strings. Defaults to empty string.
virtual const_iterator end() const =0
Gets an ending const_iterator for values of this Parameter.
void addToSet_(ParameterSet *ps)
Add this parameter to a set - an action which is protected and requires the friendship that the Param...
uint32_t getReadCount() const
Number of times this Parameter has been read after initialization or after the last write (or explici...
virtual void setItemValueFromStringImpl_(const std::vector< uint32_t > &indices, const std::string &str)=0
Implements setItemValueFromStringImpl_.
virtual bool isDefault() const
Is this parameter's current value the default value.
bool ignored_
Has this parameter been ignored. Resettable. Mutable so that it can be accessed from a const Parmeter...
static constexpr char PARAMETER_NODE_TAG[]
Tag added to Parameter nodes.
class sparta::ParameterBase::ParameterValueIterator const_iterator
Generic value iterator for a SINGLE parameter which represents values ONLY as std::string.
void ignore_() const
Flag as ignored. See Parameter<T>::ignore.
virtual std::string getValueAsString() const =0
Gets the current value of this Parameter as a string.
virtual const std::string getTypeName() const =0
Gets the compiler-independent readable type string of the value currently held.
std::string setStringQuote(const std::string &s)
Set the quote sequence for printing strings.
Exception indicating a misconfigured Parameter or invalid Parameter access.
ParameterException(const std::string &reason)
Construct with a default string.
ParameterException(const ParameterException &)=default
Default copy (rule of 3)
ParameterException()=default
Default construction (rule of 3)
ParameterException & operator<<(const T &msg)
Wrapper around SpartaException::operator<<.
virtual ~ParameterException() noexcept
Destructor.
Generic container of Parameters.
Parameter instance, templated to contain only a specific type.
sparta::utils::DisplayBase getNumericDisplayBase() const
Gets the numeric base for displaying the value of this parameter.
void operator=(const Parameter &p)=delete
Copy assignment - deleted explicitly.
virtual void overrideDefaultResizeVectorsFromString(const std::vector< uint32_t > &indices) override final
Override the default value by clearing the possibly-nested vector (if this parameter is a vector)....
ValueType getDefault() const
Returns the default value.
std::enable_if<!std::is_base_of< ParameterBase, T >::value, bool >::type operator==(const T rhp) const
Increments read count.
void operator=(const ValueType &v)
Assigns the specified value to this parameter.
virtual void restoreValueFromDefaultImpl_() override final
Implements restoreValueFromDefault.
void addDependentValidationCallback(T *obj, const std::string &name)
Adds dependency callback to a class member function.
virtual bool isVisibilityAllowed() const override
Query if this parameter is safe to be displayed via prints, dumps. A parameter should not be displaye...
virtual void setItemValueFromStringImpl_(const std::vector< uint32_t > &indices, const std::string &str) override final
Implements setItemValueFromStringImpl_.
virtual void overrideDefaultItemValueFromString(const std::vector< uint32_t > &indices, const std::string &str) override final
Partially override the default default value in some element at an n-dimensional array specified.
uint32_t getVectorSizeAt(const std::vector< uint32_t > &indices, bool peek=false) const override final
Get the size of a nested vector within the parameter located by indices.
std::string getValueAsStringAt(size_t idx, bool peek=false) const override final
Treats this parameter as a vector and gets the value as a string at a specific index....
const ValueType & getValue() const
Gets the current value of this Parameter.
bool validateDependencies(const TreeNode *node, std::string &err_names) const override
Invokes all validation callbacks for a particular node in the device tree and returns true if none of...
ParameterAttribute
ParameterAttribute enum class which describes special attributes of this parameter.
virtual void resizeVectorsFromString(const std::vector< uint32_t > &indices) override final
Attempt to resize a vector nested within this parameter to contain the vector indicated by indices.
virtual void setValueFromStringImpl_(const std::string &str, bool poke=false) override final
Implements setValueFromString.
virtual ParameterBase::const_iterator end() const override final
Get begin iterator.
virtual std::string getDefaultAsString() const override final
Returns the default value as a string, even if type is a vector.
virtual uint32_t getDimensionality() const override final
Determines the number of dimensions of this Parameter. A scalar has 0 dimensions. A parameter of type...
virtual bool isDefaultOverridden() const override final
Has the default value (NOT the current value) for parameter been overridden in any way (including par...
virtual const std::string getTypeName() const override final
Gets the human-readable name of this parameter's type.
bool operator<=(const Parameter< type > &rhp) const
Compares two Parameter objects by value.
std::enable_if<!std::is_base_of< ParameterBase, T >::value, bool >::type operator!=(const T rhp) const
Increments read count.
virtual bool isVector() const override final
Is this parameter a vector?
virtual void clearVectorValue() override final
If the parameter is a vector type, clears the value so that it becomes an empty vector (regardless of...
virtual ParameterBase::const_iterator begin() const override final
Get begin iterator.
const ValueType & peekValue() const
Gets the current value of this Parameter without incrementing the read count. This should be used whe...
std::enable_if<!std::is_base_of< ParameterBase, T >::value, bool >::type operator>=(const T rhp) const
Increments read count.
void ignore() const
Marks this parameter as ignored.
const ValueType & getValue_() const
Iternal getValue_ wrapper which does not increment the read counter.
virtual void setValueFromStringVectorImpl_(const std::vector< std::string > &vec, bool poke=false) override final
Implements setValueFromStringVectorImpl_.
virtual bool equals(const ParameterBase &other) override final
Returns true if the value of this equals other.
Parameter< ValueType > & operator<<(U e)
Helper for constructing vectors.
std::string getItemValueFromString(const std::vector< uint32_t > &indices, bool peek=false) const override final
Override from ParameterBase.
const ValueType & operator()() const
Gets the value currently held by this Parameter.
Parameter(const std::string &name, const ValueType &def, const std::string &doc, bool isvolatile=false)
Construct a parameter.
double getDoubleValue() const override final
Cast value to double if possible. Throw if not.
virtual size_t getNumValues(bool peek=false) const override final
Gets the number of values in this Parameter.
void unread() const
Mark this parameter as unread and unignored.
Parameter(const std::string &name, const ValueType &def, const std::string &doc, ParameterSet *ps, bool isvolatile=false)
Constructor used by the PARAMETER macro.
virtual void overrideDefaultFromStringVector(const std::vector< std::string > &vec) override final
Sets the default value of this vector parameter for architecture baseline configuration purposes.
bool operator>=(const Parameter< T > &rhp) const
Compares two Parameter objects by value.
sparta::utils::DisplayBase setNumericDisplayBase(sparta::utils::DisplayBase base)
Set the numeric base for displaying the value of this parameter.
virtual void overrideDefaultClearVectorValue() override final
If the parameter is a vector type, clears the default value so that it becomes an empty vector (regar...
virtual ~Parameter()=default
Destructor.
std::string getValueAsString() const override final
Returns value as a string, even if type is a vector.
bool operator<(const Parameter< type > &rhp) const
Compares two Parameter objects by value.
bool operator!=(const Parameter< T > &rhp) const
Compares two Parameter objects by value.
ValueType type
Type held by this parameter. This cannot change at run-time.
virtual void overrideDefaultFromString(const std::string &str) override final
Sets the default value of this non-vector parameter for architecture baseline configuration purposes.
bool validateIndependently(std::string &err_names) const override
Performs validation independently of all other Parameters.
bool operator==(const Parameter< T > &rhp) const
Compares two Parameter objects by value.
void addDependentValidationCallback(bool(*method)(ValueType &, const sparta::TreeNode *), const std::string &name)
Adds dependency callback via a global function or lambda.
bool operator>(const Parameter< type > &rhp) const
Compares two Parameter objects by value.
std::enable_if<!std::is_base_of< ParameterBase, T >::value, bool >::type operator>(const T rhp) const
Increments read count.
TreePhase getPhase() const
Gets the trees current phase.
@ TREE_FINALIZED
Tree and all resources have been instantiated. No more configuration/connection allowed.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
SpartaException & operator<<(const T &msg)
Append additional information to the message.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
void markHidden(bool hidden=true)
Marks this TreeNode hidden for the purposes of printint out nodes. This does not make the node inacce...
bool areParametersLocked_() const
This method informs whether the tree is past the lockdown phase for all LOCKED and HIDDEN parameters....
virtual std::string stringize(bool pretty=false) const
Create a string representation of this node.
const std::string & getName() const override
Gets the name of this node.
bool isHidden() const
Is this TreeNode supposed to be hidden during tree printouts This value does not have to be respected...
void addTag(const std::string &tag)
Adds single tag to this node.
Delegate for Parameter validation.
ValidationCheckCallback(bool(*method)(ValueType &, const sparta::TreeNode *), const std::string &name)
Construct delegate with a class member pointer.
ValidationCheckCallback()
Construct with no functionality.
bool operator()(ValueType &val, const TreeNode *node) const
Invoke callback to check given value at the indicated position in the device tree.
static void validateName(const std::string &nm)
ValidationCheckCallback(const std::string &name)
Construct with no functionality and a name.
ValidationCheckCallback(const ValidationCheckCallback< ValueType > &rhp)
Copy Constructor.
Macros for handling exponential backoff.
T smartLexicalCast(const ParameterBase *p, const std::string &s, size_t &end_pos, bool allow_recursion=true, bool allow_prefix=true)
smartLexicalCast wrapper with parameter information added to exceptions
std::string demangle(const std::string &name) noexcept
Demangles a C++ symbol.
void bind(Bus *p1, Bus *p2)
Bind two buses together.
Templated for determining if ValueType is std::vector for use in metaprogramming constructs....
static const bool value
'value' field used by enable_if construct.