Version: SMASH-1.5
smash::Configuration::Value Class Reference

#include <configuration.h>

Return type of Configuration::take that automatically determines the target type.

This class is an implementation detail of Configuration and can be ignored by users of Configuration.

Definition at line 345 of file configuration.h.

Collaboration diagram for smash::Configuration::Value:
[legend]

Public Member Functions

 Value (const Value &)=delete
 If you want to copy this you're doing it wrong. More...
 
Valueoperator= (const Value &)=delete
 If you want to copy this you're doing it wrong. More...
 
template<typename T >
convert_for (const T &) const
 Convert the value to the type of the supplied argument. More...
 
template<typename T >
 operator T () const
 This function determines the type it is assigned to and calls YAML::Node::as<T>() with this type. More...
 
template<typename T >
 operator std::vector< T > () const
 Check conversion exceptions. More...
 
template<typename T , size_t N>
 operator std::array< T, N > () const
 Cast array of keys to a std::array of length N. More...
 
 operator ReactionsBitSet () const
 Set ReactionBitSet from configuration values. More...
 
 operator std::set< ThermodynamicQuantity > () const
 Set thermodynamic quantity from configuration values. More...
 
 operator CalculationFrame () const
 Set calculation frame from configuration values. More...
 
 operator FermiMotion () const
 (De-)Activate Fermi motion from configuration values. More...
 
 operator DensityType () const
 Set density type from configuration values. More...
 
 operator ExpansionMode () const
 Set expansion mode from configuration values. More...
 
 operator TimeStepMode () const
 Set time step mode from configuration values. More...
 
 operator BoxInitialCondition () const
 Set initial condition for box setup from configuration values. More...
 
 operator SphereInitialCondition () const
 Set initial condition for sphere setup from configuration values. More...
 
 operator NNbarTreatment () const
 Set treatment of N-Nbar reactions from configuration values. More...
 
 operator Sampling () const
 Set cross-section sampling method from configuration values. More...
 
 operator ThermalizationAlgorithm () const
 Set algorithm for forced thermalization from configuration values. More...
 

Private Member Functions

 Value (const YAML::Node &n, const char *key)
 Constructs the Value wrapper from a YAML::Node. More...
 

Private Attributes

const YAML::Node node_
 a YAML leaf node More...
 
const char *const key_
 The key to be interpreted. More...
 

Friends

class Configuration
 

Constructor & Destructor Documentation

◆ Value() [1/2]

smash::Configuration::Value::Value ( const YAML::Node &  n,
const char *  key 
)
inlineprivate

Constructs the Value wrapper from a YAML::Node.

Note
This constructor must be implicit, otherwise it's impossible to return an rvalue Value object - because the copy constructor is deleted.

Definition at line 359 of file configuration.h.

359  : node_(n), key_(key) {
360  if (!(n.IsScalar() || n.IsSequence() || n.IsMap())) {
361  std::stringstream err;
362  err << "Configuration value for \"" << key
363  << "\" is missing or invalid";
364  throw std::runtime_error(err.str());
365  }
366  }
const char *const key_
The key to be interpreted.
const YAML::Node node_
a YAML leaf node
constexpr int n
Neutron.

◆ Value() [2/2]

smash::Configuration::Value::Value ( const Value )
delete

If you want to copy this you're doing it wrong.

Member Function Documentation

◆ operator=()

Value& smash::Configuration::Value::operator= ( const Value )
delete

If you want to copy this you're doing it wrong.

◆ convert_for()

template<typename T >
T smash::Configuration::Value::convert_for ( const T &  ) const
inline

Convert the value to the type of the supplied argument.

The argument itself is not used other than to determine its type. This function is necessary because in some situations the overload resolution rules lead to the correct conversion becoming hidden. Then you'll see a compiler error with a list of ambiguous constructor calls as candidates. Use this function as a workaround. Example:

// this doesn't compile:
const PdgCode code0(config.take({"key"}));
// this compiles (because PdgCode::operator= is not overloaded), but note
// that it cannot be used in constructor initializer lists:
const PdgCode code1 = config.take({"key"});
// Thus, for class member variables use the following pattern:
class X {
public:
X() : code_(config.take({"key"}).convert_for(code_)) {}
private:
const PdgCode code_;
};

Definition at line 401 of file configuration.h.

401  {
402  return *this;
403  }

◆ operator T()

template<typename T >
smash::Configuration::Value::operator T ( ) const
inline

This function determines the type it is assigned to and calls YAML::Node::as<T>() with this type.

This makes reading values more convenient than calling as<type>() explicitly.

Exceptions
IncorrectTypeInAssignment

Definition at line 414 of file configuration.h.

414  {
415  try {
416  return node_.as<T>();
417  } catch (YAML::TypedBadConversion<T> &e) {
418  throw IncorrectTypeInAssignment(
419  "The value for key \"" + std::string(key_) +
420  "\" cannot be converted to the requested type.");
421  }
422  }
const char *const key_
The key to be interpreted.
const YAML::Node node_
a YAML leaf node

◆ operator std::vector< T >()

template<typename T >
smash::Configuration::Value::operator std::vector< T > ( ) const
inline

Check conversion exceptions.

Exceptions
IncorrectTypeInAssignmentin case type conversion failed.

Definition at line 430 of file configuration.h.

430  {
431  try {
432  return node_.as<std::vector<T>>();
433  } catch (YAML::TypedBadConversion<T> &e) {
434  throw IncorrectTypeInAssignment(
435  "One of the values in the sequence for key \"" + std::string(key_) +
436  "\" failed to convert to the requested type. E.g. [1 2] is a "
437  "sequence of one string \"1 2\" and [1, 2] is a sequence of two "
438  "integers. Often there is just a comma missing in the config "
439  "file.");
440  } catch (YAML::TypedBadConversion<std::vector<T>> &e) {
441  throw IncorrectTypeInAssignment(
442  "The value for key \"" + std::string(key_) +
443  "\" cannot be converted to the requested type. A sequence was "
444  "expected but apparently not found.");
445  }
446  }
const char *const key_
The key to be interpreted.
const YAML::Node node_
a YAML leaf node

◆ operator std::array< T, N >()

template<typename T , size_t N>
smash::Configuration::Value::operator std::array< T, N > ( ) const
inline

Cast array of keys to a std::array of length N.

Returns
Array of std::array type.
Exceptions
IncorrectTypeInAssignmentin case the number of keys does not match the length of the newly generated array.

Definition at line 456 of file configuration.h.

456  {
457  const std::vector<T> vec = operator std::vector<T>();
458  const size_t n_read = vec.size();
459  // Alert if size does not match
460  if (n_read != N) {
461  throw IncorrectTypeInAssignment("Wrong number of values in array \"" +
462  std::string(key_) + "\". Expected " +
463  std::to_string(N) +
464  " values,"
465  " found " +
466  std::to_string(n_read) + ".");
467  }
468  std::array<T, N> arr;
469  std::copy_n(vec.begin(), N, arr.begin());
470  return arr;
471  }
const char *const key_
The key to be interpreted.

◆ operator ReactionsBitSet()

smash::Configuration::Value::operator ReactionsBitSet ( ) const
inline

Set ReactionBitSet from configuration values.

Returns
ReactionBitSet with all included reaction types.
Exceptions
IncorrectTypeInAssignmentin case a reaction type that is not available is provided as a configuration value.

Definition at line 480 of file configuration.h.

480  {
481  const std::vector<std::string> v = operator std::vector<std::string>();
482  ReactionsBitSet s;
483  for (const auto &x : v) {
484  if (x == "All") {
485  s.set();
486  break;
487  } else if (x == "Elastic") {
489  } else if (x == "NN_to_NR") {
491  } else if (x == "NN_to_DR") {
493  } else if (x == "KN_to_KN") {
495  } else if (x == "KN_to_KDelta") {
497  } else if (x == "Strangeness_exchange") {
499  } else {
500  throw IncorrectTypeInAssignment(
501  "The value for key \"" + std::string(key_) +
502  "\" should be \"All\", \"Elastic\", \"NN_to_NR\", \"NN_to_DR\","
503  "\"KN_to_KN\", \"KN_to_KDelta\" or \"strangeness_exchange\","
504  " or any combination of these.");
505  }
506  }
507  return s;
508  }
const char *const key_
The key to be interpreted.
elastic scattering: particles remain the same, only momenta change
std::bitset< 6 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.

◆ operator std::set< ThermodynamicQuantity >()

smash::Configuration::Value::operator std::set< ThermodynamicQuantity > ( ) const
inline

Set thermodynamic quantity from configuration values.

Returns
Set of thermodynamic quantity.
Exceptions
IncorrectTypeInAssignmentin case a thermodynamic quantity that is not available is provided as a configuration value.

Definition at line 517 of file configuration.h.

517  {
518  const std::vector<std::string> v = operator std::vector<std::string>();
519  std::set<ThermodynamicQuantity> s;
520  for (const auto &x : v) {
521  if (x == "rho_eckart") {
523  } else if (x == "tmn") {
524  s.insert(ThermodynamicQuantity::Tmn);
525  } else if (x == "tmn_landau") {
527  } else if (x == "landau_velocity") {
529  } else {
530  throw IncorrectTypeInAssignment(
531  "The value for key \"" + std::string(key_) +
532  "\" should be \"rho_eckart\", \"tmn\""
533  ", \"tmn_landau\" or \"landau_velocity\".");
534  }
535  }
536  return s;
537  }
const char *const key_
The key to be interpreted.

◆ operator CalculationFrame()

smash::Configuration::Value::operator CalculationFrame ( ) const
inline

Set calculation frame from configuration values.

Returns
string of calculation frame.
Exceptions
IncorrectTypeInAssignmentin case a calculation frame that is not available is provided as a configuration value.

Definition at line 546 of file configuration.h.

546  {
547  const std::string s = operator std::string();
548  if (s == "center of velocity") {
550  }
551  if (s == "center of mass") {
553  }
554  if (s == "fixed target") {
556  }
557  throw IncorrectTypeInAssignment(
558  "The value for key \"" + std::string(key_) +
559  "\" should be \"center of velocity\" or \"center of mass\" "
560  "or \"fixed target\".");
561  }
const char *const key_
The key to be interpreted.

◆ operator FermiMotion()

smash::Configuration::Value::operator FermiMotion ( ) const
inline

(De-)Activate Fermi motion from configuration values.

Returns
Fermi motion setup.
Exceptions
IncorrectTypeInAssignmentin case a Fermi motion value that is not available is provided as a configuration value.

Definition at line 570 of file configuration.h.

570  {
571  const std::string s = operator std::string();
572  if (s == "off") {
573  return FermiMotion::Off;
574  }
575  if (s == "on") {
576  return FermiMotion::On;
577  }
578  if (s == "frozen") {
579  return FermiMotion::Frozen;
580  }
581  throw IncorrectTypeInAssignment(
582  "The value for key \"" + std::string(key_) +
583  "\" should be \"off\" or \"on\" or \"frozen\".");
584  }
const char *const key_
The key to be interpreted.
Don&#39;t use fermi motion.
Use fermi motion without potentials.
Use fermi motion in combination with potentials.

◆ operator DensityType()

smash::Configuration::Value::operator DensityType ( ) const
inline

Set density type from configuration values.

Returns
Density type.
Exceptions
IncorrectTypeInAssignmentin case a density type that is not available is provided as a configuration value.

Definition at line 593 of file configuration.h.

593  {
594  const std::string s = operator std::string();
595  if (s == "hadron") {
596  return DensityType::Hadron;
597  }
598  if (s == "baryon") {
599  return DensityType::Baryon;
600  }
601  if (s == "baryonic isospin") {
603  }
604  if (s == "pion") {
605  return DensityType::Pion;
606  }
607  if (s == "none") {
608  return DensityType::None;
609  }
610  throw IncorrectTypeInAssignment("The value for key \"" +
611  std::string(key_) +
612  "\" should be \"hadron\" or \"baryon\" "
613  "or \"baryonic isospin\" or \"pion\" "
614  "or \"none\".");
615  }
const char *const key_
The key to be interpreted.

◆ operator ExpansionMode()

smash::Configuration::Value::operator ExpansionMode ( ) const
inline

Set expansion mode from configuration values.

Returns
Expansion mode.
Exceptions
IncorrectTypeInAssignmentin case an expansion mode that is not available is provided as a configuration value.

Definition at line 624 of file configuration.h.

624  {
625  const std::string s = operator std::string();
626  if (s == "NoExpansion") {
628  }
629  if (s == "MasslessFRW") {
631  }
632  if (s == "MassiveFRW") {
634  }
635  if (s == "Exponential") {
637  }
638  throw IncorrectTypeInAssignment(
639  "The value for key \"" + std::string(key_) +
640  "\" should be \"NoExpansion\", \"MasslessFRW\"," +
641  "\"MassiveFRW\" or \"Exponential\".");
642  }
const char *const key_
The key to be interpreted.

◆ operator TimeStepMode()

smash::Configuration::Value::operator TimeStepMode ( ) const
inline

Set time step mode from configuration values.

Returns
time step mode.
Exceptions
IncorrectTypeInAssignmentin case a time step mode that is not available is provided as a configuration value.

Definition at line 651 of file configuration.h.

651  {
652  const std::string s = operator std::string();
653  if (s == "None") {
654  return TimeStepMode::None;
655  }
656  if (s == "Fixed") {
657  return TimeStepMode::Fixed;
658  }
659  throw IncorrectTypeInAssignment("The value for key \"" +
660  std::string(key_) +
661  "\" should be \"None\" or \"Fixed\".");
662  }
const char *const key_
The key to be interpreted.
Use fixed time step.

◆ operator BoxInitialCondition()

smash::Configuration::Value::operator BoxInitialCondition ( ) const
inline

Set initial condition for box setup from configuration values.

Returns
Initial condition for box setup.
Exceptions
IncorrectTypeInAssignmentin case an initial conditions that is not available is provided as a configuration value.

Definition at line 671 of file configuration.h.

671  {
672  const std::string s = operator std::string();
673  if (s == "thermal momenta") {
675  }
676  if (s == "peaked momenta") {
678  }
679  throw IncorrectTypeInAssignment(
680  "The value for key \"" + std::string(key_) +
681  "\" should be \"thermal momenta\" or \"peaked momenta\".");
682  }
const char *const key_
The key to be interpreted.

◆ operator SphereInitialCondition()

smash::Configuration::Value::operator SphereInitialCondition ( ) const
inline

Set initial condition for sphere setup from configuration values.

Returns
Initial condition for sphere setup.
Exceptions
IncorrectTypeInAssignmentin case an initial conditions that is not available is provided as a configuration value.

Definition at line 691 of file configuration.h.

691  {
692  const std::string s = operator std::string();
693  if (s == "thermal momenta") {
695  }
696  if (s == "IC_ES") {
698  }
699  if (s == "IC_1M") {
701  }
702  if (s == "IC_2M") {
704  }
705  if (s == "IC_Massive") {
707  }
708  throw IncorrectTypeInAssignment(
709  "The value for key \"" + std::string(key_) +
710  "\" should be \"thermal momenta\", \"IC_ES\", " +
711  "\"IC_1M\", \"IC_2M\" or" + "\"IC_Massive\".");
712  }
const char *const key_
The key to be interpreted.

◆ operator NNbarTreatment()

smash::Configuration::Value::operator NNbarTreatment ( ) const
inline

Set treatment of N-Nbar reactions from configuration values.

Returns
N-Nbar treatment.
Exceptions
IncorrectTypeInAssignmentin case an N-Nbar treatment that is not available is provided as a configuration value.

Definition at line 721 of file configuration.h.

721  {
722  const std::string s = operator std::string();
723  if (s == "no annihilation") {
725  }
726  if (s == "resonances") {
728  }
729  if (s == "strings") {
731  }
732  throw IncorrectTypeInAssignment(
733  "The value for key \"" + std::string(key_) + "\" should be " +
734  "\"no annihilation\", \"detailed balance\", or \"strings\".");
735  }
const char *const key_
The key to be interpreted.
Use string fragmentation.
Use intermediate Resonances.

◆ operator Sampling()

smash::Configuration::Value::operator Sampling ( ) const
inline

Set cross-section sampling method from configuration values.

Returns
Sampling method of cross-section.
Exceptions
IncorrectTypeInAssignmentin case a sampling method that is not available is provided as a configuration value.

Definition at line 744 of file configuration.h.

744  {
745  const std::string s = operator std::string();
746  if (s == "quadratic") {
747  return Sampling::Quadratic;
748  }
749  if (s == "custom") {
750  return Sampling::Custom;
751  }
752  if (s == "uniform") {
753  return Sampling::Uniform;
754  }
755  throw IncorrectTypeInAssignment(
756  "The value for key \"" + std::string(key_) +
757  "\" should be \"quadratic\", \"uniform\" or \"custom\".");
758  }
const char *const key_
The key to be interpreted.
Sample from uniform distribution.
Sample from custom, user-defined distribution.
Sample from areal / quadratic distribution.

◆ operator ThermalizationAlgorithm()

smash::Configuration::Value::operator ThermalizationAlgorithm ( ) const
inline

Set algorithm for forced thermalization from configuration values.

Returns
Algorithm for forced thermalization.
Exceptions
IncorrectTypeInAssignmentin case a thermalization algorithm that is not available is provided as a configuration value.

Definition at line 767 of file configuration.h.

767  {
768  const std::string s = operator std::string();
769  if (s == "mode sampling") {
771  }
772  if (s == "biased BF") {
774  }
775  if (s == "unbiased BF") {
777  }
778  throw IncorrectTypeInAssignment(
779  "The value for key \"" + std::string(key_) +
780  "\" should be \"mode sampling\", \"biased BF\" or \"unbiased BF\".");
781  }
const char *const key_
The key to be interpreted.

Friends And Related Function Documentation

◆ Configuration

friend class Configuration
friend

Definition at line 346 of file configuration.h.

Member Data Documentation

◆ node_

const YAML::Node smash::Configuration::Value::node_
private

a YAML leaf node

Todo:
(steinberg) What is that?

Definition at line 349 of file configuration.h.

◆ key_

const char* const smash::Configuration::Value::key_
private

The key to be interpreted.

Definition at line 351 of file configuration.h.


The documentation for this class was generated from the following file: