|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2010 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: stkpp::DManager 00027 * created on: 18 oct. 2010 00028 * Purpose: Declaration of the Optio class. 00029 * Author: iovleff, serge.iovleff@stkpp.org 00030 * 00031 **/ 00032 00037 #ifndef STK_OPTION_H 00038 #define STK_OPTION_H 00039 00040 // C++ headers 00041 #include <list> 00042 00043 // STK+ headers 00044 #include "../../STKernel/include/STK_String.h" 00045 #include "../../STKernel/include/STK_Integer.h" 00046 #include "../../STKernel/include/STK_Real.h" 00047 #include "../../STKernel/include/STK_Range.h" 00048 #include "../../STKernel/include/STK_Stream.h" 00049 00050 #include "../include/STK_DManager_Util.h" 00051 00052 namespace STK 00053 { 00054 00055 // forward declaration of the IPage class 00056 class IPage; 00057 00063 class Option 00064 { 00065 public: 00079 enum TypeOption 00080 { 00081 unknown_ =0, 00082 string_, 00083 real_, 00084 integer_, 00085 range_, 00086 lstring_, 00087 lreal_, 00088 linteger_, 00089 lrange_, 00090 page_ 00091 }; 00092 00099 Option( String const& name, TypeOption type = string_, bool isOptional = true); 00104 Option( IPage const& page); 00108 Option( Option const& opt); 00110 ~Option(); 00111 00118 Option& operator=(const Option &opt); 00119 00124 inline String const& name() const { return name_;} 00128 inline TypeOption type() const { return type_;} 00132 inline bool isOptional() const { return isOptional_;} 00133 00137 inline void setListSeparator( Char const& sep ) 00138 { sep_ = sep;} 00139 00143 void write( ostream& os) const; 00144 00150 void read( istream& is); 00151 00157 bool setValue( String const& str ); 00158 00163 void setPage( IPage const& value ); 00164 00168 inline String const& get( String const& value ) const 00169 { return *p_String_;} 00173 inline Real const& get( Real const& value) const 00174 { return *p_Real_;} 00178 inline Integer const& get( Integer const& value) const 00179 { return *p_Integer_;} 00183 inline Range const& get( Range const& value) const 00184 { return *p_Range_;} 00188 inline std::list<String> const& get( std::list<String> const& value) const 00189 { return *p_lString_;} 00193 inline std::list<Real> const& get( std::list<Real> const& value) const 00194 { return *p_lReal_;} 00198 inline std::list<Integer> const& get( std::list<Integer> const& value) const 00199 { return *p_lInteger_;} 00203 inline std::list<Range> const& get( std::list<Range> const& value) const 00204 { return *p_lRange_;} 00208 inline IPage const& get( IPage const& value) const 00209 { return *p_Page_;} 00210 00211 protected: 00215 void set( String const& value ); 00219 void set( Real const& value ); 00223 void set( Integer const& value ); 00227 void set( Range const& value ); 00231 void set( std::list<String> const& value ); 00235 void set(std::list<Real> const& value ); 00239 void set(std::list<Integer> const& value ); 00243 void set(std::list<Range> const& value ); 00244 00245 private: 00247 String name_; 00249 Char sep_; 00251 TypeOption type_; 00253 bool isOptional_; 00256 bool isValued_; 00258 union 00259 { 00260 String* p_String_; 00261 Real* p_Real_; 00262 Integer* p_Integer_; 00263 Range* p_Range_; 00264 std::list<String>* p_lString_; 00265 std::list<Real>* p_lReal_; 00266 std::list<Integer>* p_lInteger_; 00267 std::list<Range>* p_lRange_; 00268 IPage* p_Page_; 00269 }; 00271 void deleteValue(); 00274 void setDefaultValue(); 00275 }; 00276 00277 } 00278 00279 #endif /* STK_OPTION_H */