AnyObject.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#include "AnyObject.h"
25
26#include <SimoxUtility/meta/type_name.h>
27
29{
30 /* constructors */
32 detail::AnyGenerator<type::AnyObject, AnyObject>(
33 "armarx::aron::data::Dict",
34 "armarx::aron::data::Dict",
35 simox::meta::get_type_name<data::dto::Dict>(),
36 simox::meta::get_type_name<type::dto::AnyObject>(),
37 e)
38 {
39 // if the type is not known, we only accept shared ptr for unspecified aron dicts
40 if (type.getMaybe() != type::Maybe::SHARED_PTR)
41 {
42 throw error::ValueNotValidException(
43 __PRETTY_FUNCTION__,
44 "At the moment the unknown any object type must be a shared_ptr! ",
45 std::to_string((int)type.getMaybe()) + " aka " +
46 type::defaultconversion::string::Maybe2String.at(type.getMaybe()),
47 type.getPath());
48 }
49 }
50
51 /* virtual implementations */
52
53 std::vector<std::string>
55 {
56 std::vector<std::string> required_includes = {
57 "<RobotAPI/libraries/aron/core/data/converter/variant/VariantConverter.h>"};
58 return required_includes;
59 }
60
62 AnyObject::getWriteBlock(const std::string& cppAccessor,
63 const Path& p,
64 std::string& variantAccessor) const
65 {
66 auto block_if_data = std::make_shared<CppBlock>();
67 std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
68 variantAccessor = Generator::ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
69
70 block_if_data->addLine(variantAccessor +
71 " = "
72 "::armarx::aron::data::readAndWrite<::armarx::aron::data::"
73 "FromVariantConverter<WriterT>>(" +
74 cppAccessor + "); // of " + cppAccessor);
75
76 return block_if_data;
77 }
78
80 AnyObject::getReadBlock(const std::string& cppAccessor,
81 const std::string& variantAccessor) const
82 {
83 auto block_if_data = std::make_shared<CppBlock>();
84 std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
85
86 block_if_data->addLine(
87 cppAccessor +
88 " = "
89 "::armarx::aron::data::Dict::DynamicCastAndCheck(::armarx::aron::data::readAndWrite<::"
90 "armarx::aron::data::ToVariantConverter<ReaderT>>(" +
91 variantAccessor + ")); // of " + cppAccessor);
92
93 return block_if_data;
94 }
95
97 AnyObject::getWriteTypeBlock(const std::string& typeAccessor,
98 const std::string& accessor,
99 const Path& p,
100 std::string& variantAccessor) const
101 {
102 CppBlockPtr b = std::make_shared<CppBlock>();
103 std::string escaped_accessor = EscapeAccessor(accessor);
104 variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
105
106 b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeAnyObject(" +
107 conversion::Maybe2CppString.at(type.getMaybe()) + ", " +
108 "::armarx::aron::Path(" + ARON_PATH_ACCESSOR + ", {" +
109 simox::alg::join(p.getPath(), ", ") + "})); // of " + typeAccessor);
110 return b;
111 }
112} // namespace armarx::aron::codegenerator::cpp::generator
The Path class.
Definition Path.h:36
std::vector< std::string > getPath() const
Definition Path.cpp:87
static std::string EscapeAccessor(const std::string &)
Definition Generator.cpp:53
static const std::string ARON_PATH_ACCESSOR
Definition Generator.h:163
static const std::string ARON_WRITER_ACCESSOR
Definition Generator.h:165
static const std::string ARON_VARIANT_RETURN_ACCESSOR
Definition Generator.h:167
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const final
Definition AnyObject.cpp:80
std::vector< std::string > getRequiredIncludes() const final
Definition AnyObject.cpp:54
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const final
Definition AnyObject.cpp:62
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const final
Definition AnyObject.cpp:97
The AnyObject class.
Definition AnyObject.h:38
const std::map< type::Maybe, std::string > Maybe2CppString
Definition Generator.h:48
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< CppBlock > CppBlockPtr
Definition CppBlock.h:37
Definition Impl.cpp:41