VariantVisitor.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 "VariantVisitor.h"
26
28#include "../../variant/All.h"
29
30namespace armarx::aron::data
31{
32 /****************************************************************************
33 * ConstVariantVisitor
34 ***************************************************************************/
37 {
38 if (!n)
39 {
41 }
42 return n->getDescriptor();
43 }
44
50
51 void
57
58 void
64
65 void
71
72 void
78
79 void
85
86 void
92
93 void
99
100 void
106
107 void
113
114 void
118
119 void
123
124 void
128
129 void
133
134 void
138
139 void
143
144 void
148
149 void
153
154 void
158
159 /****************************************************************************
160 * ConstTypedVariantVisitor
161 ***************************************************************************/
164 {
166 if (t_desc == type::Descriptor::UNKNOWN)
167 {
168 auto d_desc = ConstVariantVisitor::GetDescriptor(i);
170 }
171 return t_desc;
172 }
173
179
180 void
187
188 void
195
196 void
203
204 void
211
212 void
219
220 void
222 {
224 auto t = type::Matrix::DynamicCastAndCheck(j);
225 visitAronVariant(d, t);
226 }
227
228 void
235
236 void
243
244 void
251
252 void
259
260 void
267
268 void
275
276 void
283
284 void
291
292 void
299
300 void
307
308 void
315
316 void
320
321 void
325
326 void
330
331 void
335
336 void
340
341 void
345
346 void
350
351 void
355
356 void
360
361 void
365
366 void
370
371 void
375
376 void
380
381 void
385
386 void
390
391 void
395
396 void
400
401 /****************************************************************************
402 * RecursiveConstVariantVisitor
403 ***************************************************************************/
409
412 {
414 return x->getElements();
415 }
416
422
425 {
427 return x->getElements();
428 }
429
435
436 void
442
443 void
449
450 void
456
457 void
463
464 void
470
471 void
477
478 void
484
485 void
491
492 void
498
499 void
505
506 void
512
513 void
517
518 void
522
523 void
527
528 void
532
533 void
537
538 void
542
543 void
547
548 void
552
553 void
557
558 void
562
563 void
567
568 /****************************************************************************
569 * RecursiveVariantVisitor
570 ***************************************************************************/
576
577 std::map<std::string, RecursiveVariantVisitor::InputNonConst>
582
583 std::vector<RecursiveVariantVisitor::InputNonConst>
588
589 void
595
596 void
602
603 void
609
610 void
616
617 void
623
624 void
630
631 void
637
638 void
644
645 void
651
652 void
658
659 void
665
666 void
670
671 void
675
676 void
680
681 void
685
686 void
690
691 void
695
696 void
700
701 void
705
706 void
710
711 void
715
716 void
720
721 /****************************************************************************
722 * RecursiveConstTypedVariantVisitor
723 ***************************************************************************/
729
732 {
733 std::map<std::string, std::pair<data::VariantPtr, type::VariantPtr>> ret;
736
738
739 if (x)
740 {
741 for (const auto& [key, e] : x->getElements())
742 {
743 auto ct = y->getMemberType(key);
744 ret.insert({key, {e, ct}});
745 }
746 }
747 return ret;
748 }
749
752 {
753 std::map<std::string, std::pair<aron::data::VariantPtr, aron::type::VariantPtr>> ret;
756
757 if (data)
758 {
759 for (const auto& [key, e] : data->getElements())
760 {
761 if (type && type->hasMemberType(key))
762 {
763 auto memberType = type->getMemberType(key);
764 ret.insert({key, {e, memberType}});
765 }
766 else
767 {
768 ret.insert({key, {e, nullptr}});
769 }
770 }
771 }
772 return ret;
773 }
774
777 {
778 std::map<std::string, std::pair<data::VariantPtr, type::VariantPtr>> ret;
781
782 auto ac = y ? y->getAcceptedType() : nullptr;
783
784 if (x)
785 {
786 for (const auto& [key, e] : x->getElements())
787 {
788 ret.insert({key, {e, ac}});
789 }
790 }
791 return ret;
792 }
793
796 {
797 std::vector<std::pair<data::VariantPtr, type::VariantPtr>> ret;
800
801 auto ac = y ? y->getAcceptedType() : nullptr;
802
803 if (x)
804 {
805 for (const auto& e : x->getElements())
806 {
807 ret.push_back({e, ac});
808 }
809 }
810 return ret;
811 }
812
815 {
818
820
821 if (x)
822 {
823 auto e0 = x->getElement(0);
824 auto ac0 = y->getFirstAcceptedType();
825 auto e1 = x->getElement(1);
826 auto ac1 = y->getSecondAcceptedType();
827 return {{e0, ac0}, {e1, ac1}};
828 }
829 return {};
830 }
831
834 {
835 std::vector<std::pair<data::VariantPtr, type::VariantPtr>> ret;
838
840
841 if (x)
842 {
843 unsigned int i = 0;
844 for (const auto& e : x->getElements())
845 {
846 auto ac = y->getAcceptedType(i++);
847 ret.push_back({e, ac});
848 }
849 }
850 return ret;
851 }
852
858
864
870
876
882
883 void
890
891 void
898
899 void
906
907 void
914
915 void
922
923 void
930
931 void
938
939 void
946
947 void
954
955 void
962
963 void
965 {
967 auto t = type::Matrix::DynamicCastAndCheck(j);
968 visitAronVariant(d, t);
969 }
970
971 void
978
979 void
986
987 void
994
995 void
1002
1003 void
1010
1011 void
1018
1019 void
1026
1027 void
1034
1035 void
1042
1043 void
1050
1051 void
1058
1059 // see above
1060 void
1065
1066 void
1071
1072 void
1077
1078 void
1083
1084 void
1089
1090 void
1095
1096 void
1101
1102 void
1107
1108 void
1113
1114 void
1119
1120 void
1125
1126 void
1131
1132 void
1137
1138 void
1143
1144 void
1149
1150 void
1155
1156 void
1160
1161 void
1165
1166 void
1171
1172 void
1177
1178 void
1182
1183 void
1188} // namespace armarx::aron::data
#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...
const std::map< Descriptor, aron::type::Descriptor > Data2TypeDescriptor
Definition Descriptor.h:245
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< List > ListPtr
Definition List.h:41
std::shared_ptr< Bool > BoolPtr
std::shared_ptr< Float > FloatPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition NDArray.h:46
std::shared_ptr< Long > LongPtr
std::shared_ptr< Int > IntPtr
std::shared_ptr< Double > DoublePtr
std::shared_ptr< String > StringPtr
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< class Quaternion > QuaternionPtr
std::shared_ptr< Object > ObjectPtr
Definition Object.h:36
std::shared_ptr< class Double > DoublePtr
std::shared_ptr< class Matrix > MatrixPtr
std::shared_ptr< class Image > ImagePtr
std::shared_ptr< class Long > LongPtr
std::shared_ptr< class String > StringPtr
std::shared_ptr< class PointCloud > PointCloudPtr
std::shared_ptr< class Pair > PairPtr
std::shared_ptr< class NDArray > NDArrayPtr
std::shared_ptr< class Int > IntPtr
std::shared_ptr< class Float > FloatPtr
std::shared_ptr< class Bool > BoolPtr
std::shared_ptr< class Tuple > TuplePtr
std::shared_ptr< class Dict > DictPtr
std::shared_ptr< IntEnum > IntEnumPtr
Definition IntEnum.h:36
std::shared_ptr< class List > ListPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
void visitPair(DataInput &, TypeInput &) override
void visitMatrix(DataInput &, TypeInput &) override
void visitString(DataInput &, TypeInput &) override
type::Descriptor getDescriptor(DataInput &i, TypeInput &j) override
void visitImage(DataInput &, TypeInput &) override
void visitObject(DataInput &i, TypeInput &j) override
void visitTuple(DataInput &, TypeInput &) override
void visitDict(DataInput &, TypeInput &) override
void visitList(DataInput &, TypeInput &) override
void visitQuaternion(DataInput &, TypeInput &) override
void visitLong(DataInput &, TypeInput &) override
void visitFloat(DataInput &, TypeInput &) override
void visitPointCloud(DataInput &, TypeInput &) override
void visitIntEnum(DataInput &, TypeInput &) override
static type::Descriptor GetDescriptor(DataInput &i, TypeInput &j)
void visitNDArray(DataInput &, TypeInput &) override
void visitInt(DataInput &, TypeInput &) override
void visitDouble(DataInput &, TypeInput &) override
void visitBool(DataInput &, TypeInput &) override
virtual void visitAronVariant(const data::DictPtr &, const type::ObjectPtr &)
data::Descriptor getDescriptor(Input &n) override
static data::Descriptor GetDescriptor(Input &n)
virtual void visitAronVariant(const data::DictPtr &)
void visitMatrix(DataInput &, TypeInput &) override
void visitString(DataInput &, TypeInput &) override
static ListElements GetListElements(DataInput &o, TypeInput &t)
void visitPairOnEnter(DataInput &, TypeInput &) override
void visitImage(DataInput &, TypeInput &) override
ListElements getListElements(DataInput &o, TypeInput &t) override
static MapElements GetDictElements(DataInput &o, TypeInput &t)
static MapElements GetObjectElements(DataInput &o, TypeInput &t)
void visitObjectOnEnter(DataInput &, TypeInput &) override
static MapElements GetObjectElementsWithNullType(DataInput &o, TypeInput &t)
void visitTupleOnEnter(DataInput &, TypeInput &) override
type::Descriptor getDescriptor(DataInput &o, TypeInput &n) override
MapElements getObjectElements(DataInput &o, TypeInput &t) override
void visitObjectOnExit(DataInput &i, TypeInput &j) override
void visitDictOnExit(DataInput &, TypeInput &) override
void visitQuaternion(DataInput &, TypeInput &) override
void visitTupleOnExit(DataInput &, TypeInput &) override
TupleElements getTupleElements(DataInput &o, TypeInput &t) override
void visitLong(DataInput &, TypeInput &) override
PairElements getPairElements(DataInput &o, TypeInput &t) override
void visitFloat(DataInput &, TypeInput &) override
void visitPointCloud(DataInput &, TypeInput &) override
virtual void visitAronVariantOnExit(const data::DictPtr &, const type::ObjectPtr &)
void visitIntEnum(DataInput &, TypeInput &) override
static TupleElements GetTupleElements(DataInput &o, TypeInput &t)
void visitNDArray(DataInput &, TypeInput &) override
void visitListOnExit(DataInput &, TypeInput &) override
virtual void visitAronVariant(const data::NDArrayPtr &, const type::MatrixPtr &)
void visitDictOnEnter(DataInput &, TypeInput &) override
void visitInt(DataInput &, TypeInput &) override
void visitDouble(DataInput &, TypeInput &) override
MapElements getDictElements(DataInput &o, TypeInput &t) override
void visitListOnEnter(DataInput &, TypeInput &) override
static PairElements GetPairElements(DataInput &o, TypeInput &t)
void visitPairOnExit(DataInput &, TypeInput &) override
virtual void visitAronVariantOnEnter(const data::DictPtr &, const type::ObjectPtr &)
void visitBool(DataInput &, TypeInput &) override
virtual void visitAronVariantOnExit(const data::DictPtr &)
data::Descriptor getDescriptor(Input &n) override
virtual void visitAronVariantOnEnter(const data::DictPtr &)
ListElements getListElements(Input &n) override
virtual void visitAronVariant(const data::NDArrayPtr &)
typename TypedVisitorBase< const data::VariantPtr, const type::VariantPtr >::TypeInput TypeInput
std::vector< std::pair< DataInputNonConst, TypeInputNonConst > > ListElements
typename TypedVisitorBase< const data::VariantPtr, const type::VariantPtr >::DataInput DataInput
std::pair< std::pair< DataInputNonConst, TypeInputNonConst >, std::pair< DataInputNonConst, TypeInputNonConst > > PairElements
std::vector< std::pair< DataInputNonConst, TypeInputNonConst > > TupleElements
std::map< std::string, std::pair< DataInputNonConst, TypeInputNonConst > > MapElements
data::Descriptor getDescriptor(Input &n) override
std::map< std::string, InputNonConst > getDictElements(Input &n) override
std::vector< InputNonConst > getListElements(Input &n) override
virtual void visitAronVariantOnExit(data::DictPtr &)
virtual void visitAronVariant(data::NDArrayPtr &)
virtual void visitAronVariantOnEnter(data::DictPtr &)
typename VisitorBase< const data::VariantPtr >::Input Input
typename TypedVisitorBase< const data::VariantPtr, const type::VariantPtr >::TypeInput TypeInput
Definition Visitor.h:94
typename TypedVisitorBase< const data::VariantPtr, const type::VariantPtr >::DataInput DataInput
Definition Visitor.h:93
typename VisitorBase< const data::VariantPtr >::Input Input
Definition Visitor.h:66
static type::Descriptor GetDescriptor(Input &n)