The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::app::FeatureConfiguration::FeatureOptions Class Reference

#include <FeatureConfiguration.hpp>

Public Member Functions

void setOptionsFromYamlFile (const std::string &yaml_opts_fname)
 
template<typename T , typename = typename std::enable_if< std::is_trivial<T>::value, T>::type>
getOptionValue (const std::string &option_name, const T default_value) const
 
template<typename T , typename = typename std::enable_if< std::is_same<T, std::string>::value, T>::type>
std::string getOptionValue (const std::string &option_name, const T default_value) const
 

Detailed Description

Feature options let you provide optional parameterization for any given feature. Typically, a feature value is either 0 or 1, but there may be more feature values:

 Value 0 = featured off
 Value 1 = featured on, foo parameters/configuration
 Value 2 = featured on, bar parameters/configuration
  ...

For these scenarios, it may be easier to run the simulator with commands like:

 <sim> -i 10k --feature my_feat 1 foo.yaml
 <sim> -i 10k --feature my_feat 1 bar.yaml

Where foo.yaml and bar.yaml are colon-separated name/value pairs such as:

 foo.yaml                        bar.yaml
-----------------------         -----------------------
 biz: 102                        bazA: hello
 buz: 48.5                       bazB: world
                                 buz: 45

Say the above example yamls were for a feature called "MyCoolFeature". You could ask the FeatureConfiguration object for the feature value as you normally would:

 if (feature_cfg->getFeatureValue("MyCoolFeature") == 1) {
     //...featured on...
 } else {
     //...featured off...
 }

And you could also (optionally) ask the FeatureConfiguration for any options that were found in yaml file(s) at the command line, like so:

 auto feature_opts = feature_cfg->getFeatureOptions("MyCoolFeature");
 if (feature_opts) {
     double biz_val = feature_opts->getOptionValue<double>("biz", 10);
     //This would equal 102 for foo.yaml configuration, but it would
     //equal 10 for bar.yaml configuration since there is no "biz"
     //parameter found in bar.yaml

     double buz_val = feature_opts->getOptionValue<double>("buz", 50);
     //Equals 48.5 for foo.yaml configuration, and 45 for bar.yaml
     //configuration.

     std::string bazA_val = feature_opts->getOptionValue<std::string>("bazA", "fizz");
     //Equals "fizz" for foo.yaml since this option does not exist
     //in that file, and it equals "hello" for bar.yaml
 } 

Definition at line 99 of file FeatureConfiguration.hpp.

Member Function Documentation

◆ getOptionValue() [1/2]

template<typename T , typename = typename std::enable_if< std::is_trivial<T>::value, T>::type>
T sparta::app::FeatureConfiguration::FeatureOptions::getOptionValue ( const std::string &  option_name,
const T  default_value 
) const
inline

Get the value of a particular feature option by name. If this option could not be found, the default_value you provide will be returned. Here are ways this method can fail:

     opts.yaml
-------------------
 myFoo: 100
 myBar: someString

If you called the getOptionValue() method like this, it would fail and return the default value you pass in:

//Fails because myFizzBuzz is not a known parameter. //Returns default value 4. auto val1 = feature_opts->getOptionValue<double>("myFizzBuzz", 4);

//Fails because myBar is a string, not a double. //Returns default value 5. auto val2 = feature_opts->getOptionValue<double>("myBar", 5);

Definition at line 150 of file FeatureConfiguration.hpp.

Here is the call graph for this function:

◆ getOptionValue() [2/2]

template<typename T , typename = typename std::enable_if< std::is_same<T, std::string>::value, T>::type>
std::string sparta::app::FeatureConfiguration::FeatureOptions::getOptionValue ( const std::string &  option_name,
const T  default_value 
) const
inline

Get the value of a particular feature option by name. If this option could not be found, the default_value you provide will be returned.

Definition at line 186 of file FeatureConfiguration.hpp.

Here is the call graph for this function:

◆ setOptionsFromYamlFile()

void sparta::app::FeatureConfiguration::FeatureOptions::setOptionsFromYamlFile ( const std::string &  yaml_opts_fname)
inline

Consume a yaml file that contains options in name-value format: param1: value1 param2: value2 ... ...

Definition at line 106 of file FeatureConfiguration.hpp.

Here is the call graph for this function:

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