libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNConfigElement.cpp
Go to the documentation of this file.
1 /* Copyright 2011-2014 CoReNum
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNConfigElement.cpp
19  * \author Yann LEYDIER
20  */
21 
23 #include <CRNi18n.h>
24 
25 using namespace crn;
26 
31  value(nullptr),
32  minValue(nullptr),
33  maxValue(nullptr)
34 { }
35 
41 ConfigElement::ConfigElement(const String& nam, int val, const String& desc):
42  value(std::make_shared<Int>(val)),
43  minValue(nullptr),
44  maxValue(nullptr),
45  name(nam),
46  description(desc)
47 { }
48 
54 ConfigElement::ConfigElement(const String& nam, double val, const String& desc):
55  value(std::make_shared<Real>(val)),
56  minValue(nullptr),
57  maxValue(nullptr),
58  name(nam),
59  description(desc)
60 { }
61 
67 ConfigElement::ConfigElement(const String& nam, bool val, const String& desc):
68  value(std::make_shared<Prop3>(val)),
69  minValue(nullptr),
70  maxValue(nullptr),
71  name(nam),
72  description(desc)
73 { }
74 
80 ConfigElement::ConfigElement(const String& nam, const Prop3& val, const String& desc):
81  value(Clone(val)),
82  minValue(nullptr),
83  maxValue(nullptr),
84  name(nam),
85  description(desc)
86 { }
87 
93 ConfigElement::ConfigElement(const String& nam, const String& val, const String& desc):
94  value(Clone(val)),
95  minValue(nullptr),
96  maxValue(nullptr),
97  name(nam),
98  description(desc)
99 { }
100 
106 ConfigElement::ConfigElement(const String& nam, const StringUTF8& val, const String& desc):
107  value(Clone(val)),
108  minValue(nullptr),
109  maxValue(nullptr),
110  name(nam),
111  description(desc)
112 { }
113 
119 ConfigElement::ConfigElement(const String& nam, const Path& val, const String& desc):
120  value(Clone(val)),
121  minValue(nullptr),
122  maxValue(nullptr),
123  name(nam),
124  description(desc)
125 { }
126 
133 {
134  if (!value)
135  throw ExceptionUninitialized(_("The element was not initialized."));
136  auto i = std::static_pointer_cast<Int>(value);
137  if (i)
138  return U"Int";
139  auto r = std::static_pointer_cast<Real>(value);
140  if (r)
141  return U"Real";
142  auto p = std::static_pointer_cast<Prop3>(value);
143  if (p)
144  return U"Prop3";
145  auto s = std::static_pointer_cast<String>(value);
146  if (s)
147  return U"String";
148  auto su = std::static_pointer_cast<StringUTF8>(value);
149  if (su)
150  return U"StringUTF8";
151  auto pa = std::static_pointer_cast<Path>(value);
152  if (pa)
153  return U"Path";
154  throw ExceptionInvalidArgument(_("The element is of unknown type."));
155 }
156 
ConfigElement()
Default constructor for serialization.
#define _(String)
Definition: CRNi18n.h:51
Unintialized object error.
Definition: CRNException.h:155
A UTF32 character string class.
Definition: CRNString.h:61
Interface class for the metric real number class.
Definition: CRNReal.h:38
A convenience class for file paths.
Definition: CRNPath.h:39
String GetType() const
Gets the inner type of data in the element.
Interface class for the metric real number class.
Definition: CRNInt.h:40
A character string class.
Definition: CRNStringUTF8.h:49
UObject Clone(const Object &obj)
Clones an object if possible.
Definition: CRNObject.cpp:35
A ternary proposition.
Definition: CRNProp3.h:40
Invalid argument error (e.g.: nullptr pointer)
Definition: CRNException.h:107