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 
29 // ArmarX
31 
32 namespace armarx::aron::data
33 {
34 
35  // Access method
36  std::unique_ptr<data::Variant>
37  VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const
38  {
39  // if aron is null ==> e.g. optional or ptr not set
40  if (!aron)
41  {
42  return nullptr;
43  };
44 
45  // compare versions
46  auto v = aron->VERSION;
47  auto v_str =
48  std::to_string(v.MAJOR) + "." + std::to_string(v.MINOR) + "." + std::to_string(v.PATCH);
49 
50  auto d = aron::Version();
51  auto d_str =
52  std::to_string(d.MAJOR) + "." + std::to_string(d.MINOR) + "." + std::to_string(d.PATCH);
53 
54  if (v != d)
55  {
57  << "Found inconsistencies in aron versions. This may lead to ice marshalling "
58  "exceptions. Please make sure to update the sender and receiver packages. "
59  << v_str << " != " << d_str;
60  }
61 
62  auto descriptor = data::Aron2Descriptor(*aron);
63  switch (descriptor)
64  {
66  return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path);
68  return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path);
70  return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron),
71  path);
73  return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path);
75  return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron),
76  path);
78  return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron),
79  path);
81  return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron),
82  path);
84  return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron),
85  path);
87  return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron),
88  path);
90  break;
91  }
93  __PRETTY_FUNCTION__, "", std::to_string((int)descriptor), path);
94  }
95 } // namespace armarx::aron::data
armarx::aron::data::VariantFactory::create
std::unique_ptr< data::Variant > create(const data::dto::GenericDataPtr &, const Path &) const
Definition: Factory.cpp:37
armarx::aron::data::Descriptor::NDARRAY
@ NDARRAY
armarx::aron::data::Descriptor::LIST
@ LIST
armarx::aron::data::Descriptor::STRING
@ STRING
armarx::aron::data::Descriptor::FLOAT
@ FLOAT
armarx::aron::data::Descriptor::INT
@ INT
armarx::aron::data::Descriptor::DICT
@ DICT
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::error::ValueNotValidException
The ValueNotValidException class.
Definition: Exception.h:145
All.h
armarx::aron::data::Descriptor::BOOL
@ BOOL
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::data::Descriptor::LONG
@ LONG
armarx::aron::data::Descriptor::DOUBLE
@ DOUBLE
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::aron::data::Descriptor::UNKNOWN
@ UNKNOWN
Factory.h
armarx::aron::data::Aron2Descriptor
data::Descriptor Aron2Descriptor(const data::dto::GenericData &t)
Definition: Descriptor.h:255