Factory.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24// STD/STL
25
26// Header
27#include "Factory.h"
28
30
31// ArmarX
33
34namespace armarx::aron::data
35{
36
37 // Access method
38 std::unique_ptr<data::Variant>
39 VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const
40 {
41 // if aron is null ==> e.g. optional or ptr not set
42 if (!aron)
43 {
44 return nullptr;
45 };
46
47 // compare versions
48 auto v = aron->VERSION;
49 auto v_str =
50 std::to_string(v.MAJOR) + "." + std::to_string(v.MINOR) + "." + std::to_string(v.PATCH);
51
52 auto d = aron::Version();
53 auto d_str =
54 std::to_string(d.MAJOR) + "." + std::to_string(d.MINOR) + "." + std::to_string(d.PATCH);
55
56 if (v != d)
57 {
59 << "Found inconsistencies in aron versions. This may lead to ice marshalling "
60 "exceptions. Please make sure to update the sender and receiver packages. "
61 << v_str << " != " << d_str;
62 }
63
64 auto descriptor = data::Aron2Descriptor(*aron);
65 switch (descriptor)
66 {
68 return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path);
70 return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path);
72 return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron),
73 path);
75 return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path);
77 return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron),
78 path);
80 return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron),
81 path);
83 return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron),
84 path);
86 return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron),
87 path);
89 return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron),
90 path);
92 break;
93 }
95 __PRETTY_FUNCTION__, "", std::to_string((int)descriptor), path);
96 }
97} // namespace armarx::aron::data
The Path class.
Definition Path.h:36
std::unique_ptr< data::Variant > create(const data::dto::GenericDataPtr &, const Path &) const
Definition Factory.cpp:39
The ValueNotValidException class.
Definition Exception.h:99
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
A convenience header to include all aron files (full include, not forward declared)
data::Descriptor Aron2Descriptor(const data::dto::GenericData &t)
Definition Descriptor.h:237