Dict.cpp
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 // Header
25 #include "Dict.h"
26 
27 namespace armarx::aron::type
28 {
29  // constructors
30  Dict::Dict(const Path& path) :
31  detail::ContainerVariant<type::dto::Dict, Dict>(type::Descriptor::DICT, path)
32  {
33  }
34 
35  Dict::Dict(const type::dto::Dict& o, const Path& path) :
36  detail::ContainerVariant<type::dto::Dict, Dict>(o, type::Descriptor::DICT, path),
37  acceptedType(FromAronDTO(*o.acceptedType, path.withAcceptedType()))
38  {
39  }
40 
43  {
44  ARMARX_CHECK_NOT_NULL(acceptedType);
45  return acceptedType;
46  }
47 
48  void
50  {
52  aron->acceptedType = a->toAronDTO();
53  acceptedType = a;
54  }
55 
58  {
59  return aron;
60  }
61 
62  // virtual implementations
63  std::vector<VariantPtr>
65  {
66  return {acceptedType};
67  }
68 
69  size_t
71  {
72  return 1;
73  }
74 
75  std::string
77  {
78  return "Dict<" + acceptedType->getShortName() + ">";
79  }
80 
81  std::string
83  {
84  return "armarx::aron::type::Dict<" + acceptedType->getFullName() + ">";
85  }
86 
87  std::string
89  {
90  return "armarx::aron::type::Dict";
91  }
92 
93  std::string
95  {
96  return "Dict";
97  }
98 
100  Dict::navigateAbsolute(const Path& path) const
101  {
102  if (!path.hasElement())
103  {
104  throw error::AronException(
105  __PRETTY_FUNCTION__, "Could not navigate without a valid path", path);
106  }
107 
108  if (path.size() != 1)
109  {
110  throw error::AronException(
111  __PRETTY_FUNCTION__, "Could not get more than 1 value from a dict.", path);
112  }
113 
114  std::string el = path.getFirstElement();
115  if (el != "::accepted_type")
116  {
118  __PRETTY_FUNCTION__, "Could not find an element of a path.", el, path);
119  }
120 
121 
122  return acceptedType;
123  }
124 } // namespace armarx::aron::type
armarx::aron::Path::getFirstElement
std::string getFirstElement() const
Definition: Path.cpp:102
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::aron::type::Dict::setAcceptedType
void setAcceptedType(const VariantPtr &)
Definition: Dict.cpp:49
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::Path::hasElement
bool hasElement() const
Definition: Path.cpp:113
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::aron::Path::size
size_t size() const
Definition: Path.cpp:119
armarx::aron::type::Dict::GetNamePrefix
static std::string GetNamePrefix()
Definition: Dict.cpp:94
detail
Definition: OpenCVUtil.cpp:127
armarx::aron::type::Dict::getChildren
std::vector< VariantPtr > getChildren() const override
get all child elements
Definition: Dict.cpp:64
armarx::aron::type::Dict::GetFullNamePrefix
static std::string GetFullNamePrefix()
Definition: Dict.cpp:88
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::error::ValueNotValidException
The ValueNotValidException class.
Definition: Exception.h:145
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::aron::type::Dict
The Dict class.
Definition: Dict.h:40
armarx::aron::type::detail::SpecializedVariantBase< type::dto::Dict, Dict >::aron
type::dto::Dict ::PointerType aron
Definition: SpecializedVariant.h:137
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::aron::type::Dict::getShortName
std::string getShortName() const override
get a short name of this specific type
Definition: Dict.cpp:76
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::aron::type::Dict::childrenSize
size_t childrenSize() const override
Definition: Dict.cpp:70
armarx::aron::type::Descriptor::DICT
@ DICT
armarx::aron::type::Dict::toDictDTO
type::dto::DictPtr toDictDTO() const
Definition: Dict.cpp:57
armarx::aron::type::Dict::getAcceptedType
VariantPtr getAcceptedType() const
Definition: Dict.cpp:42
armarx::aron::type::Dict::getFullName
std::string getFullName() const override
get the full name of this specific type
Definition: Dict.cpp:82
armarx::aron::type::Variant::path
const Path path
Definition: Variant.h:139
armarx::aron::type::Dict::Dict
Dict(const Path &path=Path())
Definition: Dict.cpp:30
Dict.h
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::Dict::navigateAbsolute
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition: Dict.cpp:100