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;
874 <<
" after reading it unless it is a volatile parameter";
880 <<
getLocation() <<
" because it is already finalized";
954 mutable uint32_t reads_;
959 std::vector<const ParameterBase *> associated_params_;
987 template<
class ValueType>
997 template<
class T,
bool (T::*TMethod)(ValueType&, const sparta::TreeNode*)>
999 const std::string& name)
1003 vcc.callback_ = std::bind(TMethod, obj, std::placeholders::_1, std::placeholders::_2);
1034 const std::string& name) :
1035 callback_(std::
bind(method, std::placeholders::_1, std::placeholders::_2)),
1044 name_(
"<uninitialized>")
1059 callback_(rhp.callback_),
1067 callback_ = rhp.callback_;
1071 std::string getName()
const
1079 return callback_(val, node);
1086 if(nm.find(
',') != std::string::npos){
1088 ex << nm <<
"\" contains a comma, which is not permitted";
1096 static bool doNothing_(ValueType& val,
const TreeNode* node)
1112 template <
typename ValueType>
1135 std::vector<ValidationCheckCallback<ValueType> > bounds_;
1136 std::vector<ValidationCheckCallback<ValueType> > dependencies_;
1141 using value_type = ValueType;
1156 const ValueType& def,
1157 const std::string& doc,
1158 bool isvolatile =
false) :
1162 disp_base_(
sparta::utils::BASE_DEC)
1179 const ValueType& def,
1180 const std::string& doc,
1182 bool isvolatile =
false) :
1185 sparta_assert(ps,
"Must construct parameter " << name <<
" with valid ParameterSet");
1190 const ValueType& def,
1191 const std::string& doc,
1194 bool isvolatile =
false) :
1197 sparta_assert(ps,
"Must construct parameter " << name <<
" with valid ParameterSet");
1199 if(param_attr_ == ParameterAttribute::HIDDEN) {
1225 template<
class T,
bool (T::*TMethod)(ValueType&, const sparta::TreeNode*)>
1255 const std::string& name)
1266 return Parameter::template getTypeName_<ValueType>();
1282 return sparta::utils::stringize_value(def_val_, disp_base_,
string_quote_);
1294 return sparta::utils::stringize_value(val_, disp_base_,
"\"");
1296 return sparta::utils::stringize_value(val_, disp_base_,
string_quote_);
1308 return Parameter::template getValueAsStringAt_<ValueType, ValueType>(idx, peek);
1317 bool peek=
false) const override final {
1318 if(indices.size() == 0){
1320 return getFinalVectorItemValueFromString_(val_, indices, 0, peek);
1324 return getVectorItemValueFromString_(val_, indices, 0, peek);
1334 bool peek=
false) const override final {
1335 if(indices.size() == 0){
1337 return getFinalVectorSize_(val_, indices, 0, peek);
1341 return getVectorSize_(val_, indices, 0, peek);
1348 operator const ValueType&()
const {
1423 return getDoubleValue_<ValueType>();
1434 return Parameter::template getNumValues_<ValueType, ValueType>(peek);
1447 return Dimensionality<ValueType>::value;
1519 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1521 return getValue() == (ValueType)rhp;
1526 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1528 return getValue() != (ValueType)rhp;
1533 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1535 return getValue() > (ValueType)rhp;
1540 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1542 return getValue() >= (ValueType)rhp;
1547 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1549 return getValue() < (ValueType)rhp;
1554 typename std::enable_if<!std::is_base_of<ParameterBase, T>::value,
bool>
::type
1556 return getValue() <= (ValueType)rhp;
1586 checkModificationPermission_();
1592 static bool been_warned =
false;
1594 std::cout <<
"WARNING: A simulator override for parameter " <<
getLocation()
1595 <<
" (using operator=) was performed and ignored. This is because"
1596 <<
" the simulator is using --read-final-config. This is your"
1597 <<
" first and last warning." << std::endl;
1604 ValueType old_val = val_;
1617 return default_override_;
1621 Parameter::template overrideDefaultFromString_<ValueType, ValueType>(str);
1623 "Cannot override default on parameter if read count is > 0. "
1625 default_override_ =
true;
1629 Parameter::template overrideDefaultFromStringVector_<ValueType, ValueType>(vec);
1631 "Cannot override default on parameter if read count is > 0. "
1633 default_override_ =
true;
1637 const std::string& str)
override final {
1638 if(indices.size() == 0){
1640 Parameter::template overrideDefaultFromString_<ValueType, ValueType>(str);
1643 const bool incr_write_count =
false;
1644 setVectorItemValueFromString_(def_val_, indices, 0, str, incr_write_count);
1646 default_override_ =
true;
1650 if(indices.size() == 0){
1654 resizeVectorsFromString_(def_val_, indices, 0);
1658 clearVectorValue_(def_val_);
1663 checkModificationPermission_();
1665 "Parameter " <<
getLocation() <<
" must not have been read when restoring "
1666 "a value from the default. This is a write");
1678 if(indices.size() == 0){
1682 resizeVectorsFromString_(val_, indices, 0);
1686 clearVectorValue_(val_);
1694 checkModificationPermission_();
1730 bool success =
true;
1733 if(!vcb(val, node)){
1734 err_names += vcb.getName() +
",";
1755 return Parameter::template operator_insert_<U, ValueType>(e);
1764 return ((param_attr_ == ParameterAttribute::HIDDEN) and
1770 template <
class U,
class C1>
1772 operator_insert_(U e) {
1773 checkModificationPermission_();
1775 val_.push_back((
typename ValueType::value_type) e);
1780 Parameter::template setValueFromString_<ValueType, ValueType>(str, poke);
1784 Parameter::template setValueFromStringVector_<ValueType, ValueType>(vec, poke);
1788 const std::string& str)
override final {
1789 if(indices.size() == 0){
1791 Parameter::template setValueFromString_<ValueType, ValueType>(str);
1794 const bool incr_write_count =
true;
1795 setVectorItemValueFromString_(val_, indices, 0, str, incr_write_count);
1804 template <
typename T>
1805 typename std::enable_if<std::is_arithmetic<T>::value,
double>
::type
1806 getDoubleValue_()
const {
1810 template <
typename T>
1811 typename std::enable_if<!std::is_arithmetic<T>::value,
double>
::type
1812 getDoubleValue_()
const {
1813 throw SpartaException(
"Cannot get 'double' type value from parameter ")
1822 void checkModificationPermission_()
const{
1824 param_attr_ != ParameterAttribute::DEFAULT){
1825 throw ParameterException(
"Modifying special parameters after Lockdown phase is disallowed.");
1850 template <
typename T>
1851 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1852 setVectorItemValueFromString_(T& vec,
1853 const std::vector<uint32_t>& indices,
1854 uint32_t index_level,
1855 const std::string& str,
1856 bool increment_write_count) {
1857 checkModificationPermission_();
1858 assert(indices.size() > 0);
1860 uint32_t idx = indices.at(index_level);
1861 if(idx >= vec.size()){
1865 if(indices.size() - 1 == index_level){
1868 typename T::reference to_set = vec.at(idx);
1869 setFinalVectorItemValueFromString_(to_set, indices, index_level, str);
1870 if(increment_write_count){
1876 typename T::reference next_vec = vec.at(idx);
1877 setVectorItemValueFromString_(next_vec, indices, index_level+1, str, increment_write_count);
1886 template <
typename T>
1887 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
1888 setVectorItemValueFromString_(T& vec,
1889 const std::vector<uint32_t>& indices,
1890 uint32_t index_level,
1891 const std::string& str,
1892 bool increment_write_count) {
1893 checkModificationPermission_();
1897 (void) increment_write_count;
1899 throw ParameterException(
"Cannot set value from string on parameter \"")
1900 <<
getName() <<
"\" which is of type \""
1901 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
1902 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
1911 template <
typename T>
1912 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1913 setFinalVectorItemValueFromString_(T& to_set,
1914 const std::vector<uint32_t>& indices,
1915 uint32_t index_level,
1916 const std::string& str) {
1917 checkModificationPermission_();
1921 throw ParameterException(
"Cannot set value from string on parameter \"")
1922 <<
getName() <<
"\" which is of type \""
1923 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
1924 <<
" levels)" <<
" because this type has more than " << index_level <<
" dimensions";
1940 template <
typename T>
1941 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
1942 setFinalVectorItemValueFromString_(T& to_set,
1943 const std::vector<uint32_t>& indices,
1944 uint32_t index_level,
1945 const std::string& str) {
1946 checkModificationPermission_();
1947 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
1950 to_set = smartLexicalCast<typename bit_reference_to_bool<T>::type>(
this, str, end_pos);
1972 template <
typename T>
1973 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
1974 resizeVectorsFromString_(T& vec,
1975 const std::vector<uint32_t>& indices,
1976 uint32_t index_level) {
1977 checkModificationPermission_();
1978 if(index_level == indices.size()){
1982 uint32_t idx = indices.at(index_level);
1983 if(idx >= vec.size()){
1987 if(index_level < indices.size()){
1989 typename T::reference next_vec = vec.at(idx);
1990 resizeVectorsFromString_(next_vec, indices, index_level+1);
2000 template <
typename T>
2001 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
2002 resizeVectorsFromString_(T& vec,
2003 const std::vector<uint32_t>& indices,
2004 uint32_t index_level) {
2005 checkModificationPermission_();
2009 throw ParameterException(
"Cannot resize a vector in parameter \"")
2010 <<
getName() <<
"\" which is of type \""
2011 <<
getTypeName() <<
"\" to contain indices: " << indices <<
" (" << indices.size()
2013 <<
" dimensions. Therefore this index "
2014 "would be within a vector of scalars and this method has no idea with what "
2015 "value to initialize the new elements of said vector. Ues an indices vector "
2028 template <
typename T>
2030 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value>
::type
2031 clearVectorValue_(T& vec) {
2041 template <
typename T>
2043 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value>
::type
2044 clearVectorValue_(T& vec) {
2068 template <
typename T>
2069 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2070 getVectorItemValueFromString_(
const T& vec,
2071 const std::vector<uint32_t>& indices,
2072 uint32_t index_level,
2074 assert(indices.size() > 0);
2076 uint32_t idx = indices.at(index_level);
2077 if(idx >= vec.size()){
2078 throw ParameterException(
"Cannot get item from parameter \"")
2079 <<
getName() <<
"\" as a vector which is of type \""
2080 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2081 <<
" levels)" <<
" because this type has only " << vec.size()
2082 <<
" elements at the vector located by indices[" << index_level <<
"]";
2085 if(indices.size() - 1 == index_level){
2088 typename T::const_reference to_get = vec.at(idx);
2089 return getFinalVectorItemValueFromString_(to_get, indices, index_level, peek);
2092 typename T::const_reference next_vec = vec.at(idx);
2093 return getVectorItemValueFromString_(next_vec, indices, index_level+1, peek);
2102 template <
typename T>
2103 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2104 getVectorItemValueFromString_(
const T& vec,
2105 const std::vector<uint32_t>& indices,
2106 uint32_t index_level,
2112 throw ParameterException(
"Cannot get item from parameter \"")
2113 <<
getName() <<
"\" which is of type \""
2114 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2115 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
2124 template <
typename T>
2125 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2126 getFinalVectorItemValueFromString_(
const T& to_get,
2127 const std::vector<uint32_t>& indices,
2128 uint32_t index_level,
2133 throw ParameterException(
"Cannot get value from string on parameter \"")
2134 <<
getName() <<
"\" which is of type \""
2135 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2136 <<
" levels)" <<
" because this type has more than " << index_level <<
" dimensions";
2153 template <
typename T>
2154 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, std::string>
::type
2155 getFinalVectorItemValueFromString_(
const T& to_get,
2156 const std::vector<uint32_t>& indices,
2157 uint32_t index_level,
2159 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
2189 template <
typename T>
2190 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2191 getVectorSize_(
const T& vec,
2192 const std::vector<uint32_t>& indices,
2193 uint32_t index_level,
2198 uint32_t idx = indices.at(index_level);
2199 if(idx >= vec.size()){
2200 throw ParameterException(
"Cannot get size of vector from parameter \"")
2201 <<
getName() <<
"\" as a vector which is of type \""
2202 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2203 <<
" levels)" <<
" because this type has only " << vec.size()
2204 <<
" elements at the vector located by indices[" << index_level <<
"]";
2207 if(indices.size() - 1 == index_level){
2210 typename T::const_reference to_get = vec.at(idx);
2211 return getFinalVectorSize_(to_get, indices, index_level, peek);
2214 typename T::const_reference next_vec = vec.at(idx);
2215 return getVectorSize_(next_vec, indices, index_level+1, peek);
2224 template <
typename T>
2225 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2226 getVectorSize_(
const T& vec,
2227 const std::vector<uint32_t>& indices,
2228 uint32_t index_level,
2234 throw ParameterException(
"Cannot get size of vector from parameter \"")
2235 <<
getName() <<
"\" which is of type \""
2236 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2237 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
2245 template <
typename T>
2246 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2247 getFinalVectorSize_(
const T& to_get,
2248 const std::vector<uint32_t>& indices,
2249 uint32_t index_level,
2254 throw ParameterException(
"Cannot get size of vector from parameter \"")
2255 <<
getName() <<
"\" which is of type \""
2256 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2257 <<
" levels)" <<
" because the in dimension " << index_level
2258 <<
" is a a scalar (not a vector)";
2272 template <
typename T>
2273 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2274 getFinalVectorSize_(
const T& to_get,
2275 const std::vector<uint32_t>& indices,
2276 uint32_t index_level,
2279 sparta_assert(indices.size() == 0 || indices.size() - 1 == index_level);
2285 return to_get.size();
2292 typename std::enable_if<is_vector<T>::value, std::string>
::type
2293 getTypeName_()
const {
2294 std::stringstream ss;
2295 ss <<
"std::vector<";
2296 ss << getTypeName_<typename T::value_type>();
2302 typename std::enable_if<!is_vector<T>::value, std::string>
::type
2303 getTypeName_()
const {
2313 template <
class T,
class C1>
2314 typename std::enable_if<is_vector<C1>::value >
::type
2315 setValueFromString_(
const std::string& str,
bool poke=
false) {
2316 checkModificationPermission_();
2319 throw ParameterException(
"Cannot set value from string on parameter \"")
2320 <<
getName() <<
"\" which is a vector type \""
2325 template <
class T,
class C1>
2326 typename std::enable_if<!is_vector<C1>::value >
::type
2327 setValueFromString_(
const std::string& str,
bool poke=
false) {
2328 checkModificationPermission_();
2338 ValueType old_val = val_;
2351 template <
class T,
class C1>
2352 typename std::enable_if<is_vector<C1>::value >
::type
2353 overrideDefaultFromString_(
const std::string& str) {
2354 checkModificationPermission_();
2356 throw ParameterException(
"Cannot set default from string on parameter \"")
2357 <<
getName() <<
"\" which is a vector type \""
2362 template <
class T,
class C1>
2363 typename std::enable_if<!is_vector<C1>::value >
::type
2364 overrideDefaultFromString_(
const std::string& str) {
2365 checkModificationPermission_();
2376 template <
class T,
class C1>
2377 typename std::enable_if<!is_vector<C1>::value >
::type
2378 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2379 checkModificationPermission_();
2382 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2383 <<
getName() <<
"\" which is a scalar (or string) type \""
2387 template <
class T,
class C1>
2389 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2390 checkModificationPermission_();
2392 for(
const std::string& s : vec){
2399 ValueType old_val = val_;
2410 template <
class T,
class C1>
2412 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2413 checkModificationPermission_();
2416 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2418 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2424 template <
class T,
class C1>
2425 typename std::enable_if<!is_vector<C1>::value >
::type
2426 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2427 checkModificationPermission_();
2430 throw ParameterException(
"Cannot directly override default value from string vector on parameter \"")
2431 <<
getName() <<
"\" which is a scalar (or string) type \""
2435 template <
class T,
class C1>
2437 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2438 checkModificationPermission_();
2440 for(
const std::string& s : vec){
2447 template <
class T,
class C1>
2449 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2450 checkModificationPermission_();
2453 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2455 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2461 template <
class T,
class C1>
2462 typename std::enable_if<!is_vector<C1>::value, std::string>
::type
2463 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2465 ParameterException ex(
"Cannot get value as string at index other than 0 on parameter \"");
2466 ex <<
getName() <<
"\" which is a scalar (or string) type \""
2476 template <
class T,
class C1>
2477 typename std::enable_if<is_vector<C1>::value, std::string>
::type
2478 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2488 template <
class T,
class C1>
2489 typename std::enable_if<!is_vector<C1>::value,
size_t>
::type
2490 getNumValues_(
bool peek)
const {
2497 template <
class T,
class C1>
2498 typename std::enable_if<is_vector<C1>::value,
size_t>
::type
2499 getNumValues_(
bool peek)
const {
2513 template<
typename T,
typename Enable =
void>
2514 struct Dimensionality {
2522 template<
typename T>
2523 struct Dimensionality<T, typename std::enable_if<is_vector<T>::value>
::type> {
2524 enum { value = Dimensionality<typename T::value_type>::value + 1};
2530 template<
typename T>
2531 struct Dimensionality<T, typename std::enable_if<!is_vector<T>::value>
::type> {
2546 <<
" because it is internally a " <<
getTypeName()
2547 <<
". getValueAs must be exact";
2552 template <
typename T>
2554 const std::string& s,
2556 bool allow_recursion,
2560 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...
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.