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 // ----------------------------------------------------------------------------
40 DGtal::ParameterValue::ParameterValue ( const std::string& v )
43 // ----------------------------------------------------------------------------
45 DGtal::ParameterValue::ParameterValue ( const X& v )
46 : myValue( detail::ValueConverter< X, std::string>::cast( v ) )
48 // ----------------------------------------------------------------------------
51 DGtal::ParameterValue::as() const
53 return detail::ValueConverter< std::string, T >::cast( myValue );
55 // ----------------------------------------------------------------------------
58 DGtal::ParameterValue::selfDisplay ( std::ostream & out ) const
63 // ----------------------------------------------------------------------------
65 DGtal::Parameters::Parameters( std::string name, ParameterValue pv )
67 operator()( name, pv );
69 // ----------------------------------------------------------------------------
71 DGtal::Parameters::Self&
72 DGtal::Parameters::operator()( std::string name, ParameterValue pv )
74 myParameters[ name ] = pv;
77 // ----------------------------------------------------------------------------
79 DGtal::Parameters::Self&
80 DGtal::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 // ----------------------------------------------------------------------------
89 DGtal::Parameters::Self
90 DGtal::Parameters::operator|( const Self& other ) const
92 return Parameters( *this )( other );
95 // ----------------------------------------------------------------------------
98 DGtal::Parameters::operator[]( std::string name ) const
100 auto it = myParameters.find( name );
101 return ( it != myParameters.end() ) ? it->second : ParameterValue( "UNSET PARAMETER" );
103 // ----------------------------------------------------------------------------
106 DGtal::Parameters::count( std::string name ) const
108 auto it = myParameters.find( name );
109 return it != myParameters.end();
112 // ----------------------------------------------------------------------------
115 DGtal::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 // ----------------------------------------------------------------------------
130 DGtal::Parameters::isValid() const
135 ///////////////////////////////////////////////////////////////////////////////
136 // ----------------------- Standard services ------------------------------
139 ///////////////////////////////////////////////////////////////////////////////
140 // Interface - public :
142 ///////////////////////////////////////////////////////////////////////////////
143 // Implementation of inline functions //
145 // ----------------------------------------------------------------------------
148 DGtal::operator<< ( std::ostream & out,
149 const ParameterValue & object )
151 object.selfDisplay( out );
155 // ----------------------------------------------------------------------------
158 DGtal::operator<< ( std::ostream & out,
159 const Parameters & object )
161 object.selfDisplay( out );
166 ///////////////////////////////////////////////////////////////////////////////