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
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::aron::data::Variant::descriptor
const data::Descriptor descriptor
Definition: Variant.h:155
armarx::aron::data::detail::PrimitiveVariant::operator=
DerivedT & operator=(const ValueT &x)
Definition: PrimitiveVariant.h:66
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::aron::data::detail::PrimitiveVariant::~PrimitiveVariant
virtual ~PrimitiveVariant()=default
armarx::aron::data::detail::PrimitiveVariant::childrenSize
size_t childrenSize() const override
get the children size of a data variant
Definition: PrimitiveVariant.h:108
armarx::aron::data::detail::PrimitiveVariant::fromString
virtual void fromString(const std::string &setter)=0
set a primitive from a std string
armarx::aron::data::detail::PrimitiveVariant::PointerType
std::shared_ptr< DerivedT > PointerType
Definition: PrimitiveVariant.h:44
armarx::aron::data::Variant::FromAronDTO
static VariantPtr FromAronDTO(const data::dto::GenericDataPtr &, const Path &=Path())
create a variant from a dto object
Definition: Variant.cpp:39
armarx::aron::data::detail::PrimitiveVariant::PrimitiveVariant
PrimitiveVariant(const ValueT &v, const data::Descriptor descriptor, const Path &path=Path())
Definition: PrimitiveVariant.h:50
armarx::aron::data::Variant::getPath
Path getPath() const
get the path
Definition: Variant.h:110
armarx::aron::data::Variant::PointerType
VariantPtr PointerType
Definition: Variant.h:63
armarx::aron::data::Variant::path
const Path path
Definition: Variant.h:156
armarx::aron::data::Descriptor
Descriptor
Definition: Descriptor.h:193
armarx::aron::data::detail::PrimitiveVariant::getValue
ValueT getValue() const
Definition: PrimitiveVariant.h:132
armarx::aron::data::detail::SpecializedVariantBase::clone
virtual PointerType clone() const
Definition: SpecializedVariant.h:82
armarx::aron::data::detail::PrimitiveVariant< data::dto::AronInt, int, Int >::ValueType
int ValueType
Definition: PrimitiveVariant.h:45
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::detail
Definition: ComplexVariant.h:34
armarx::aron::data::detail::SpecializedVariantBase::SpecializedVariantBase
SpecializedVariantBase()=delete
armarx::aron::data::detail::PrimitiveVariant::navigateAbsolute
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition: PrimitiveVariant.h:83
armarx::aron::data::detail::PrimitiveVariant::getValue
ValueT & getValue()
Definition: PrimitiveVariant.h:138
armarx::aron::data::detail::PrimitiveVariant::getChildren
std::vector< VariantPtr > getChildren() const override
get the children of a data variant
Definition: PrimitiveVariant.h:102
armarx::aron::data::detail::PrimitiveVariant::clone
PointerType clone(const Path &newPath) const override
Definition: PrimitiveVariant.h:95
armarx::aron::data::detail::PrimitiveVariant
Definition: PrimitiveVariant.h:40
armarx::aron::data::detail::SpecializedVariantBase::toAronDTO
data::dto::GenericDataPtr toAronDTO() const override
convert the variant to the ice representation
Definition: SpecializedVariant.h:103
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::data::detail::SpecializedVariantBase
Definition: SpecializedVariant.h:39
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
SpecializedVariant.h
armarx::aron::data::detail::SpecializedVariantBase::aron
AronDataType::PointerType aron
Definition: SpecializedVariant.h:154
armarx::aron::data::detail::PrimitiveVariant::setValue
void setValue(const ValueT &x)
Definition: PrimitiveVariant.h:126
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125
armarx::aron::data::detail::PrimitiveVariant::getAsDict
DictPtr getAsDict() const
Definition: PrimitiveVariant.h:117