STK++ 0.9.13
|
the Option
class allow to store the value of an option from a IPage.
More...
#include <STK_Option.h>
Public Types | |
enum | TypeOption { unknown_ =0 , string_ , real_ , integer_ , range_ , lstring_ , lreal_ , linteger_ , lrange_ , page_ } |
A TypeOption is the kind of options that can read or write a program in a file. More... | |
Public Member Functions | |
Option (String const &name, TypeOption type=string_, bool isOptional=true) | |
constructor. | |
Option (IPage const &page) | |
Special constructor. | |
Option (Option const &opt) | |
Copy constructor. | |
~Option () | |
Destructor. | |
Option & | operator= (const Option &opt) |
Assignment operator. | |
String const & | name () const |
name of the option. | |
TypeOption | type () const |
type of the option. | |
bool | isOptional () const |
check if the option is optional of the option. | |
void | setListSeparator (Char const &sep) |
set the separator to use in the list of options. | |
void | write (ostream &os) const |
write out the options in the output stream | |
void | read (istream &is) |
read in the options from the input stream. | |
bool | setValue (String const &str) |
Convert a string in a value. | |
void | setPage (IPage const &value) |
set a value from a Page. | |
String const & | get (String const &value) const |
get the option as a String | |
Real const & | get (Real const &value) const |
get the option as a Real | |
int | get (int const &value) const |
get the option as an int | |
Range const & | get (Range const &value) const |
get the option as a Range | |
std::list< String > const & | get (std::list< String > const &value) const |
get the option as a list of String | |
std::list< Real > const & | get (std::list< Real > const &value) const |
get the option as a list of Real | |
std::list< int > const & | get (std::list< int > const &value) const |
get the option as a list of int | |
std::list< Range > const & | get (std::list< Range > const &value) const |
get the option as a list of Range | |
IPage const & | get (IPage const &value) const |
get the option as a page | |
Protected Member Functions | |
void | set (String const &value) |
set a value from string. | |
void | set (Real const &value) |
set a value from a Real. | |
void | set (int const &value) |
set a value from an int. | |
void | set (Range const &value) |
set a value from a Range. | |
void | set (std::list< String > const &value) |
set a value from a list of String. | |
void | set (std::list< Real > const &value) |
set a value from a list of Real. | |
void | set (std::list< int > const &value) |
set a value from a list of int. | |
void | set (std::list< Range > const &value) |
set a value from a list of Range. | |
Private Member Functions | |
void | deleteValue () |
Remove the value of the option. | |
void | setDefaultValue () |
set a default value of the option. | |
Private Attributes | ||
String | name_ | |
name of the option | ||
Char | sep_ | |
Char used for the option list. | ||
TypeOption | type_ | |
type of the option | ||
bool | isOptional_ | |
true if the option is optional, false otherwise | ||
bool | isValued_ | |
true if the option is valued, false otherwise. | ||
union { | ||
String * p_String_ | ||
Real * p_Real_ | ||
int * p_int_ | ||
Range * p_Range_ | ||
std::list< String > * p_lString_ | ||
std::list< Real > * p_lReal_ | ||
std::list< int > * p_lint_ | ||
std::list< Range > * p_lRange_ | ||
IPage * p_Page_ | ||
}; | ||
value of the option. | ||
the Option
class allow to store the value of an option from a IPage.
An Option
is essentially a variant type. TODO add error message handling
Definition at line 55 of file STK_Option.h.
constructor.
name | the name of the Option |
type | the type of the Option |
isOptional | true if the parameter is optional, false otherwise |
Definition at line 47 of file STK_Option.cpp.
References name_, setDefaultValue(), and STK::toUpperString().
Referenced by Option().
Special constructor.
This will construct an option as a sub-page. The name of the option will be the name of the page.
page | the page to set as option |
Definition at line 63 of file STK_Option.cpp.
References name_, and STK::toUpperString().
Copy constructor.
opt | the Option to copy |
Definition at line 77 of file STK_Option.cpp.
References integer_, linteger_, lrange_, lreal_, lstring_, Option(), p_int_, p_lint_, p_lRange_, p_lReal_, p_lString_, p_Page_, p_Range_, p_Real_, p_String_, page_, range_, real_, set(), setPage(), STKRUNTIME_ERROR_NO_ARG, string_, type(), type_, and unknown_.
STK::Option::~Option | ( | ) |
Destructor.
Definition at line 131 of file STK_Option.cpp.
References deleteValue().
|
private |
Remove the value of the option.
Definition at line 424 of file STK_Option.cpp.
References integer_, isValued_, linteger_, lrange_, lreal_, lstring_, p_int_, p_lint_, p_lRange_, p_lReal_, p_lString_, p_Page_, p_Range_, p_Real_, p_String_, page_, range_, real_, string_, and type_.
Referenced by set(), set(), set(), set(), set(), set(), set(), set(), setPage(), and ~Option().
get the option as an int
value | any int (will not be used) |
Definition at line 170 of file STK_Option.h.
References p_int_.
get the option as a page
value | any page (will not be used) |
Definition at line 200 of file STK_Option.h.
References p_Page_.
get the option as a Range
value | any Range (will not be used) |
Definition at line 175 of file STK_Option.h.
References p_Range_.
get the option as a Real
value | any Real (will not be used) |
Definition at line 165 of file STK_Option.h.
References p_Real_.
get the option as a list of int
value | any list of int (will not be used) |
Definition at line 190 of file STK_Option.h.
References p_lint_.
get the option as a list of Range
value | any list of Range (will not be used) |
Definition at line 195 of file STK_Option.h.
References p_lRange_.
get the option as a list of Real
value | any list of Real (will not be used) |
Definition at line 185 of file STK_Option.h.
References p_lReal_.
get the option as a list of String
value | any list of String (will not be used) |
Definition at line 180 of file STK_Option.h.
References p_lString_.
get the option as a String
value | any String (will not be used) |
Definition at line 160 of file STK_Option.h.
References p_String_.
|
inline |
check if the option is optional of the option.
ture
if the option s optional, false
otherwise Definition at line 124 of file STK_Option.h.
References isOptional_.
name of the option.
If the option is a IPage, the name have to be the keyword.
Definition at line 116 of file STK_Option.h.
References name_.
Assignment operator.
We need to overload this operator otherwise the variant union containing the value of the Option will not be copied correctly.
opt | the Option to copy |
Definition at line 134 of file STK_Option.cpp.
References integer_, isOptional_, isValued_, linteger_, lrange_, lreal_, lstring_, name_, p_int_, p_lint_, p_lRange_, p_lReal_, p_lString_, p_Page_, p_Range_, p_Real_, p_String_, page_, range_, real_, sep_, set(), setPage(), STKRUNTIME_ERROR_NO_ARG, string_, type(), type_, and unknown_.
read in the options from the input stream.
This method is only used for reading the pages options. All the other options are read outside and set using the set and setValue methods.
is | the input stream to read |
Definition at line 330 of file STK_Option.cpp.
References STK::IPage::msg_error(), p_Page_, page_, STK::IPage::read(), read(), STKRUNTIME_ERROR_NO_ARG, type_, and STK::IPage::validate().
Referenced by read().
set a value from an int.
value | the int value to set |
Definition at line 367 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_int_.
set a value from a Range.
value | the Range value to set |
Definition at line 377 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_Range_.
set a value from a Real.
value | the Real value to set |
Definition at line 357 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_Real_.
set a value from a list of int.
value | the list of int values to set |
Definition at line 407 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_lint_.
set a value from a list of Range.
value | the list of Range values to set |
Definition at line 416 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_lRange_.
set a value from a list of Real.
value | the list of Real values to set |
Definition at line 397 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_lReal_.
set a value from a list of String.
value | the list of string values to set |
Definition at line 387 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_lString_.
set a value from string.
value | the string value to set |
Definition at line 347 of file STK_Option.cpp.
References deleteValue(), isValued_, and p_String_.
Referenced by operator=(), Option(), and setValue().
|
private |
set a default value of the option.
This method is used only once when the object is created.
Definition at line 472 of file STK_Option.cpp.
References integer_, linteger_, lrange_, lreal_, lstring_, STK::Arithmetic< Type >::NA(), p_int_, p_lint_, p_lRange_, p_lReal_, p_lString_, p_Page_, p_Range_, p_Real_, p_String_, page_, range_, real_, string_, STK::stringNa, and type_.
Referenced by Option().
set the separator to use in the list of options.
sep | the separator to use |
Definition at line 129 of file STK_Option.h.
References sep_.
set a value from a Page.
The field type_ of the class is set to DManager::page_
.
value | the Page to set |
Definition at line 263 of file STK_Option.cpp.
References STK::IPage::clone(), deleteValue(), isValued_, p_Page_, page_, and type_.
Referenced by operator=(), and Option().
Convert a string in a value.
The conversion is done using the field type_ of the class.
str | the string to convert |
true
if the conversion success, false
otherwise Definition at line 192 of file STK_Option.cpp.
References integer_, linteger_, lrange_, lreal_, lstring_, page_, range_, STK::DManager::readList(), real_, set(), setValue(), STKRUNTIME_ERROR_1ARG, string_, STK::stringToType(), type_, and unknown_.
Referenced by setValue().
|
inline |
type of the option.
Definition at line 120 of file STK_Option.h.
References type_.
Referenced by operator=(), and Option().
write out the options in the output stream
os | output stream |
Definition at line 275 of file STK_Option.cpp.
References _T, integer_, linteger_, lrange_, lreal_, lstring_, name_, p_int_, p_lint_, p_lRange_, p_lReal_, p_lString_, p_Page_, p_Range_, p_Real_, p_String_, page_, range_, real_, sep_, STKRUNTIME_ERROR_NO_ARG, string_, type_, unknown_, STK::IPage::write(), write(), and STK::DManager::writeList().
Referenced by write().
union { ... } STK::Option |
value of the option.
An other choice would be void*.
|
private |
true
if the option is optional, false
otherwise
Definition at line 245 of file STK_Option.h.
Referenced by isOptional(), and operator=().
|
private |
true
if the option is valued, false
otherwise.
A default value is settled when the Option is created as the type is fixed.
Definition at line 248 of file STK_Option.h.
Referenced by deleteValue(), operator=(), set(), set(), set(), set(), set(), set(), set(), set(), and setPage().
|
private |
name of the option
Definition at line 239 of file STK_Option.h.
Referenced by name(), operator=(), Option(), Option(), and write().
int* STK::Option::p_int_ |
Definition at line 254 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
std::list<int>* STK::Option::p_lint_ |
Definition at line 258 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
std::list<Range>* STK::Option::p_lRange_ |
Definition at line 259 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
std::list<Real>* STK::Option::p_lReal_ |
Definition at line 257 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
std::list<String>* STK::Option::p_lString_ |
Definition at line 256 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
IPage* STK::Option::p_Page_ |
Definition at line 260 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), read(), setDefaultValue(), setPage(), and write().
Range* STK::Option::p_Range_ |
Definition at line 255 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
Real* STK::Option::p_Real_ |
Definition at line 253 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
String* STK::Option::p_String_ |
Definition at line 252 of file STK_Option.h.
Referenced by deleteValue(), get(), operator=(), Option(), set(), setDefaultValue(), and write().
|
private |
Char used for the option list.
Definition at line 241 of file STK_Option.h.
Referenced by operator=(), setListSeparator(), and write().
|
private |
type of the option
Definition at line 243 of file STK_Option.h.
Referenced by deleteValue(), operator=(), Option(), read(), setDefaultValue(), setPage(), setValue(), type(), and write().