PrimitiveVariant.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#include <string>
29#include <unordered_map>
30
31// Base class
32#include "SpecializedVariant.h"
33
34// ArmarX
35#include "../container/Dict.h"
36
38{
39 template <typename AronDataT, typename ValueT, typename DerivedT>
40 class PrimitiveVariant : public SpecializedVariantBase<AronDataT, DerivedT>
41 {
42 public:
44 using PointerType = std::shared_ptr<DerivedT>;
45 using ValueType = ValueT;
46
47 public:
48 using typename Base::SpecializedVariantBase;
49
50 PrimitiveVariant(const ValueT& v,
52 const Path& path = Path()) :
54 {
55 this->aron->value = v;
56 }
57
58 virtual ~PrimitiveVariant() = default;
59
60 operator ValueT() const
61 {
62 return this->aron->value;
63 }
64
65 DerivedT&
66 operator=(const ValueT& x)
67 {
68 this->aron->value = x;
69 return *this;
70 }
71
72 // Already implemented through thge constructor of a primitive navigator
73 /*bool operator==(const ValueT& x) const
74 {
75 return this->aron->value == x;
76 }*/
77
78 /// set a primitive from a std string
79 virtual void fromString(const std::string& setter) = 0;
80
81 // virtual implementations
83 navigateAbsolute(const Path& path) const override
84 {
86 __PRETTY_FUNCTION__,
87 "Could not navigate through a non container navigator. The input path was: " +
88 path.toString(),
90 }
91
92 using Base::clone;
93
95 clone(const Path& newPath) const override
96 {
97 PointerType ret(new DerivedT(getValue(), newPath));
98 ret->setImportance(this->getImportance());
99 return ret;
100 }
101
102 std::vector<VariantPtr>
103 getChildren() const override
104 {
105 return {};
106 }
107
108 size_t
109 childrenSize() const override
110 {
111 return 0;
112 }
113
114 // static methods
115
116 /* public member functions */
117 DictPtr
118 getAsDict() const
119 {
120 auto dict = std::make_shared<Dict>();
121 auto copy_this = FromAronDTO(this->toAronDTO(), this->getPath());
122 dict->addElement("data", copy_this);
123 return dict;
124 }
125
126 void
127 setValue(const ValueT& x)
128 {
129 this->aron->value = x;
130 }
131
132 ValueT
133 getValue() const
134 {
135 return this->aron->value;
136 }
137
138 ValueT&
140 {
141 return this->aron->value;
142 }
143 };
144} // namespace armarx::aron::data::detail
The Path class.
Definition Path.h:36
const data::Descriptor descriptor
Definition Variant.h:166
static VariantPtr FromAronDTO(const data::dto::GenericDataPtr &, const Path &=Path())
create a variant from a dto object
Definition Variant.cpp:39
Path getPath() const
get the path
Definition Variant.h:111
size_t childrenSize() const override
get the children size of a data variant
PrimitiveVariant(const ValueT &v, const data::Descriptor descriptor, const Path &path=Path())
SpecializedVariantBase< AronDataT, DerivedT > Base
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
std::vector< VariantPtr > getChildren() const override
get the children of a data variant
virtual void fromString(const std::string &setter)=0
set a primitive from a std string
PointerType clone(const Path &newPath) const override
data::dto::GenericDataPtr toAronDTO() const override
convert the variant to the ice representation
std::optional< float > getImportance() const override
get optional importance metadata for this data variant.
A base class for aron exceptions.
Definition Exception.h:37
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< Variant > VariantPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.