libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNObject.cpp
Go to the documentation of this file.
1 /* Copyright 2006-2016 Yann LEYDIER, INSA-Lyon, CoReNum, 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: CRNObject.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <CRNObject.h>
23 #include <CRNProtocols.h>
24 #include <CRNData/CRNInt.h>
25 #include <CRNData/CRNReal.h>
26 #include <CRNMath/CRNProp3.h>
27 #include <CRNi18n.h>
28 
29 using namespace crn;
30 using namespace crn::literals;
31 
35 UObject crn::Clone(const Object &obj)
36 {
37  return Cloner::Clone(obj);
38 }
39 
44 UObject crn::Clone(const UCObject &obj)
45 {
46  if (!obj)
47  throw ExceptionUninitialized("Clone(): "_s + _("null pointer."));
48  return Clone(*obj);
49 }
50 
55 UObject crn::Clone(const SCObject &obj)
56 {
57  if (!obj)
58  throw ExceptionUninitialized("Clone(): "_s + _("null pointer."));
59  return Clone(*obj);
60 }
61 
62 UInt crn::Clone(int i)
63 {
64  return std::make_unique<Int>(i);
65 }
66 
67 UReal crn::Clone(double d)
68 {
69  return std::make_unique<Real>(d);
70 }
71 
72 UProp3 crn::Clone(bool b)
73 {
74  return std::make_unique<Prop3>(b);
75 }
76 
81 {
82  Serializer::Deserialize(obj, el);
83 }
84 
89 void crn::Deserialize(const UObject &obj, xml::Element &el)
90 {
91  if (!obj)
92  throw ExceptionUninitialized("Deserialize(): "_s + _("null pointer."));
93  Deserialize(*obj, el);
94 }
95 
100 void crn::Deserialize(const SObject &obj, xml::Element &el)
101 {
102  if (!obj)
103  throw ExceptionUninitialized("Deserialize(): "_s + _("null pointer."));
104  Deserialize(*obj, el);
105 }
106 
111 {
112  return Serializer::Serialize(obj, parent);
113 }
114 
118 xml::Element crn::Serialize(const UCObject &obj, xml::Element &parent)
119 {
120  if (!obj)
121  throw ExceptionUninitialized("Serialize(): "_s + _("null pointer."));
122  return Serialize(*obj, parent);
123 }
124 
128 xml::Element crn::Serialize(const SCObject &obj, xml::Element &parent)
129 {
130  if (!obj)
131  throw ExceptionUninitialized("Serialize(): "_s + _("null pointer."));
132  return Serialize(*obj, parent);
133 }
134 
138 double crn::Distance(const Object &o1, const Object &o2)
139 {
140  return Ruler::ComputeDistance(o1, o2);
141 }
142 
147 double crn::Distance(const UCObject &o1, const UCObject &o2)
148 {
149  if (!o1 || !o2)
150  throw ExceptionUninitialized("Distance(): "_s + _("null pointer."));
151  return Distance(*o1, *o2);
152 }
153 
158 double crn::Distance(const SCObject &o1, const SCObject &o2)
159 {
160  if (!o1 || !o2)
161  throw ExceptionUninitialized("Distance(): "_s + _("null pointer."));
162  return Distance(*o1, *o2);
163 }
164 
xml::Element Serialize(const Object &obj, xml::Element &parent)
Writes an object to XML if possible.
Definition: CRNObject.cpp:110
static xml::Element Serialize(const Object &obj, xml::Element &el)
Definition: CRNProtocols.h:48
XML element.
Definition: CRNXml.h:135
#define _(String)
Definition: CRNi18n.h:51
Unintialized object error.
Definition: CRNException.h:155
static void Deserialize(Object &obj, xml::Element &el)
Definition: CRNProtocols.h:40
static UObject Clone(const Object &obj)
Definition: CRNProtocols.h:86
static double ComputeDistance(const Object &o1, const Object &o2)
Definition: CRNProtocols.h:127
double Distance(const Int &i1, const Int &i2) noexcept
Definition: CRNInt.h:78
void Deserialize(Object &obj, xml::Element &el)
Reads an object from XML if possible.
Definition: CRNObject.cpp:80
UObject Clone(const Object &obj)
Clones an object if possible.
Definition: CRNObject.cpp:35