String.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 "String.h"
25
26#include <SimoxUtility/meta/type_name.h>
27
29{
30 /* constructors */
32 detail::PrimitiveGenerator<type::String, String>(
33 "std::string",
34 "std::string",
35 simox::meta::get_type_name<data::dto::AronString>(),
36 simox::meta::get_type_name<type::dto::AronString>(),
37 e)
38 {
39 }
40
41 /* virtual implementations */
42 std::pair<std::vector<std::pair<std::string, std::string>>, bool>
43 String::getCtorInitializers(const std::string& name) const
44 {
45 if (auto def = type.getDefaultValue(); def.has_value())
46 {
47 return {{{name, "\"" + *def + "\""}}, true};
48 }
49 return {{}, false};
50 }
51
53 String::getWriteTypeBlock(const std::string& typeAccessor,
54 const std::string& accessor,
55 const Path& p,
56 std::string& variantAccessor) const
57 {
58 CppBlockPtr b = std::make_shared<CppBlock>();
59 std::string escaped_accessor = EscapeAccessor(accessor);
60 variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
61
62 std::string defaultValue = type.getDefaultValue().has_value()
63 ? ("\"" + *type.getDefaultValue() + "\"")
64 : "std::nullopt";
65
66 b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeString(" +
67 defaultValue + ", " + conversion::Maybe2CppString.at(type.getMaybe()) + ", " +
68 "armarx::aron::Path(" + ARON_PATH_ACCESSOR + ", {" +
69 simox::alg::join(p.getPath(), ", ") + "})); // of " + typeAccessor);
70 return b;
71 }
72
74 String::getResetHardBlock(const std::string& cppAccessor) const
75 {
76 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
77 block_if_data->addLine(cppAccessor + " = \"\";");
78 return resolveMaybeResetHardBlock(block_if_data, cppAccessor);
79 }
80
82 String::getResetSoftBlock(const std::string& cppAccessor) const
83 {
84 auto block_if_data = std::make_shared<CppBlock>();
85 block_if_data->addLine(cppAccessor + " = \"\";");
86 return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor);
87 }
88} // namespace armarx::aron::codegenerator::cpp::generator
The Path class.
Definition Path.h:36
std::vector< std::string > getPath() const
Definition Path.cpp:87
CppBlockPtr resolveMaybeResetHardBlock(const CppBlockPtr &, const std::string &) const
static std::string EscapeAccessor(const std::string &)
Definition Generator.cpp:53
CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr &, const std::string &) const
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 getResetHardBlock(const std::string &cppAccessor) const final
Definition String.cpp:74
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const final
Definition String.cpp:53
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const final
Definition String.cpp:43
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
Definition String.cpp:82
The String class.
Definition String.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