Pair.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 "Pair.h"
26 
27 namespace armarx::aron::type
28 {
29  // constructors
30  Pair::Pair(const Path& path) :
31  detail::ContainerVariant<type::dto::Pair, Pair>(type::Descriptor::PAIR, path)
32  {
33  }
34 
35  Pair::Pair(const type::dto::Pair& o, const Path& path) :
36  detail::ContainerVariant<type::dto::Pair, Pair>(o, type::Descriptor::PAIR, path),
37  acceptedType1(FromAronDTO(*o.acceptedType1, path.withAcceptedTypeIndex(0))),
38  acceptedType2(FromAronDTO(*o.acceptedType2, path.withAcceptedTypeIndex(1)))
39  {
40  }
41 
42  // Member functions
43  std::pair<VariantPtr, VariantPtr>
45  {
46  return {acceptedType1, acceptedType2};
47  }
48 
51  {
52  return acceptedType1;
53  }
54 
57  {
58  return acceptedType2;
59  }
60 
61  void
63  {
65 
66  if (acceptedType1 == nullptr)
67  {
68  acceptedType1 = n;
69  return;
70  }
71  if (acceptedType2 == nullptr)
72  {
73  acceptedType2 = n;
74  return;
75  }
76  throw error::AronException(__PRETTY_FUNCTION__, "Both types are already set", getPath());
77  }
78 
79  void
81  {
83  acceptedType1 = n;
84  }
85 
86  void
88  {
90  acceptedType2 = n;
91  }
92 
95  {
96  return this->aron;
97  }
98 
99  // virtual implementations
100  std::vector<VariantPtr>
102  {
103  return {acceptedType1, acceptedType2};
104  }
105 
106  size_t
108  {
109  return 2;
110  }
111 
112  std::string
114  {
115  return "Pair<" + acceptedType1->getShortName() + ", " + acceptedType2->getShortName() + ">";
116  }
117 
118  std::string
120  {
121  return "armarx::aron::type::Pair<" + acceptedType1->getFullName() + ", " +
122  acceptedType2->getFullName() + ">";
123  }
124 
125  std::string
127  {
128  return "armarx::aron::type::Pair";
129  }
130 
131  std::string
133  {
134  return "Pair";
135  }
136 
137  VariantPtr
138  Pair::navigateAbsolute(const Path& path) const
139  {
140  if (!path.hasElement())
141  {
142  throw error::AronException(
143  __PRETTY_FUNCTION__, "Could not navigate without a valid path", path);
144  }
145 
146  std::string el = path.getFirstElement();
147  if (el == "::accepted_type_0")
148  {
149  if (path.size() == 1)
150  {
151  return acceptedType1;
152  }
153  else
154  {
156  return acceptedType1->navigateAbsolute(next);
157  }
158  }
159  else if (el == "::accepted_type_1")
160  {
161  if (path.size() == 1)
162  {
163  return acceptedType2;
164  }
165  else
166  {
168  return acceptedType2->navigateAbsolute(next);
169  }
170  }
171  else
172  {
174  __PRETTY_FUNCTION__, "Could not find an element of a path.", el, path);
175  }
176  }
177 } // namespace armarx::aron::type
armarx::aron::type::Pair::GetNamePrefix
static std::string GetNamePrefix()
Definition: Pair.cpp:132
armarx::aron::type::Pair::getAcceptedTypes
std::pair< VariantPtr, VariantPtr > getAcceptedTypes() const
Definition: Pair.cpp:44
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::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::Descriptor::PAIR
@ PAIR
armarx::aron::type::Pair::addAcceptedType
void addAcceptedType(const VariantPtr &)
Definition: Pair.cpp:62
detail
Definition: OpenCVUtil.cpp:127
armarx::aron::type::Pair::getFullName
std::string getFullName() const override
get the full name of this specific type
Definition: Pair.cpp:119
armarx::aron::type::Pair::getFirstAcceptedType
VariantPtr getFirstAcceptedType() const
Definition: Pair.cpp:50
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::error::ValueNotValidException
The ValueNotValidException class.
Definition: Exception.h:145
armarx::aron::type::Pair::getSecondAcceptedType
VariantPtr getSecondAcceptedType() const
Definition: Pair.cpp:56
armarx::aron::type::Pair::getShortName
std::string getShortName() const override
get a short name of this specific type
Definition: Pair.cpp:113
armarx::aron::type::Pair::childrenSize
size_t childrenSize() const override
Definition: Pair.cpp:107
Pair.h
armarx::aron::type::detail::SpecializedVariantBase< type::dto::Pair, Pair >::aron
type::dto::Pair ::PointerType aron
Definition: SpecializedVariant.h:137
armarx::aron::type::PairPtr
std::shared_ptr< class Pair > PairPtr
Definition: forward_declarations.h:16
armarx::aron::type::Pair::Pair
Pair(const Path &path=Path())
Definition: Pair.cpp:30
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::aron::type::Pair
The Pair class.
Definition: Pair.h:39
armarx::aron::type::Pair::navigateAbsolute
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition: Pair.cpp:138
armarx::aron::Path::withDetachedFirstElement
Path withDetachedFirstElement() const
Definition: Path.cpp:205
armarx::aron::type::Pair::setSecondAcceptedType
void setSecondAcceptedType(const VariantPtr &)
Definition: Pair.cpp:87
armarx::aron::type::Variant::path
const Path path
Definition: Variant.h:139
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::Pair::toPairDTO
type::dto::PairPtr toPairDTO() const
Definition: Pair.cpp:94
armarx::aron::type::Pair::getChildren
std::vector< VariantPtr > getChildren() const override
get all child elements
Definition: Pair.cpp:101
armarx::aron::type::Pair::setFirstAcceptedType
void setFirstAcceptedType(const VariantPtr &)
Definition: Pair.cpp:80
armarx::aron::type::Variant::getPath
Path getPath() const
Definition: Variant.h:99
armarx::aron::type::Pair::GetFullNamePrefix
static std::string GetFullNamePrefix()
Definition: Pair.cpp:126