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 return ret;
99 }
100
101 std::vector<VariantPtr>
102 getChildren() const override
103 {
104 return {};
105 }
106
107 size_t
108 childrenSize() const override
109 {
110 return 0;
111 }
112
113 // static methods
114
115 /* public member functions */
116 DictPtr
117 getAsDict() const
118 {
119 auto dict = std::make_shared<Dict>();
120 auto copy_this = FromAronDTO(this->toAronDTO(), this->getPath());
121 dict->addElement("data", copy_this);
122 return dict;
123 }
124
125 void
126 setValue(const ValueT& x)
127 {
128 this->aron->value = x;
129 }
130
131 ValueT
132 getValue() const
133 {
134 return this->aron->value;
135 }
136
137 ValueT&
139 {
140 return this->aron->value;
141 }
142 };
143} // namespace armarx::aron::data::detail
The Path class.
Definition Path.h:36
const data::Descriptor descriptor
Definition Variant.h:155
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:110
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
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.