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 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 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,
2195 assert(indices.size() > 0);
2197 uint32_t idx = indices.at(index_level);
2198 if(idx >= vec.size()){
2199 throw ParameterException(
"Cannot get size of vector from parameter \"")
2200 <<
getName() <<
"\" as a vector which is of type \""
2201 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2202 <<
" levels)" <<
" because this type has only " << vec.size()
2203 <<
" elements at the vector located by indices[" << index_level <<
"]";
2206 if(indices.size() - 1 == index_level){
2209 typename T::const_reference to_get = vec.at(idx);
2210 return getFinalVectorSize_(to_get, indices, index_level, peek);
2213 typename T::const_reference next_vec = vec.at(idx);
2214 return getVectorSize_(next_vec, indices, index_level+1, peek);
2223 template <
typename T>
2224 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2225 getVectorSize_(
const T& vec,
2226 const std::vector<uint32_t>& indices,
2227 uint32_t index_level,
2233 throw ParameterException(
"Cannot get size of vector from parameter \"")
2234 <<
getName() <<
"\" which is of type \""
2235 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2236 <<
" levels)" <<
" because this type only has " << index_level <<
" dimensions";
2244 template <
typename T>
2245 typename std::enable_if<!is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2246 getFinalVectorSize_(
const T& to_get,
2247 const std::vector<uint32_t>& indices,
2248 uint32_t index_level,
2253 throw ParameterException(
"Cannot get size of vector from parameter \"")
2254 <<
getName() <<
"\" which is of type \""
2255 <<
getTypeName() <<
"\" with indices: " << indices <<
" (" << indices.size()
2256 <<
" levels)" <<
" because the in dimension " << index_level
2257 <<
" is a a scalar (not a vector)";
2271 template <
typename T>
2272 typename std::enable_if<is_vector<typename std::remove_reference<T>::type>::value, uint32_t>
::type
2273 getFinalVectorSize_(
const T& to_get,
2274 const std::vector<uint32_t>& indices,
2275 uint32_t index_level,
2277 assert(indices.size() == 0 || indices.size() - 1 == index_level);
2283 return to_get.size();
2290 typename std::enable_if<is_vector<T>::value, std::string>
::type
2291 getTypeName_()
const {
2292 std::stringstream ss;
2293 ss <<
"std::vector<";
2294 ss << getTypeName_<typename T::value_type>();
2300 typename std::enable_if<!is_vector<T>::value, std::string>
::type
2301 getTypeName_()
const {
2302 if(KeyValue::hasTypeNameFor<T>()){
2303 return KeyValue::lookupTypeName<T>();
2311 template <
class T,
class C1>
2312 typename std::enable_if<is_vector<C1>::value >
::type
2313 setValueFromString_(
const std::string& str,
bool poke=
false) {
2314 checkModificationPermission_();
2317 throw ParameterException(
"Cannot set value from string on parameter \"")
2318 <<
getName() <<
"\" which is a vector type \""
2323 template <
class T,
class C1>
2324 typename std::enable_if<!is_vector<C1>::value >
::type
2325 setValueFromString_(
const std::string& str,
bool poke=
false) {
2326 checkModificationPermission_();
2330 tmp = smartLexicalCast<ValueType>(
this, str, end_pos);
2336 ValueType old_val = val_;
2349 template <
class T,
class C1>
2350 typename std::enable_if<is_vector<C1>::value >
::type
2351 overrideDefaultFromString_(
const std::string& str) {
2352 checkModificationPermission_();
2354 throw ParameterException(
"Cannot set default from string on parameter \"")
2355 <<
getName() <<
"\" which is a vector type \""
2360 template <
class T,
class C1>
2361 typename std::enable_if<!is_vector<C1>::value >
::type
2362 overrideDefaultFromString_(
const std::string& str) {
2363 checkModificationPermission_();
2367 tmp = smartLexicalCast<ValueType>(
this, str, end_pos);
2374 template <
class T,
class C1>
2375 typename std::enable_if<!is_vector<C1>::value >
::type
2376 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2377 checkModificationPermission_();
2380 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2381 <<
getName() <<
"\" which is a scalar (or string) type \""
2385 template <
class T,
class C1>
2387 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2388 checkModificationPermission_();
2390 for(
const std::string& s : vec){
2392 tmpvec.push_back(smartLexicalCast<typename ValueType::value_type>(
this, s, end_pos));
2397 ValueType old_val = val_;
2408 template <
class T,
class C1>
2410 setValueFromStringVector_(
const std::vector<std::string>& vec,
bool poke=
false) {
2411 checkModificationPermission_();
2414 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2416 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2422 template <
class T,
class C1>
2423 typename std::enable_if<!is_vector<C1>::value >
::type
2424 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2425 checkModificationPermission_();
2428 throw ParameterException(
"Cannot directly override default value from string vector on parameter \"")
2429 <<
getName() <<
"\" which is a scalar (or string) type \""
2433 template <
class T,
class C1>
2435 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2436 checkModificationPermission_();
2438 for(
const std::string& s : vec){
2440 tmpvec.push_back(smartLexicalCast<typename ValueType::value_type>(
this, s, end_pos));
2445 template <
class T,
class C1>
2447 overrideDefaultFromStringVector_(
const std::vector<std::string>& vec) {
2448 checkModificationPermission_();
2451 throw ParameterException(
"Cannot directly set value from string vector on parameter \"")
2453 <<
getTypeName() <<
"\". Only 1-dimensional parameters can be set using this method";
2459 template <
class T,
class C1>
2460 typename std::enable_if<!is_vector<C1>::value, std::string>
::type
2461 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2463 ParameterException ex(
"Cannot get value as string at index other than 0 on parameter \"");
2464 ex <<
getName() <<
"\" which is a scalar (or string) type \""
2474 template <
class T,
class C1>
2475 typename std::enable_if<is_vector<C1>::value, std::string>
::type
2476 getValueAsStringAt_(
size_t idx,
bool peek)
const {
2486 template <
class T,
class C1>
2487 typename std::enable_if<!is_vector<C1>::value,
size_t>
::type
2488 getNumValues_(
bool peek)
const {
2495 template <
class T,
class C1>
2496 typename std::enable_if<is_vector<C1>::value,
size_t>
::type
2497 getNumValues_(
bool peek)
const {
2511 template<
typename T,
typename Enable =
void>
2512 struct Dimensionality {
2520 template<
typename T>
2521 struct Dimensionality<T, typename std::enable_if<is_vector<T>::value>
::type> {
2522 enum { value = Dimensionality<typename T::value_type>::value + 1};
2528 template<
typename T>
2529 struct Dimensionality<T, typename std::enable_if<!is_vector<T>::value>
::type> {
2544 <<
" because it is internally a " <<
getTypeName()
2545 <<
". getValueAs must be exact";
2550 template <
typename T>
2552 const std::string& s,
2554 bool allow_recursion,
2558 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.
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 ...
class sparta::ParameterBase::ParameterValueIterator const_iterator
Generic value iterator for a SINGLE parameter which represents values ONLY as std::string.
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.
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.