VariantReader.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @author Fabian Peller (fabian dot peller at kit dot edu)
17* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18* GNU General Public License
19*/
20
21// STD/STL
22#include <memory>
23#include <numeric>
24
25// Header
26#include "VariantReader.h"
27
28// ArmarX
32
34{
35
41
42 std::optional<float>
44 {
46 return input->getImportance();
47 }
48
49 void
51 std::vector<data::VariantPtr>& elements,
52 Path& p)
53 {
55 auto o = data::List::DynamicCastAndCheck(input);
56 elements = o->getElements();
57 p = o->getPath();
58 }
59
60 void
62 std::map<std::string, data::VariantPtr>& elements,
63 Path& p)
64 {
66 auto o = data::Dict::DynamicCastAndCheck(input);
67 elements = o->getElements();
68 p = o->getPath();
69 }
70
71 void
73 std::vector<int>& shape,
74 std::string& typeAsString,
75 std::vector<unsigned char>& data,
76 Path& p)
77 {
80 shape = o->getShape();
81 typeAsString = o->getType();
82 data = o->getDataAsVector();
83 p = o->getPath();
84 }
85
86 void
87 VariantReader::readInt(const data::VariantPtr& input, int& i, Path& p)
88 {
90 auto o = data::Int::DynamicCastAndCheck(input);
91 i = o->getValue();
92 p = o->getPath();
93 }
94
95 void
96 VariantReader::readLong(const data::VariantPtr& input, long& i, Path& p)
97 {
99 auto o = data::Long::DynamicCastAndCheck(input);
100 i = o->getValue();
101 p = o->getPath();
102 }
103
104 void
105 VariantReader::readFloat(const data::VariantPtr& input, float& i, Path& p)
106 {
108 auto o = data::Float::DynamicCastAndCheck(input);
109 i = o->getValue();
110 p = o->getPath();
111 }
112
113 void
114 VariantReader::readDouble(const data::VariantPtr& input, double& i, Path& p)
115 {
117 auto o = data::Double::DynamicCastAndCheck(input);
118 i = o->getValue();
119 p = o->getPath();
120 }
121
122 void
123 VariantReader::readString(const data::VariantPtr& input, std::string& i, Path& p)
124 {
126 auto o = data::String::DynamicCastAndCheck(input);
127 i = o->getValue();
128 p = o->getPath();
129 }
130
131 void
132 VariantReader::readBool(const data::VariantPtr& input, bool& i, Path& p)
133 {
135 auto o = data::Bool::DynamicCastAndCheck(input);
136 i = o->getValue();
137 p = o->getPath();
138 }
139} // namespace armarx::aron::data::reader
The Path class.
Definition Path.h:36
std::vector< std::string > getPath() const
Definition Path.cpp:87
void readBool(InputType &input, bool &i, Path &p) final
std::optional< float > readImportance(InputType &input) final
void readDict(InputType &input, std::map< std::string, InputTypeNonConst > &elements, Path &p) final
void readLong(InputType &input, long &i, Path &p) final
void readList(InputType &input, std::vector< InputTypeNonConst > &elements, Path &p) final
void readInt(InputType &input, int &i, Path &p) final
void readString(InputType &input, std::string &s, Path &p) final
void readNDArray(InputType &input, std::vector< int > &shape, std::string &typeAsString, std::vector< unsigned char > &data, Path &p) final
void readDouble(InputType &input, double &i, Path &p) final
data::Descriptor getDescriptor(InputType &input) final
void readFloat(InputType &input, float &i, Path &p) final
#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...
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< Variant > VariantPtr
static data::Descriptor GetDescriptor(Input &n)