DGtal 1.3.0
Loading...
Searching...
No Matches
Parameters.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
18 * @file
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21 *
22 * @date 2018/06/26
23 *
24 * Implementation of inline methods defined in Parameters.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38// ----------------------------------------------------------------------------
39inline
40DGtal::ParameterValue::ParameterValue ( const std::string& v )
41 : myValue( v )
42{}
43// ----------------------------------------------------------------------------
44template <typename X>
45DGtal::ParameterValue::ParameterValue ( const X& v )
46 : myValue( detail::ValueConverter< X, std::string>::cast( v ) )
47{}
48// ----------------------------------------------------------------------------
49template <typename T>
50T
51DGtal::ParameterValue::as() const
52{
53 return detail::ValueConverter< std::string, T >::cast( myValue );
54}
55// ----------------------------------------------------------------------------
56inline
57void
58DGtal::ParameterValue::selfDisplay ( std::ostream & out ) const
59{
60 out << myValue;
61}
62
63// ----------------------------------------------------------------------------
64inline
65DGtal::Parameters::Parameters( std::string name, ParameterValue pv )
66{
67 operator()( name, pv );
68}
69// ----------------------------------------------------------------------------
70inline
71DGtal::Parameters::Self&
72DGtal::Parameters::operator()( std::string name, ParameterValue pv )
73{
74 myParameters[ name ] = pv;
75 return *this;
76}
77// ----------------------------------------------------------------------------
78inline
79DGtal::Parameters::Self&
80DGtal::Parameters::operator()( const Parameters& params )
81{
82 // if keys collide, values of params overrides this's values.
83 for(auto& it : params.myParameters)
84 myParameters[it.first] = it.second;
85 return *this;
86}
87// ----------------------------------------------------------------------------
88inline
89DGtal::Parameters::Self
90DGtal::Parameters::operator|( const Self& other ) const
91{
92 return Parameters( *this )( other );
93}
94
95// ----------------------------------------------------------------------------
96inline
97DGtal::ParameterValue
98DGtal::Parameters::operator[]( std::string name ) const
99{
100 auto it = myParameters.find( name );
101 return ( it != myParameters.end() ) ? it->second : ParameterValue( "UNSET PARAMETER" );
102}
103// ----------------------------------------------------------------------------
104inline
105bool
106DGtal::Parameters::count( std::string name ) const
107{
108 auto it = myParameters.find( name );
109 return it != myParameters.end();
110}
111
112// ----------------------------------------------------------------------------
113inline
114void
115DGtal::Parameters::selfDisplay ( std::ostream & out ) const
116{
117 out << "{ ";
118 for ( auto it = myParameters.begin(), itE = myParameters.end();
119 it != itE; )
120 {
121 out << it->first << ": " << it->second;
122 ++it;
123 if ( it != itE ) out << ", ";
124 }
125 out << " }";
126}
127// ----------------------------------------------------------------------------
128inline
129bool
130DGtal::Parameters::isValid() const
131{
132 return true;
133}
134
135///////////////////////////////////////////////////////////////////////////////
136// ----------------------- Standard services ------------------------------
137
138
139///////////////////////////////////////////////////////////////////////////////
140// Interface - public :
141
142///////////////////////////////////////////////////////////////////////////////
143// Implementation of inline functions //
144
145// ----------------------------------------------------------------------------
146inline
147std::ostream&
148DGtal::operator<< ( std::ostream & out,
149 const ParameterValue & object )
150{
151 object.selfDisplay( out );
152 return out;
153}
154
155// ----------------------------------------------------------------------------
156inline
157std::ostream&
158DGtal::operator<< ( std::ostream & out,
159 const Parameters & object )
160{
161 object.selfDisplay( out );
162 return out;
163}
164
165// //
166///////////////////////////////////////////////////////////////////////////////
167
168