libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNReal.cpp
Go to the documentation of this file.
1 /* Copyright 2006-2016 Yann LEYDIER, CoReNum, INSA-Lyon, ENS-lyon
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: CRNReal.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <CRNData/CRNReal.h>
23 #include <math.h>
24 #include <CRNException.h>
25 #include <CRNMath/CRNProp3.h>
26 #include <CRNData/CRNDataFactory.h>
27 #include <CRNMath/CRNMath.h>
28 #include <CRNi18n.h>
29 
30 using namespace crn;
31 
32 /*****************************************************************************/
41 {
42  if (el.GetValue() != "Real")
43  {
44  throw ExceptionInvalidArgument(StringUTF8("void Real::Deserialize(xml::Element &el): ") +
45  _("Wrong XML element."));
46  }
47  val = el.GetAttribute<double>("value");
48 }
49 
50 /*****************************************************************************/
58 {
59  xml::Element el(parent.PushBackElement("Real"));
60  el.SetAttribute("value", val);
61  return el;
62 }
63 
66  Cloner::Register<Real>();
67  Ruler::Register<Real>();
69 
XML element.
Definition: CRNXml.h:135
#define _(String)
Definition: CRNi18n.h:51
#define CRN_END_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
Definition: CRNObject.h:198
void Deserialize(xml::Element &el)
Reads from an XML element.
Definition: CRNReal.cpp:40
Interface class for the metric real number class.
Definition: CRNReal.h:38
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML element.
Definition: CRNReal.cpp:57
#define CRN_DATA_FACTORY_REGISTER(elemname, classname)
Registers a class to the data factory.
virtual StringUTF8 GetValue() const
Gets the content of the node.
Definition: CRNXml.cpp:171
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
Definition: CRNXml.cpp:595
T GetAttribute(const StringUTF8 &name, bool silent=true) const
Gets an attribute.
Definition: CRNXml.h:219
A character string class.
Definition: CRNStringUTF8.h:49
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Definition: CRNXml.cpp:355
Invalid argument error (e.g.: nullptr pointer)
Definition: CRNException.h:107
#define CRN_BEGIN_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
Definition: CRNObject.h:185