2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
24 * Implementation of inline methods defined in Parameters.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
38// ----------------------------------------------------------------------------
40DGtal::ParameterValue::ParameterValue ( const std::string& v )
43// ----------------------------------------------------------------------------
45DGtal::ParameterValue::ParameterValue ( const X& v )
46 : myValue( detail::ValueConverter< X, std::string>::cast( v ) )
48// ----------------------------------------------------------------------------
51DGtal::ParameterValue::as() const
53 return detail::ValueConverter< std::string, T >::cast( myValue );
55// ----------------------------------------------------------------------------
58DGtal::ParameterValue::selfDisplay ( std::ostream & out ) const
63// ----------------------------------------------------------------------------
65DGtal::Parameters::Parameters( std::string name, ParameterValue pv )
67 operator()( name, pv );
69// ----------------------------------------------------------------------------
71DGtal::Parameters::Self&
72DGtal::Parameters::operator()( std::string name, ParameterValue pv )
74 myParameters[ name ] = pv;
77// ----------------------------------------------------------------------------
79DGtal::Parameters::Self&
80DGtal::Parameters::operator()( const Parameters& params )
82 // if keys collide, values of params overrides this's values.
83 for(auto& it : params.myParameters)
84 myParameters[it.first] = it.second;
87// ----------------------------------------------------------------------------
89DGtal::Parameters::Self
90DGtal::Parameters::operator|( const Self& other ) const
92 return Parameters( *this )( other );
95// ----------------------------------------------------------------------------
98DGtal::Parameters::operator[]( std::string name ) const
100 auto it = myParameters.find( name );
101 return ( it != myParameters.end() ) ? it->second : ParameterValue( "UNSET PARAMETER" );
103// ----------------------------------------------------------------------------
106DGtal::Parameters::count( std::string name ) const
108 auto it = myParameters.find( name );
109 return it != myParameters.end();
112// ----------------------------------------------------------------------------
115DGtal::Parameters::selfDisplay ( std::ostream & out ) const
118 for ( auto it = myParameters.begin(), itE = myParameters.end();
121 out << it->first << ": " << it->second;
123 if ( it != itE ) out << ", ";
127// ----------------------------------------------------------------------------
130DGtal::Parameters::isValid() const
135///////////////////////////////////////////////////////////////////////////////
136// ----------------------- Standard services ------------------------------
139///////////////////////////////////////////////////////////////////////////////
140// Interface - public :
142///////////////////////////////////////////////////////////////////////////////
143// Implementation of inline functions //
145// ----------------------------------------------------------------------------
148DGtal::operator<< ( std::ostream & out,
149 const ParameterValue & object )
151 object.selfDisplay( out );
155// ----------------------------------------------------------------------------
158DGtal::operator<< ( std::ostream & out,
159 const Parameters & object )
161 object.selfDisplay( out );
166///////////////////////////////////////////////////////////////////////////////