1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #ifndef _OPTION_MANAGER_HXX
23 #define _OPTION_MANAGER_HXX
27 #include "MEDMEM_Exception.hxx"
32 //dummy method to have some polymorphism...
33 virtual void dummy()=0;
37 class Option : public OptionGeneric
42 Option( T defaut, T * var):
47 void setValue(T value)
56 //dummy method to have some polymorphism...
63 std::map< std::string, OptionGeneric* > _optionList;
69 std::map< std::string, OptionGeneric*>::iterator mi;
70 for(mi = _optionList.begin() ; mi != _optionList.end() ; mi++) delete (*mi).second;
73 template <class T> void registerOption( T * var, const std::string& name, T defaut)
75 OptionGeneric * newoption = new Option<T>( defaut, var);
76 _optionList.insert(make_pair(name, newoption));
79 template <class T> void getOption(const std::string& name, T& var)
81 if(_optionList.find(name) != _optionList.end())
83 Option<T>* option_ptr = dynamic_cast<Option<T>*>(_optionList.find(name)->second);
84 var= option_ptr->getValue();
86 else throw MEDEXCEPTION
87 ("Option is not listed, please register the option before using the getOption command");
90 template <class T> void setOption(const std::string& name, T value)
92 if(_optionList.find(name) != _optionList.end())
94 Option<T>* option_ptr = dynamic_cast<Option<T>*>(_optionList.find(name)->second);
96 option_ptr->setValue(value);
97 else throw MEDEXCEPTION ("Error setOption: Option is registered with a different type");
99 else throw MEDEXCEPTION
100 ("Option is not listed, please register the option before using the setOption command");
103 void setOption(const std::string& name, int value)
105 if(_optionList.find(name) != _optionList.end())
107 Option<double>* option_double_ptr = dynamic_cast<Option<double>*> (_optionList.find(name)->second);
108 if (option_double_ptr!=0)
109 setOption(name,(double) value);
112 Option<int>* option_ptr =dynamic_cast<Option<int>*>(_optionList.find(name)->second);
113 if (option_ptr != 0 )
114 option_ptr->setValue(value);
115 else throw MEDEXCEPTION ("Error setOption: Option is registered with a different type");
118 else throw MEDEXCEPTION
119 ("Option is not listed, please register the option before using the setOption command");