STK++ 0.9.13
STK_Option.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2010 Serge Iovleff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23 */
24
25/*
26 * Project: stkpp::DManager
27 * created on: 18 oct. 2010
28 * Purpose: Declaration of the Optio class.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
37#ifndef STK_OPTION_H
38#define STK_OPTION_H
39
40#include <list>
41#include "../include/STK_DManager_Util.h"
43
44namespace STK
45{
46
47// forward declaration of the IPage class
48class IPage;
49
55class Option
56{
57 public:
84
91 Option( String const& name, TypeOption type = string_, bool isOptional = true);
96 Option( IPage const& page);
100 Option( Option const& opt);
102 ~Option();
103
110 Option& operator=(const Option &opt);
111
116 inline String const& name() const { return name_;}
120 inline TypeOption type() const { return type_;}
124 inline bool isOptional() const { return isOptional_;}
125
129 inline void setListSeparator( Char const& sep )
130 { sep_ = sep;}
131
135 void write( ostream& os) const;
136
142 void read( istream& is);
143
149 bool setValue( String const& str );
150
155 void setPage( IPage const& value );
156
160 inline String const& get( String const& value ) const
161 { return *p_String_;}
165 inline Real const& get( Real const& value) const
166 { return *p_Real_;}
170 inline int get( int const& value) const
171 { return *p_int_;}
175 inline Range const& get( Range const& value) const
176 { return *p_Range_;}
180 inline std::list<String> const& get( std::list<String> const& value) const
181 { return *p_lString_;}
185 inline std::list<Real> const& get( std::list<Real> const& value) const
186 { return *p_lReal_;}
190 inline std::list<int> const& get( std::list<int> const& value) const
191 { return *p_lint_;}
195 inline std::list<Range> const& get( std::list<Range> const& value) const
196 { return *p_lRange_;}
200 inline IPage const& get( IPage const& value) const
201 { return *p_Page_;}
202
203 protected:
207 void set( String const& value );
211 void set( Real const& value );
215 void set( int const& value );
219 void set( Range const& value );
223 void set( std::list<String> const& value );
227 void set(std::list<Real> const& value );
231 void set(std::list<int> const& value );
235 void set(std::list<Range> const& value );
236
237 private:
250 union
251 {
254 int* p_int_;
256 std::list<String>* p_lString_;
257 std::list<Real>* p_lReal_;
258 std::list<int>* p_lint_;
259 std::list<Range>* p_lRange_;
261 };
263 void deleteValue();
266 void setDefaultValue();
267};
268
269} // namespace STK
270
271#endif /* STK_OPTION_H */
This file define methods for displaying Arrays and Expressions.
A IPage is an interface base class for reading and/or writing a page of option in a file.
Definition STK_IPage.h:94
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
the Option class allow to store the value of an option from a IPage.
Definition STK_Option.h:56
void read(istream &is)
read in the options from the input stream.
String const & name() const
name of the option.
Definition STK_Option.h:116
Range * p_Range_
Definition STK_Option.h:255
Option & operator=(const Option &opt)
Assignment operator.
void setPage(IPage const &value)
set a value from a Page.
Range const & get(Range const &value) const
get the option as a Range
Definition STK_Option.h:175
void setDefaultValue()
set a default value of the option.
int get(int const &value) const
get the option as an int
Definition STK_Option.h:170
void setListSeparator(Char const &sep)
set the separator to use in the list of options.
Definition STK_Option.h:129
IPage * p_Page_
Definition STK_Option.h:260
bool setValue(String const &str)
Convert a string in a value.
std::list< int > * p_lint_
Definition STK_Option.h:258
std::list< String > const & get(std::list< String > const &value) const
get the option as a list of String
Definition STK_Option.h:180
String * p_String_
Definition STK_Option.h:252
Real * p_Real_
Definition STK_Option.h:253
void write(ostream &os) const
write out the options in the output stream
Char sep_
Char used for the option list.
Definition STK_Option.h:241
IPage const & get(IPage const &value) const
get the option as a page
Definition STK_Option.h:200
std::list< Range > const & get(std::list< Range > const &value) const
get the option as a list of Range
Definition STK_Option.h:195
TypeOption type_
type of the option
Definition STK_Option.h:243
std::list< String > * p_lString_
Definition STK_Option.h:256
Real const & get(Real const &value) const
get the option as a Real
Definition STK_Option.h:165
~Option()
Destructor.
std::list< int > const & get(std::list< int > const &value) const
get the option as a list of int
Definition STK_Option.h:190
bool isOptional_
true if the option is optional, false otherwise
Definition STK_Option.h:245
bool isOptional() const
check if the option is optional of the option.
Definition STK_Option.h:124
bool isValued_
true if the option is valued, false otherwise.
Definition STK_Option.h:248
TypeOption type() const
type of the option.
Definition STK_Option.h:120
std::list< Range > * p_lRange_
Definition STK_Option.h:259
std::list< Real > * p_lReal_
Definition STK_Option.h:257
String const & get(String const &value) const
get the option as a String
Definition STK_Option.h:160
String name_
name of the option
Definition STK_Option.h:239
void deleteValue()
Remove the value of the option.
std::list< Real > const & get(std::list< Real > const &value) const
get the option as a list of Real
Definition STK_Option.h:185
void set(String const &value)
set a value from string.
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
TypeOption
A TypeOption is the kind of options that can read or write a program in a file.
Definition STK_Option.h:72
@ linteger_
list of discrete numbers separated by commas
Definition STK_Option.h:80
@ page_
a page option
Definition STK_Option.h:82
@ range_
range of number
Definition STK_Option.h:77
@ lstring_
list of strings separated by commas
Definition STK_Option.h:78
@ lreal_
list of floating numbers separated by commas
Definition STK_Option.h:79
@ integer_
discrete number
Definition STK_Option.h:76
@ lrange_
list of range of number separated by commas
Definition STK_Option.h:81
@ string_
characters
Definition STK_Option.h:74
@ real_
floating
Definition STK_Option.h:75
char Char
STK fundamental type of a Char.
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
std::basic_ostream< Char > ostream
ostream for Char
Definition STK_Stream.h:57
std::basic_istream< Char > istream
istream for Char
Definition STK_Stream.h:55
The namespace STK is the main domain space of the Statistical ToolKit project.