Version: SMASH-1.6
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

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.
smash::Configuration::Value::Value ( const Value )
delete

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

Member Function Documentation

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

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

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  }
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
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
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.
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.
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 if (x == "j_QBS") {
531  } else {
532  throw IncorrectTypeInAssignment(
533  "The value for key \"" + std::string(key_) +
534  "\" should be \"rho_eckart\", \"tmn\""
535  ", \"tmn_landau\", \"landau_velocity\" or \"j_QBS\".");
536  }
537  }
538  return s;
539  }
const char *const key_
The key to be interpreted.
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 548 of file configuration.h.

548  {
549  const std::string s = operator std::string();
550  if (s == "center of velocity") {
552  }
553  if (s == "center of mass") {
555  }
556  if (s == "fixed target") {
558  }
559  throw IncorrectTypeInAssignment(
560  "The value for key \"" + std::string(key_) +
561  "\" should be \"center of velocity\" or \"center of mass\" "
562  "or \"fixed target\".");
563  }
const char *const key_
The key to be interpreted.
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 572 of file configuration.h.

572  {
573  const std::string s = operator std::string();
574  if (s == "off") {
575  return FermiMotion::Off;
576  }
577  if (s == "on") {
578  return FermiMotion::On;
579  }
580  if (s == "frozen") {
581  return FermiMotion::Frozen;
582  }
583  throw IncorrectTypeInAssignment(
584  "The value for key \"" + std::string(key_) +
585  "\" should be \"off\" or \"on\" or \"frozen\".");
586  }
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.
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 595 of file configuration.h.

595  {
596  const std::string s = operator std::string();
597  if (s == "hadron") {
598  return DensityType::Hadron;
599  }
600  if (s == "baryon") {
601  return DensityType::Baryon;
602  }
603  if (s == "baryonic isospin") {
605  }
606  if (s == "pion") {
607  return DensityType::Pion;
608  }
609  if (s == "total isospin") {
611  }
612  if (s == "none") {
613  return DensityType::None;
614  }
615  throw IncorrectTypeInAssignment("The value for key \"" +
616  std::string(key_) +
617  "\" should be \"hadron\" or \"baryon\" "
618  "or \"baryonic isospin\" or \"pion\" "
619  "or \"none\".");
620  }
const char *const key_
The key to be interpreted.
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 629 of file configuration.h.

629  {
630  const std::string s = operator std::string();
631  if (s == "NoExpansion") {
633  }
634  if (s == "MasslessFRW") {
636  }
637  if (s == "MassiveFRW") {
639  }
640  if (s == "Exponential") {
642  }
643  throw IncorrectTypeInAssignment(
644  "The value for key \"" + std::string(key_) +
645  "\" should be \"NoExpansion\", \"MasslessFRW\"," +
646  "\"MassiveFRW\" or \"Exponential\".");
647  }
const char *const key_
The key to be interpreted.
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 656 of file configuration.h.

656  {
657  const std::string s = operator std::string();
658  if (s == "None") {
659  return TimeStepMode::None;
660  }
661  if (s == "Fixed") {
662  return TimeStepMode::Fixed;
663  }
664  throw IncorrectTypeInAssignment("The value for key \"" +
665  std::string(key_) +
666  "\" should be \"None\" or \"Fixed\".");
667  }
const char *const key_
The key to be interpreted.
Use fixed time step.
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 676 of file configuration.h.

676  {
677  const std::string s = operator std::string();
678  if (s == "thermal momenta") {
680  }
681  if (s == "peaked momenta") {
683  }
684  throw IncorrectTypeInAssignment(
685  "The value for key \"" + std::string(key_) +
686  "\" should be \"thermal momenta\" or \"peaked momenta\".");
687  }
const char *const key_
The key to be interpreted.
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 696 of file configuration.h.

696  {
697  const std::string s = operator std::string();
698  if (s == "thermal momenta") {
700  }
701  if (s == "IC_ES") {
703  }
704  if (s == "IC_1M") {
706  }
707  if (s == "IC_2M") {
709  }
710  if (s == "IC_Massive") {
712  }
713  throw IncorrectTypeInAssignment(
714  "The value for key \"" + std::string(key_) +
715  "\" should be \"thermal momenta\", \"IC_ES\", " +
716  "\"IC_1M\", \"IC_2M\" or" + "\"IC_Massive\".");
717  }
const char *const key_
The key to be interpreted.
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 726 of file configuration.h.

726  {
727  const std::string s = operator std::string();
728  if (s == "no annihilation") {
730  }
731  if (s == "resonances") {
733  }
734  if (s == "strings") {
736  }
737  throw IncorrectTypeInAssignment(
738  "The value for key \"" + std::string(key_) + "\" should be " +
739  "\"no annihilation\", \"detailed balance\", or \"strings\".");
740  }
const char *const key_
The key to be interpreted.
Use string fragmentation.
Use intermediate Resonances.
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 749 of file configuration.h.

749  {
750  const std::string s = operator std::string();
751  if (s == "quadratic") {
752  return Sampling::Quadratic;
753  }
754  if (s == "custom") {
755  return Sampling::Custom;
756  }
757  if (s == "uniform") {
758  return Sampling::Uniform;
759  }
760  throw IncorrectTypeInAssignment(
761  "The value for key \"" + std::string(key_) +
762  "\" should be \"quadratic\", \"uniform\" or \"custom\".");
763  }
const char *const key_
The key to be interpreted.
Sample from uniform distribution.
Sample from custom, user-defined distribution.
Sample from areal / quadratic distribution.
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 772 of file configuration.h.

772  {
773  const std::string s = operator std::string();
774  if (s == "mode sampling") {
776  }
777  if (s == "biased BF") {
779  }
780  if (s == "unbiased BF") {
782  }
783  throw IncorrectTypeInAssignment(
784  "The value for key \"" + std::string(key_) +
785  "\" should be \"mode sampling\", \"biased BF\" or \"unbiased BF\".");
786  }
const char *const key_
The key to be interpreted.

Friends And Related Function Documentation

friend class Configuration
friend

Definition at line 346 of file configuration.h.

Member Data Documentation

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.

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: