PrimitiveGenerator.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 <string>
27
29
31{
32 template <typename typeT, typename DerivedT>
33 class PrimitiveGenerator : public SpecializedGeneratorBase<typeT, DerivedT>
34 {
35 public:
37 virtual ~PrimitiveGenerator() = default;
38
40 getWriteBlock(const std::string& cppAccessor,
41 const Path& p,
42 std::string& variantAccessor) const override
43 {
44 auto block_if_data = std::make_shared<CppBlock>();
45 std::string resolved_accessor = this->resolveMaybeAccessor(cppAccessor);
46 std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
47 variantAccessor = Generator::ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
48
49 block_if_data->addLine(
50 variantAccessor + " = " + this->ARON_WRITER_ACCESSOR + ".writePrimitive(" +
51 resolved_accessor + ", " + "armarx::aron::Path(" + this->ARON_PATH_ACCESSOR +
52 ", {" + simox::alg::join(p.getPath(), ", ") + "})); // of " + cppAccessor);
53
54 return this->resolveMaybeWriteBlock(block_if_data, cppAccessor);
55 }
56
58 getReadBlock(const std::string& cppAccessor,
59 const std::string& variantAccessor) const override
60 {
61 auto block_if_data = std::make_shared<CppBlock>();
62 std::string resolved_accessor = this->resolveMaybeAccessor(cppAccessor);
63 std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
64
65 block_if_data->addLine("" + this->ARON_READER_ACCESSOR + ".readPrimitive(" +
66 variantAccessor + ", " + resolved_accessor + "); // of " +
67 cppAccessor);
68 return this->resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor);
69 }
70 };
71} // namespace armarx::aron::codegenerator::cpp::generator::detail
The Path class.
Definition Path.h:36
std::vector< std::string > getPath() const
Definition Path.cpp:87
std::string resolveMaybeAccessor(const std::string &) const
CppBlockPtr resolveMaybeReadBlock(const CppBlockPtr &, const std::string &, const std::string &) const
static std::string EscapeAccessor(const std::string &)
Definition Generator.cpp:53
static const std::string ARON_READER_ACCESSOR
Definition Generator.h:164
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 resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const override
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const override
SpecializedGeneratorBase(const std::string &instantiatedCppTypename, const std::string &classCppTypename, const std::string &aronDataTypename, const std::string &aronTypeTypename, const typeT &t)
std::shared_ptr< CppBlock > CppBlockPtr
Definition CppBlock.h:37