OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Options Class Reference

#include <Options.hh>

Inheritance diagram for Options:
Inheritance graph
Collaboration diagram for Options:
Collaboration graph

Public Member Functions

 Options ()
 
virtual ~Options ()
 
void addOptionValue (const string &name, OptionValue *option)
 
OptionValueoptionValue (const string &name, int index=0)
 
int valueCount (const string &name)
 

Private Attributes

map< string, vector< OptionValue * > > options_
 

Detailed Description

Generic container of option values.

Definition at line 51 of file Options.hh.

Constructor & Destructor Documentation

◆ Options()

Options::Options ( )

Constructor.

Definition at line 51 of file Options.cc.

51 {
52}

◆ ~Options()

Options::~Options ( )
virtual

Destructor.

Definition at line 57 of file Options.cc.

57 {
58 std::map<string, vector<OptionValue*> >::iterator i = options_.begin();
59 vector<OptionValue*>::iterator j;
60 for (; i != options_.end(); i++) {
61 j = (*i).second.begin();
62 for (; j != (*i).second.end(); j++) {
63 delete (*j);
64 }
65 (*i).second.clear();
66 }
67 options_.clear();
68}
map< string, vector< OptionValue * > > options_
Definition Options.hh:62

References options_.

Member Function Documentation

◆ addOptionValue()

void Options::addOptionValue ( const string &  name,
OptionValue option 
)

Adds one option value to given option.

Parameters
nameName of the option.
optionValue of the option.
Exceptions
TypeMismatchIf new value's type differ the old ones.

Definition at line 78 of file Options.cc.

78 {
79 try {
80 vector<OptionValue*> values;
82
83 OptionValue& other = *values.at(0);
84 // check that new value is same type that old ones
85 if (typeid(*option) == typeid(other)) {
86 values.push_back(option);
87 options_.erase(name);
88 options_.insert(pair<string, vector<OptionValue*> >(name, values));
89 } else {
90 string procName = "Options::addOptionValue";
91 string errorMsg =
92 "Type of new OptionValue differs from the type of old values";
93 throw TypeMismatch(__FILE__, __LINE__, procName, errorMsg);
94 }
95 } catch (KeyNotFound& e) {
96 vector<OptionValue*> values;
97 values.push_back(option);
98 options_.insert(pair<string, vector<OptionValue*> >(name, values));
99 }
100}
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)

References MapTools::keyForValue(), and options_.

Referenced by MachineCanvasOptions::MachineCanvasOptions().

Here is the call graph for this function:

◆ optionValue()

OptionValue & Options::optionValue ( const string &  name,
int  index = 0 
)

Returns optionValue of the given option.

The index must be given between 0 and the option count where 0 is the latest value.

Parameters
nameName of the option.
indexIndex for lists of options.
Returns
The optionValue of an option.
Exceptions
OutOfRangeThe index is out of range of values.
KeyNotFoundNo option with given name.

Definition at line 115 of file Options.cc.

115 {
116 if (index < 0 || index > valueCount(name) - 1) {
117 string procName = "OptionValue::optionValue";
118 throw OutOfRange(__FILE__, __LINE__, procName);
119 }
120 vector<OptionValue*> values;
122
123 return *values[values.size() - index - 1];
124}
int valueCount(const string &name)
Definition Options.cc:134

References MapTools::keyForValue(), options_, and valueCount().

Referenced by ToggleUnitDetailsCmd::Do(), UnitFigure::drawSelf(), ToggleUnitDetailsCmd::isChecked(), UnitFigure::layoutSelf(), ProximMachineStateWindow::onToggleUnitInfo(), and ProximMachineStateWindow::onUpdateUIEvent().

Here is the call graph for this function:

◆ valueCount()

int Options::valueCount ( const string &  name)

Returns the count of optionValues of an option.

Parameters
nameName of the option.
Returns
Number of values for the option.
Exceptions
KeyNotFoundNo option with given name.

Definition at line 134 of file Options.cc.

134 {
135 vector<OptionValue*> values;
136 try {
138 } catch (KeyNotFound& e) {
139 string procName = "OptionValue::valueCount";
140 throw KeyNotFound(__FILE__, __LINE__, procName);
141 }
142 return values.size();
143}

References MapTools::keyForValue(), and options_.

Referenced by optionValue().

Here is the call graph for this function:

Member Data Documentation

◆ options_

map<string, vector<OptionValue*> > Options::options_
private

Definition at line 62 of file Options.hh.

Referenced by addOptionValue(), optionValue(), valueCount(), and ~Options().


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