1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _OPTION_MANAGER_HXX
21 #define _OPTION_MANAGER_HXX
25 #include "MEDMEM_Exception.hxx"
30 //dummy method to have some polymorphism...
31 virtual void dummy()=0;
35 class Option : public OptionGeneric
40 Option( T defaut, T * var):
45 void setValue(T value)
54 //dummy method to have some polymorphism...
61 std::map< std::string, OptionGeneric* > _optionList;
67 std::map< std::string, OptionGeneric*>::iterator mi;
68 for(mi = _optionList.begin() ; mi != _optionList.end() ; mi++) delete (*mi).second;
71 template <class T> void registerOption( T * var, const std::string& name, T defaut)
73 OptionGeneric * newoption = new Option<T>( defaut, var);
74 _optionList.insert(make_pair(name, newoption));
77 template <class T> void getOption(const std::string& name, T& var)
79 if(_optionList.find(name) != _optionList.end())
81 Option<T>* option_ptr = dynamic_cast<Option<T>*>(_optionList.find(name)->second);
82 var= option_ptr->getValue();
84 else throw MEDEXCEPTION
85 ("Option is not listed, please register the option before using the getOption command");
88 template <class T> void setOption(const std::string& name, T value)
90 if(_optionList.find(name) != _optionList.end())
92 Option<T>* option_ptr = dynamic_cast<Option<T>*>(_optionList.find(name)->second);
94 option_ptr->setValue(value);
95 else throw MEDEXCEPTION ("Error setOption: Option is registered with a different type");
97 else throw MEDEXCEPTION
98 ("Option is not listed, please register the option before using the setOption command");
101 void setOption(const std::string& name, int value)
103 if(_optionList.find(name) != _optionList.end())
105 Option<double>* option_double_ptr = dynamic_cast<Option<double>*> (_optionList.find(name)->second);
106 if (option_double_ptr!=0)
107 setOption(name,(double) value);
110 Option<int>* option_ptr =dynamic_cast<Option<int>*>(_optionList.find(name)->second);
111 if (option_ptr != 0 )
112 option_ptr->setValue(value);
113 else throw MEDEXCEPTION ("Error setOption: Option is registered with a different type");
116 else throw MEDEXCEPTION
117 ("Option is not listed, please register the option before using the setOption command");