Version: SMASH-1.7
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...
 
 operator CollisionCriterion () const
 Set collision criterion 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 if (x == "NNbar") {
501  } else if (x == "PiDeuteron_to_NN") {
503  } else if (x == "PiDeuteron_to_pidprime") {
505  } else if (x == "NDeuteron_to_Ndprime") {
507  } else {
508  throw IncorrectTypeInAssignment(
509  "The value for key \"" + std::string(key_) +
510  "\" should be \"All\", \"Elastic\", \"NN_to_NR\", \"NN_to_DR\","
511  "\"KN_to_KN\", \"KN_to_KDelta\", \"PiDeuteron_to_NN\", "
512  "\"PiDeuteron_to_pidprime\", \"NDeuteron_to_Ndprime\", "
513  "\"Strangeness_exchange\" or "
514  "\"NNbar\", or any combination of these.");
515  }
516  }
517  return s;
518  }
const char *const key_
The key to be interpreted.
elastic scattering: particles remain the same, only momenta change
std::bitset< 10 > 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 527 of file configuration.h.

527  {
528  const std::vector<std::string> v = operator std::vector<std::string>();
529  std::set<ThermodynamicQuantity> s;
530  for (const auto &x : v) {
531  if (x == "rho_eckart") {
533  } else if (x == "tmn") {
534  s.insert(ThermodynamicQuantity::Tmn);
535  } else if (x == "tmn_landau") {
537  } else if (x == "landau_velocity") {
539  } else if (x == "j_QBS") {
541  } else {
542  throw IncorrectTypeInAssignment(
543  "The value for key \"" + std::string(key_) +
544  "\" should be \"rho_eckart\", \"tmn\""
545  ", \"tmn_landau\", \"landau_velocity\" or \"j_QBS\".");
546  }
547  }
548  return s;
549  }
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 558 of file configuration.h.

558  {
559  const std::string s = operator std::string();
560  if (s == "center of velocity") {
562  }
563  if (s == "center of mass") {
565  }
566  if (s == "fixed target") {
568  }
569  throw IncorrectTypeInAssignment(
570  "The value for key \"" + std::string(key_) +
571  "\" should be \"center of velocity\" or \"center of mass\" "
572  "or \"fixed target\".");
573  }
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 582 of file configuration.h.

582  {
583  const std::string s = operator std::string();
584  if (s == "off") {
585  return FermiMotion::Off;
586  }
587  if (s == "on") {
588  return FermiMotion::On;
589  }
590  if (s == "frozen") {
591  return FermiMotion::Frozen;
592  }
593  throw IncorrectTypeInAssignment(
594  "The value for key \"" + std::string(key_) +
595  "\" should be \"off\" or \"on\" or \"frozen\".");
596  }
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 605 of file configuration.h.

605  {
606  const std::string s = operator std::string();
607  if (s == "hadron") {
608  return DensityType::Hadron;
609  }
610  if (s == "baryon") {
611  return DensityType::Baryon;
612  }
613  if (s == "baryonic isospin") {
615  }
616  if (s == "pion") {
617  return DensityType::Pion;
618  }
619  if (s == "total isospin") {
621  }
622  if (s == "none") {
623  return DensityType::None;
624  }
625  throw IncorrectTypeInAssignment("The value for key \"" +
626  std::string(key_) +
627  "\" should be \"hadron\" or \"baryon\" "
628  "or \"baryonic isospin\" or \"pion\" "
629  "or \"none\".");
630  }
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 639 of file configuration.h.

639  {
640  const std::string s = operator std::string();
641  if (s == "NoExpansion") {
643  }
644  if (s == "MasslessFRW") {
646  }
647  if (s == "MassiveFRW") {
649  }
650  if (s == "Exponential") {
652  }
653  throw IncorrectTypeInAssignment(
654  "The value for key \"" + std::string(key_) +
655  "\" should be \"NoExpansion\", \"MasslessFRW\"," +
656  "\"MassiveFRW\" or \"Exponential\".");
657  }
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 666 of file configuration.h.

666  {
667  const std::string s = operator std::string();
668  if (s == "None") {
669  return TimeStepMode::None;
670  }
671  if (s == "Fixed") {
672  return TimeStepMode::Fixed;
673  }
674  throw IncorrectTypeInAssignment("The value for key \"" +
675  std::string(key_) +
676  "\" should be \"None\" or \"Fixed\".");
677  }
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 686 of file configuration.h.

686  {
687  const std::string s = operator std::string();
688  if (s == "thermal momenta") {
690  }
691  if (s == "peaked momenta") {
693  }
694  throw IncorrectTypeInAssignment(
695  "The value for key \"" + std::string(key_) +
696  "\" should be \"thermal momenta\" or \"peaked momenta\".");
697  }
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 706 of file configuration.h.

706  {
707  const std::string s = operator std::string();
708  if (s == "thermal momenta") {
710  }
711  if (s == "IC_ES") {
713  }
714  if (s == "IC_1M") {
716  }
717  if (s == "IC_2M") {
719  }
720  if (s == "IC_Massive") {
722  }
723  throw IncorrectTypeInAssignment(
724  "The value for key \"" + std::string(key_) +
725  "\" should be \"thermal momenta\", \"IC_ES\", " +
726  "\"IC_1M\", \"IC_2M\" or" + "\"IC_Massive\".");
727  }
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 736 of file configuration.h.

736  {
737  const std::string s = operator std::string();
738  if (s == "no annihilation") {
740  }
741  if (s == "resonances") {
743  }
744  if (s == "strings") {
746  }
747  throw IncorrectTypeInAssignment(
748  "The value for key \"" + std::string(key_) + "\" should be " +
749  "\"no annihilation\", \"detailed balance\", or \"strings\".");
750  }
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 759 of file configuration.h.

759  {
760  const std::string s = operator std::string();
761  if (s == "quadratic") {
762  return Sampling::Quadratic;
763  }
764  if (s == "custom") {
765  return Sampling::Custom;
766  }
767  if (s == "uniform") {
768  return Sampling::Uniform;
769  }
770  throw IncorrectTypeInAssignment(
771  "The value for key \"" + std::string(key_) +
772  "\" should be \"quadratic\", \"uniform\" or \"custom\".");
773  }
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 782 of file configuration.h.

782  {
783  const std::string s = operator std::string();
784  if (s == "mode sampling") {
786  }
787  if (s == "biased BF") {
789  }
790  if (s == "unbiased BF") {
792  }
793  throw IncorrectTypeInAssignment(
794  "The value for key \"" + std::string(key_) +
795  "\" should be \"mode sampling\", \"biased BF\" or \"unbiased BF\".");
796  }
const char *const key_
The key to be interpreted.
smash::Configuration::Value::operator CollisionCriterion ( ) const
inline

Set collision criterion from configuration values.

Returns
CollisionCriterion.
Exceptions
IncorrectTypeInAssignmentin case an collision criterion that is not available is provided as a configuration value.

Definition at line 805 of file configuration.h.

805  {
806  const std::string s = operator std::string();
807  if (s == "Geometric") {
809  }
810  if (s == "Stochastic") {
812  }
813  throw IncorrectTypeInAssignment("The value for key \"" +
814  std::string(key_) + "\" should be " +
815  "\"Geometric\" or \"Stochastic\".");
816  }
(Default) geometric criterion.
Stochastic Criteiron.
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: