VariantVisitor.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 #include <map>
27 #include <string>
28 #include <vector>
29 
30 #include "../../variant/forward_declarations.h"
31 #include "../RecursiveVisitor.h"
32 
33 namespace armarx::aron::type
34 {
35  /**
36  * @brief The VariantVisitor struct. Already implements the method to get the descriptor of an aron variant.
37  */
38  struct ConstVariantVisitor : virtual public Visitor<const type::VariantPtr>
39  {
42  virtual ~ConstVariantVisitor() = default;
43 
44  // Already implemented so that they cast the input and call specilized method below
45  // Override if you do not want to use the specialized methods
46  void visitObject(Input&) override;
47  void visitDict(Input&) override;
48  void visitPair(Input&) override;
49  void visitTuple(Input&) override;
50  void visitList(Input&) override;
51  void visitMatrix(Input&) override;
52  void visitNDArray(Input&) override;
53  void visitQuaternion(Input&) override;
54  void visitImage(Input&) override;
55  void visitPointCloud(Input&) override;
56  void visitIntEnum(Input&) override;
57  void visitInt(Input&) override;
58  void visitLong(Input&) override;
59  void visitFloat(Input&) override;
60  void visitDouble(Input&) override;
61  void visitBool(Input&) override;
62  void visitString(Input&) override;
63  void visitAnyObject(Input&) override;
64 
65  // Use these if you do not want to cast manually
66  virtual void visitAronVariant(const type::ObjectPtr&);
67  virtual void visitAronVariant(const type::DictPtr&);
68  virtual void visitAronVariant(const type::ListPtr&);
69  virtual void visitAronVariant(const type::PairPtr&);
70  virtual void visitAronVariant(const type::TuplePtr&);
71  virtual void visitAronVariant(const type::MatrixPtr&);
72  virtual void visitAronVariant(const type::NDArrayPtr&);
73  virtual void visitAronVariant(const type::QuaternionPtr&);
74  virtual void visitAronVariant(const type::PointCloudPtr&);
75  virtual void visitAronVariant(const type::ImagePtr&);
76  virtual void visitAronVariant(const type::IntEnumPtr&);
77  virtual void visitAronVariant(const type::IntPtr&);
78  virtual void visitAronVariant(const type::LongPtr&);
79  virtual void visitAronVariant(const type::FloatPtr&);
80  virtual void visitAronVariant(const type::DoublePtr&);
81  virtual void visitAronVariant(const type::BoolPtr&);
82  virtual void visitAronVariant(const type::StringPtr&);
83  virtual void visitAronVariant(const type::AnyObjectPtr&);
84  };
85 
86  /**
87  * @brief The RecursiveVariantVisitor struct. Already implements the methods to get the descriptor and children of an aron variant
88  */
89  struct RecursiveConstVariantVisitor : virtual public RecursiveVisitor<const type::VariantPtr>
90  {
102 
103  void visitObjectOnEnter(Input&) override;
104  void visitObjectOnExit(Input&) override;
105  void visitDictOnEnter(Input&) override;
106  void visitDictOnExit(Input&) override;
107  void visitPairOnEnter(Input&) override;
108  void visitPairOnExit(Input&) override;
109  void visitTupleOnEnter(Input&) override;
110  void visitTupleOnExit(Input&) override;
111  void visitListOnEnter(Input&) override;
112  void visitListOnExit(Input&) override;
113 
114  void visitMatrix(Input&) override;
115  void visitNDArray(Input&) override;
116  void visitQuaternion(Input&) override;
117  void visitImage(Input&) override;
118  void visitPointCloud(Input&) override;
119  void visitIntEnum(Input&) override;
120  void visitInt(Input&) override;
121  void visitLong(Input&) override;
122  void visitFloat(Input&) override;
123  void visitDouble(Input&) override;
124  void visitBool(Input&) override;
125  void visitString(Input&) override;
126  void visitAnyObject(Input&) override;
127 
128 
129  // Use these if you do not want to cast manually
130  virtual void visitAronVariantEnter(const type::ObjectPtr&);
131  virtual void visitAronVariantExit(const type::ObjectPtr&);
132  virtual void visitAronVariantEnter(const type::DictPtr&);
133  virtual void visitAronVariantExit(const type::DictPtr&);
134  virtual void visitAronVariantEnter(const type::ListPtr&);
135  virtual void visitAronVariantExit(const type::ListPtr&);
136  virtual void visitAronVariantEnter(const type::PairPtr&);
137  virtual void visitAronVariantExit(const type::PairPtr&);
138  virtual void visitAronVariantEnter(const type::TuplePtr&);
139  virtual void visitAronVariantExit(const type::TuplePtr&);
140  virtual void visitAronVariant(const type::MatrixPtr&);
141  virtual void visitAronVariant(const type::NDArrayPtr&);
142  virtual void visitAronVariant(const type::QuaternionPtr&);
143  virtual void visitAronVariant(const type::PointCloudPtr&);
144  virtual void visitAronVariant(const type::ImagePtr&);
145  virtual void visitAronVariant(const type::IntEnumPtr&);
146  virtual void visitAronVariant(const type::IntPtr&);
147  virtual void visitAronVariant(const type::LongPtr&);
148  virtual void visitAronVariant(const type::FloatPtr&);
149  virtual void visitAronVariant(const type::DoublePtr&);
150  virtual void visitAronVariant(const type::BoolPtr&);
151  virtual void visitAronVariant(const type::StringPtr&);
152  virtual void visitAronVariant(const type::AnyObjectPtr&);
153 
154  virtual ~RecursiveConstVariantVisitor() = default;
155  };
156 } // namespace armarx::aron::type
armarx::aron::type::RecursiveVisitor< const type::VariantPtr >::ObjectElements
std::map< std::string, InputNonConst > ObjectElements
Definition: RecursiveVisitor.h:132
armarx::aron::type::VisitorBase< const type::VariantPtr >::Input
const type::VariantPtr Input
Definition: Visitor.h:94
armarx::aron::type::ConstVariantVisitor::visitList
void visitList(Input &) override
Definition: VariantVisitor.cpp:79
armarx::aron::type::MatrixPtr
std::shared_ptr< class Matrix > MatrixPtr
Definition: forward_declarations.h:20
armarx::aron::type::RecursiveConstVariantVisitor::visitTupleOnEnter
void visitTupleOnEnter(Input &) override
Definition: VariantVisitor.cpp:383
armarx::aron::type::AnyObjectPtr
std::shared_ptr< class AnyObject > AnyObjectPtr
Definition: forward_declarations.h:34
armarx::aron::type::RecursiveConstVariantVisitor::GetTupleAcceptedTypes
static TupleElements GetTupleAcceptedTypes(Input &t)
Definition: VariantVisitor.cpp:328
armarx::aron::type::RecursiveConstVariantVisitor::visitInt
void visitInt(Input &) override
Definition: VariantVisitor.cpp:453
armarx::aron::type::RecursiveConstVariantVisitor::visitString
void visitString(Input &) override
Definition: VariantVisitor.cpp:488
armarx::aron::type::ConstVariantVisitor::visitQuaternion
void visitQuaternion(Input &) override
Definition: VariantVisitor.cpp:100
armarx::aron::type::ImagePtr
std::shared_ptr< class Image > ImagePtr
Definition: forward_declarations.h:22
armarx::aron::type::NDArrayPtr
std::shared_ptr< class NDArray > NDArrayPtr
Definition: forward_declarations.h:19
armarx::aron::type::ConstVariantVisitor::visitInt
void visitInt(Input &) override
Definition: VariantVisitor.cpp:128
armarx::aron::type::ConstVariantVisitor::visitPair
void visitPair(Input &) override
Definition: VariantVisitor.cpp:65
armarx::aron::type::Visitor
The Visitor struct.
Definition: Visitor.h:104
armarx::aron::type::RecursiveVisitor< const type::VariantPtr >::TupleElements
std::vector< InputNonConst > TupleElements
Definition: RecursiveVisitor.h:134
armarx::aron::type::RecursiveConstVariantVisitor::visitPairOnEnter
void visitPairOnEnter(Input &) override
Definition: VariantVisitor.cpp:369
armarx::aron::type::RecursiveConstVariantVisitor::GetDictAcceptedType
static InputNonConst GetDictAcceptedType(Input &t)
Definition: VariantVisitor.cpp:289
armarx::aron::type::RecursiveVisitor< const type::VariantPtr >::PairElements
std::pair< InputNonConst, InputNonConst > PairElements
Definition: RecursiveVisitor.h:133
armarx::aron::type::TuplePtr
std::shared_ptr< class Tuple > TuplePtr
Definition: forward_declarations.h:17
armarx::aron::type::RecursiveConstVariantVisitor::visitPointCloud
void visitPointCloud(Input &) override
Definition: VariantVisitor.cpp:439
armarx::aron::type::RecursiveConstVariantVisitor::getPairAcceptedTypes
PairElements getPairAcceptedTypes(Input &t) override
Definition: VariantVisitor.cpp:322
armarx::aron::type::RecursiveConstVariantVisitor::GetObjectAcceptedTypes
static ObjectElements GetObjectAcceptedTypes(Input &t)
Definition: VariantVisitor.cpp:276
armarx::aron::type::ConstVariantVisitor::visitString
void visitString(Input &) override
Definition: VariantVisitor.cpp:163
armarx::aron::type::PointCloudPtr
std::shared_ptr< class PointCloud > PointCloudPtr
Definition: forward_declarations.h:23
armarx::aron::type::RecursiveConstVariantVisitor
The RecursiveVariantVisitor struct.
Definition: VariantVisitor.h:89
armarx::aron::type::RecursiveVisitor< const type::VariantPtr >::Input
typename VisitorBase< const type::VariantPtr >::Input Input
Definition: RecursiveVisitor.h:129
armarx::aron::type::ConstVariantVisitor::visitNDArray
void visitNDArray(Input &) override
Definition: VariantVisitor.cpp:93
armarx::aron::type::FloatPtr
std::shared_ptr< class Float > FloatPtr
Definition: forward_declarations.h:29
armarx::aron::type::RecursiveVisitor< const type::VariantPtr >::InputNonConst
typename std::remove_const< Input >::type InputNonConst
Definition: RecursiveVisitor.h:130
armarx::aron::type::ListPtr
std::shared_ptr< class List > ListPtr
Definition: forward_declarations.h:14
armarx::aron::type::RecursiveConstVariantVisitor::getObjectAcceptedTypes
ObjectElements getObjectAcceptedTypes(Input &t) override
Definition: VariantVisitor.cpp:283
armarx::aron::type::RecursiveConstVariantVisitor::visitObjectOnExit
void visitObjectOnExit(Input &) override
Definition: VariantVisitor.cpp:348
armarx::aron::type::LongPtr
std::shared_ptr< class Long > LongPtr
Definition: forward_declarations.h:28
armarx::aron::type::RecursiveConstVariantVisitor::visitNDArray
void visitNDArray(Input &) override
Definition: VariantVisitor.cpp:418
armarx::aron::type::StringPtr
std::shared_ptr< class String > StringPtr
Definition: forward_declarations.h:31
armarx::aron::type::RecursiveConstVariantVisitor::visitTupleOnExit
void visitTupleOnExit(Input &) override
Definition: VariantVisitor.cpp:390
armarx::aron::type::RecursiveConstVariantVisitor::getDescriptor
type::Descriptor getDescriptor(Input &n) override
Definition: VariantVisitor.cpp:270
armarx::aron::type::ConstVariantVisitor::visitAnyObject
void visitAnyObject(Input &) override
Definition: VariantVisitor.cpp:170
armarx::aron::type::RecursiveConstVariantVisitor::~RecursiveConstVariantVisitor
virtual ~RecursiveConstVariantVisitor()=default
armarx::aron::type::ConstVariantVisitor::getDescriptor
type::Descriptor getDescriptor(Input &n) override
Definition: VariantVisitor.cpp:45
armarx::aron::type::RecursiveConstVariantVisitor::getListAcceptedType
InputNonConst getListAcceptedType(Input &t) override
Definition: VariantVisitor.cpp:309
armarx::aron::type::RecursiveConstVariantVisitor::visitPairOnExit
void visitPairOnExit(Input &) override
Definition: VariantVisitor.cpp:376
armarx::aron::type::ConstVariantVisitor::visitIntEnum
void visitIntEnum(Input &) override
Definition: VariantVisitor.cpp:121
armarx::aron::type::ConstVariantVisitor::visitAronVariant
virtual void visitAronVariant(const type::ObjectPtr &)
Definition: VariantVisitor.cpp:177
armarx::aron::type::RecursiveConstVariantVisitor::visitAronVariant
virtual void visitAronVariant(const type::MatrixPtr &)
Definition: VariantVisitor.cpp:557
armarx::aron::type::PairPtr
std::shared_ptr< class Pair > PairPtr
Definition: forward_declarations.h:16
armarx::aron::type::DictPtr
std::shared_ptr< class Dict > DictPtr
Definition: forward_declarations.h:13
armarx::aron::type::RecursiveConstVariantVisitor::visitImage
void visitImage(Input &) override
Definition: VariantVisitor.cpp:432
armarx::aron::type::RecursiveConstVariantVisitor::visitDouble
void visitDouble(Input &) override
Definition: VariantVisitor.cpp:474
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::aron::type::RecursiveConstVariantVisitor::visitFloat
void visitFloat(Input &) override
Definition: VariantVisitor.cpp:467
armarx::aron::type::BoolPtr
std::shared_ptr< class Bool > BoolPtr
Definition: forward_declarations.h:32
armarx::aron::type::RecursiveConstVariantVisitor::GetListAcceptedType
static InputNonConst GetListAcceptedType(Input &t)
Definition: VariantVisitor.cpp:302
armarx::aron::type::ConstVariantVisitor::visitBool
void visitBool(Input &) override
Definition: VariantVisitor.cpp:156
armarx::aron::type::RecursiveConstVariantVisitor::visitBool
void visitBool(Input &) override
Definition: VariantVisitor.cpp:481
armarx::aron::type::RecursiveConstVariantVisitor::visitAronVariantEnter
virtual void visitAronVariantEnter(const type::ObjectPtr &)
Definition: VariantVisitor.cpp:502
armarx::aron::type::RecursiveConstVariantVisitor::getDictAcceptedType
InputNonConst getDictAcceptedType(Input &t) override
Definition: VariantVisitor.cpp:296
armarx::aron::type::ConstVariantVisitor::visitPointCloud
void visitPointCloud(Input &) override
Definition: VariantVisitor.cpp:114
armarx::aron::type::RecursiveConstVariantVisitor::GetPairAcceptedTypes
static PairElements GetPairAcceptedTypes(Input &t)
Definition: VariantVisitor.cpp:315
armarx::aron::type::ConstVariantVisitor::visitTuple
void visitTuple(Input &) override
Definition: VariantVisitor.cpp:72
armarx::aron::type::RecursiveConstVariantVisitor::visitListOnExit
void visitListOnExit(Input &) override
Definition: VariantVisitor.cpp:404
armarx::aron::type::ConstVariantVisitor::visitMatrix
void visitMatrix(Input &) override
Definition: VariantVisitor.cpp:86
armarx::aron::type::RecursiveConstVariantVisitor::visitMatrix
void visitMatrix(Input &) override
Definition: VariantVisitor.cpp:411
armarx::aron::type::RecursiveConstVariantVisitor::visitDictOnEnter
void visitDictOnEnter(Input &) override
Definition: VariantVisitor.cpp:355
armarx::aron::type::RecursiveConstVariantVisitor::visitAronVariantExit
virtual void visitAronVariantExit(const type::ObjectPtr &)
Definition: VariantVisitor.cpp:507
armarx::aron::type::RecursiveConstVariantVisitor::visitQuaternion
void visitQuaternion(Input &) override
Definition: VariantVisitor.cpp:425
armarx::aron::type::RecursiveVisitor
The RecursiveVisitor struct.
Definition: RecursiveVisitor.h:127
armarx::aron::type::ConstVariantVisitor::GetDescriptor
static type::Descriptor GetDescriptor(Input &n)
Definition: VariantVisitor.cpp:35
armarx::aron::type::IntEnumPtr
std::shared_ptr< IntEnum > IntEnumPtr
Definition: IntEnum.h:36
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::aron::type::ConstVariantVisitor
The VariantVisitor struct.
Definition: VariantVisitor.h:38
armarx::aron::type::RecursiveConstVariantVisitor::visitListOnEnter
void visitListOnEnter(Input &) override
Definition: VariantVisitor.cpp:397
armarx::aron::type::ConstVariantVisitor::visitFloat
void visitFloat(Input &) override
Definition: VariantVisitor.cpp:142
armarx::aron::type::QuaternionPtr
std::shared_ptr< class Quaternion > QuaternionPtr
Definition: forward_declarations.h:21
armarx::aron::type::IntPtr
std::shared_ptr< class Int > IntPtr
Definition: forward_declarations.h:27
armarx::aron::type::RecursiveConstVariantVisitor::visitLong
void visitLong(Input &) override
Definition: VariantVisitor.cpp:460
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::DoublePtr
std::shared_ptr< class Double > DoublePtr
Definition: forward_declarations.h:30
armarx::aron::type::RecursiveConstVariantVisitor::getTupleAcceptedTypes
TupleElements getTupleAcceptedTypes(Input &t) override
Definition: VariantVisitor.cpp:335
armarx::aron::type::ConstVariantVisitor::visitDouble
void visitDouble(Input &) override
Definition: VariantVisitor.cpp:149
armarx::aron::type::RecursiveConstVariantVisitor::visitDictOnExit
void visitDictOnExit(Input &) override
Definition: VariantVisitor.cpp:362
armarx::aron::type::ConstVariantVisitor::visitDict
void visitDict(Input &) override
Definition: VariantVisitor.cpp:58
armarx::aron::type::RecursiveConstVariantVisitor::visitObjectOnEnter
void visitObjectOnEnter(Input &) override
Definition: VariantVisitor.cpp:341
armarx::aron::type::ConstVariantVisitor::visitImage
void visitImage(Input &) override
Definition: VariantVisitor.cpp:107
armarx::aron::type::RecursiveConstVariantVisitor::visitIntEnum
void visitIntEnum(Input &) override
Definition: VariantVisitor.cpp:446
armarx::aron::type::RecursiveConstVariantVisitor::visitAnyObject
void visitAnyObject(Input &) override
Definition: VariantVisitor.cpp:495
armarx::aron::type::ConstVariantVisitor::visitLong
void visitLong(Input &) override
Definition: VariantVisitor.cpp:135
armarx::aron::type::ConstVariantVisitor::~ConstVariantVisitor
virtual ~ConstVariantVisitor()=default
armarx::aron::type::ConstVariantVisitor::visitObject
void visitObject(Input &) override
Definition: VariantVisitor.cpp:51