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#include <memory>
27
29
30#include "../Variant.h"
31
33{
34 template <typename AronTypeT, typename DerivedT>
36 {
37
38 public:
40 Variant(descriptor, path), aron(new AronTypeT())
41 {
42 }
43
44 SpecializedVariantBase(const AronTypeT& o,
46 const Path& path) :
47 Variant(descriptor, path), aron(new AronTypeT(o))
48 {
49 }
50
51 virtual ~SpecializedVariantBase() = default;
52
53 // operators
54 operator AronTypeT()
55 {
56 return *aron;
57 }
58
59 bool
60 operator==(const Variant& other) const override
61 {
62 const auto& n = dynamic_cast<const DerivedT&>(other);
63 return *this == n;
64 }
65
66 bool
67 operator==(const DerivedT& other) const
68 {
69 return *(this->aron) == *(other.aron);
70 }
71
72 // virtual implementations
73 type::dto::GenericTypePtr
74 toAronDTO() const override
75 {
77 return aron;
78 }
79
80 void
81 setMaybe(const type::Maybe m) override
82 {
83 aron->maybe = m;
84 }
85
86 type::Maybe
87 getMaybe() const override
88 {
89 return aron->maybe;
90 }
91
93 navigateRelative(const Path& path) const override
94 {
95 Path absoluteFromHere = path.getWithoutPrefix(getPath());
96 return navigateAbsolute(absoluteFromHere);
97 }
98
99 // static methods
100 static DerivedT&
102 {
103 return dynamic_cast<DerivedT&>(n);
104 }
105
106 static const DerivedT&
108 {
109 return dynamic_cast<const DerivedT&>(n);
110 }
111
112 static std::shared_ptr<DerivedT>
114 {
115 return std::dynamic_pointer_cast<DerivedT>(n);
116 }
117
118 static std::shared_ptr<DerivedT>
120 {
121 if (!n)
122 {
123 return nullptr;
124 }
125
126 auto casted = std::dynamic_pointer_cast<DerivedT>(n);
127 ARMARX_CHECK_NOT_NULL(casted);
128 return casted;
129 }
130
131 protected:
132 typename AronTypeT::PointerType aron;
133 };
134} // namespace armarx::aron::type::detail
The Path class.
Definition Path.h:36
The Variant class.
Definition Variant.h:54
virtual VariantPtr navigateAbsolute(const Path &path) const =0
naviate absolute
Variant(const type::Descriptor &descriptor, const Path &path=Path())
Definition Variant.cpp:45
const type::Descriptor descriptor
Definition Variant.h:108
static const DerivedT & DynamicCast(const Variant &n)
SpecializedVariantBase(const AronTypeT &o, const type::Descriptor &descriptor, const Path &path)
type::Maybe getMaybe() const override
get the maybe type
static std::shared_ptr< DerivedT > DynamicCastAndCheck(const VariantPtr &n)
bool operator==(const Variant &other) const override
VariantPtr navigateRelative(const Path &path) const override
navigate relative
void setMaybe(const type::Maybe m) override
set the maybetype of this type
SpecializedVariantBase(const type::Descriptor &descriptor, const Path &path)
static std::shared_ptr< DerivedT > DynamicCast(const VariantPtr &n)
type::dto::GenericTypePtr toAronDTO() const override
convert this variant to a dto object.
#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...
std::shared_ptr< Variant > VariantPtr