Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StitcherOptions.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
9 /* This is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This software is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this software. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #include "StitcherOptions.h"
26 #include "hugin_utils/utils.h"
27 
28 namespace HuginBase
29 {
30 namespace Nona
31 {
32 
33 bool GetAdvancedOption(const AdvancedOptions& opts, const std::string& name, const bool defaultValue)
34 {
35  AdvancedOptions::const_iterator it = opts.find(name);
36  if (it != opts.end())
37  {
38  //option is stored
39  const std::string value(it->second);
40  if (value == "true" || value == "1")
41  {
42  return true;
43  }
44  return false;
45  }
46  else
47  {
48  return defaultValue;
49  };
50 };
51 
52 std::string GetAdvancedOption(const AdvancedOptions& opts, const std::string& name, const std::string& defaultValue)
53 {
54  AdvancedOptions::const_iterator it = opts.find(name);
55  if (it != opts.end())
56  {
57  //option is stored
58  return it->second;
59  }
60  else
61  {
62  return defaultValue;
63  };
64 };
65 
66 float GetAdvancedOption(const AdvancedOptions& opts, const std::string& name, const float defaultValue)
67 {
68  AdvancedOptions::const_iterator it = opts.find(name);
69  if (it != opts.end())
70  {
71  //option is stored
72  double value;
73  if (hugin_utils::stringToDouble(it->second, value))
74  {
75  return static_cast<float>(value);
76  }
77  else
78  {
79  return defaultValue;
80  };
81  }
82  else
83  {
84  return defaultValue;
85  };
86 };
87 
88 void SetAdvancedOption(AdvancedOptions& opts, const std::string& name, const bool value)
89 {
90  if (value)
91  {
92  opts[name] = "true";
93  }
94  else
95  {
96  opts[name] = "false";
97  };
98 };
99 
100 void SetAdvancedOption(AdvancedOptions& opts, const std::string& name, const std::string& value)
101 {
102  opts[name] = value;
103 };
104 
105 void SetAdvancedOption(AdvancedOptions& opts, const std::string& name, const float value)
106 {
107  opts[name] = hugin_utils::doubleToString(value);
108 };
109 
110 } // namespace Nona
111 } // namespace HuginBase
bool GetAdvancedOption(const AdvancedOptions &opts, const std::string &name, const bool defaultValue)
check if given option is saved and return its boolean value, otherwise return defaultValue ...
std::string doubleToString(double d, int digits)
convert a double to a string, suitable for display within a GUI.
Definition: utils.cpp:228
Helper class for storing different options.
bool stringToDouble(const STR &str_, double &dest)
convert a string to a double, ignore localisation.
Definition: utils.h:114
std::map< std::string, std::string > AdvancedOptions
void SetAdvancedOption(AdvancedOptions &opts, const std::string &name, const bool value)
store the option with name in AdvancedOptions