SpecializedVariant.h
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#pragma once
25
26// STD/STL
27#include <memory>
28
29// Base class
30#include "../Variant.h"
31
32// ArmarX
34
36{
37 template <typename AronDataT, typename DerivedT>
39 {
40 public:
42 using PointerType = std::shared_ptr<DerivedT>;
43 using AronDataType = AronDataT;
44
45 public:
47
52
53 SpecializedVariantBase(const typename AronDataType::PointerType& o,
55 const Path& path = Path()) :
57 {
59 }
60
61 virtual ~SpecializedVariantBase() = default;
62
63 // operators
64 operator typename AronDataType::PointerType()
65 {
66 return aron;
67 }
68
69 bool
70 operator==(const Variant& other) const override
71 {
72 const auto& n = DerivedT::DynamicCast(other);
73 return *this == n;
74 }
75
76 virtual bool operator==(const DerivedT&) const = 0;
77 virtual bool operator==(const PointerType& other) const = 0;
78
79 // new interface methods
80 virtual PointerType
81 clone() const
82 {
83 return clone(getPath());
84 }
85
86 virtual PointerType clone(const Path& newPath) const = 0;
87
88 // virtual implementations
90 cloneAsVariant() const override
91 {
92 return clone();
93 }
94
96 cloneAsVariant(const Path& newPath) const override
97 {
98 return clone(newPath);
99 }
100
101 data::dto::GenericDataPtr
102 toAronDTO() const override
103 {
104 return aron;
105 }
106
108 navigateRelative(const Path& path) const override
109 {
110 Path absoluteFromHere = path.getWithoutPrefix(getPath());
111 return navigateAbsolute(absoluteFromHere);
112 }
113
114 // static methods
115 static PointerType
117 {
118 return std::dynamic_pointer_cast<DerivedT>(n);
119 }
120
121 static DerivedT&
123 {
124 return dynamic_cast<DerivedT&>(n);
125 }
126
127 static const DerivedT&
129 {
130 return dynamic_cast<const DerivedT&>(n);
131 }
132
133 static PointerType
135 {
136 if (!n)
137 {
138 return nullptr;
139 }
140
141 PointerType casted = DerivedT::DynamicCast(n);
143 << "The path was: " << n->getPath().toString() << ".\n"
144 << "It has the descriptor: '"
146 << "'.\n"
147 << "And the typeid: " << typeid(n).name() << ". Tried to cast to "
148 << typeid(PointerType).name();
149 return casted;
150 }
151
152 protected:
153 typename AronDataType::PointerType aron;
154 };
155} // namespace armarx::aron::data::detail
The Path class.
Definition Path.h:36
The Variant class.
Definition Variant.h:61
const data::Descriptor descriptor
Definition Variant.h:155
virtual VariantPtr navigateAbsolute(const Path &path) const =0
naviate absolute
Path getPath() const
get the path
Definition Variant.h:110
data::dto::GenericDataPtr toAronDTO() const override
convert the variant to the ice representation
static const DerivedT & DynamicCast(const Variant &n)
SpecializedVariantBase(const typename AronDataType::PointerType &o, const data::Descriptor descriptor, const Path &path=Path())
virtual bool operator==(const DerivedT &) const =0
bool operator==(const Variant &other) const override
VariantPtr navigateRelative(const Path &path) const override
navigate relative
SpecializedVariantBase(const data::Descriptor descriptor, const Path &path=Path())
static PointerType DynamicCastAndCheck(const VariantPtr &n)
static PointerType DynamicCast(const VariantPtr &n)
VariantPtr cloneAsVariant(const Path &newPath) const override
virtual PointerType clone(const Path &newPath) const =0
virtual bool operator==(const PointerType &other) const =0
VariantPtr cloneAsVariant() const override
get a pointer to a copy of this variant
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
const std::map< data::Descriptor, std::string > Descriptor2String
Definition Descriptor.h:207
std::shared_ptr< Variant > VariantPtr