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 
37 {
38  template <typename AronTypeT, typename DerivedT, typename ValueT>
39  class PrimitiveVariant : public SpecializedVariantBase<AronTypeT, DerivedT>
40  {
41  public:
43 
44  using ValueType = ValueT;
45 
47 
48  virtual ~PrimitiveVariant() = default;
49 
50  /* virtual implementations */
52  navigateAbsolute(const Path& path) const override
53  {
55  __PRETTY_FUNCTION__,
56  "Could not navigate through a non container navigator. The input path was: " +
57  path.toString(),
59  }
60 
61  std::vector<VariantPtr>
62  getChildren() const override
63  {
64  return {};
65  }
66 
67  size_t
68  childrenSize() const override
69  {
70  return 0;
71  }
72 
73  std::optional<ValueType>
75  {
76  if (!this->aron->defaultValue)
77  {
78  return std::nullopt;
79  }
80  return *this->aron->defaultValue;
81  }
82 
83  void
84  setDefaultValue(const std::optional<ValueType>& v)
85  {
86  if (!v)
87  {
88  this->aron->defaultValue = IceUtil::None;
89  }
90  else
91  {
92  this->aron->defaultValue = *v;
93  }
94  }
95 
96  protected:
97  };
98 } // namespace armarx::aron::type::detail
armarx::aron::type::detail::PrimitiveVariant::~PrimitiveVariant
virtual ~PrimitiveVariant()=default
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::type::detail
Definition: AnyVariant.h:36
armarx::aron::type::detail::PrimitiveVariant::getChildren
std::vector< VariantPtr > getChildren() const override
get all child elements
Definition: PrimitiveVariant.h:62
SpecializedVariant.h
armarx::aron::type::detail::PrimitiveVariant< type::dto::AronLong, Long, long >::ValueType
long ValueType
Definition: PrimitiveVariant.h:44
armarx::aron::type::detail::SpecializedVariantBase
Definition: SpecializedVariant.h:40
armarx::aron::type::detail::PrimitiveVariant::navigateAbsolute
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition: PrimitiveVariant.h:52
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::detail::PrimitiveVariant
Definition: PrimitiveVariant.h:39
armarx::aron::type::detail::SpecializedVariantBase::aron
AronTypeT::PointerType aron
Definition: SpecializedVariant.h:137
armarx::aron::type::detail::PrimitiveVariant::getDefaultValue
std::optional< ValueType > getDefaultValue() const
Definition: PrimitiveVariant.h:74
armarx::aron::type::detail::PrimitiveVariant::setDefaultValue
void setDefaultValue(const std::optional< ValueType > &v)
Definition: PrimitiveVariant.h:84
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::type::Variant::path
const Path path
Definition: Variant.h:139
armarx::aron::type::detail::PrimitiveVariant::childrenSize
size_t childrenSize() const override
Definition: PrimitiveVariant.h:68
armarx::aron::type::detail::SpecializedVariantBase::SpecializedVariantBase
SpecializedVariantBase(const type::Descriptor &descriptor, const Path &path)
Definition: SpecializedVariant.h:44
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125
armarx::aron::type::Variant::getPath
Path getPath() const
Definition: Variant.h:99