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 "SpecializedGenerator.h"
27 
28 #include <string>
29 
30 
32 {
33  template<typename typeT, typename DerivedT>
35  public SpecializedGeneratorBase<typeT, DerivedT>
36  {
37  public:
39  virtual ~PrimitiveGenerator() = default;
40 
41  CppBlockPtr getWriteBlock(const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const override
42  {
43  auto block_if_data = std::make_shared<CppBlock>();
44  std::string resolved_accessor = this->resolveMaybeAccessor(cppAccessor);
45  std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
46  variantAccessor = Generator::ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
47 
48  block_if_data->addLine(variantAccessor + " = " + this->ARON_WRITER_ACCESSOR + ".writePrimitive(" + resolved_accessor + ", "+
49  "armarx::aron::Path("+this->ARON_PATH_ACCESSOR+", {" + simox::alg::join(p.getPath(), ", ") + "})); // of " + cppAccessor);
50 
51  return this->resolveMaybeWriteBlock(block_if_data, cppAccessor);
52  }
53 
54  CppBlockPtr getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const override
55  {
56  auto block_if_data = std::make_shared<CppBlock>();
57  std::string resolved_accessor = this->resolveMaybeAccessor(cppAccessor);
58  std::string escaped_accessor = this->EscapeAccessor(cppAccessor);
59 
60  block_if_data->addLine("" + this->ARON_READER_ACCESSOR + ".readPrimitive("+variantAccessor+", " + resolved_accessor + "); // of " + cppAccessor);
61  return this->resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor);
62  }
63  };
64 }
armarx::aron::codegenerator::cpp::generator::detail::PrimitiveGenerator::~PrimitiveGenerator
virtual ~PrimitiveGenerator()=default
armarx::aron::codegenerator::cpp::Generator::ARON_VARIANT_RETURN_ACCESSOR
static const std::string ARON_VARIANT_RETURN_ACCESSOR
Definition: Generator.h:154
armarx::aron::codegenerator::cpp::generator::detail::PrimitiveGenerator
Definition: PrimitiveGenerator.h:34
armarx::aron::codegenerator::cpp::Generator::EscapeAccessor
static std::string EscapeAccessor(const std::string &)
Definition: Generator.cpp:53
armarx::aron::codegenerator::cpp::Generator::resolveMaybeAccessor
std::string resolveMaybeAccessor(const std::string &) const
Definition: Generator.cpp:563
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:35
armarx::aron::codegenerator::cpp::Generator::ARON_WRITER_ACCESSOR
static const std::string ARON_WRITER_ACCESSOR
Definition: Generator.h:152
SpecializedGenerator.h
armarx::aron::codegenerator::cpp::generator::detail::PrimitiveGenerator::getReadBlock
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const override
Definition: PrimitiveGenerator.h:54
armarx::aron::codegenerator::cpp::generator::detail
Definition: AnyGenerator.h:31
armarx::aron::codegenerator::cpp::Generator::ARON_PATH_ACCESSOR
static const std::string ARON_PATH_ACCESSOR
Definition: Generator.h:150
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::codegenerator::cpp::generator::detail::SpecializedGeneratorBase
Definition: SpecializedGenerator.h:35
armarx::aron::codegenerator::cpp::Generator::resolveMaybeReadBlock
CppBlockPtr resolveMaybeReadBlock(const CppBlockPtr &, const std::string &, const std::string &) const
Definition: Generator.cpp:711
armarx::aron::codegenerator::cpp::generator::detail::PrimitiveGenerator::getWriteBlock
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const override
Definition: PrimitiveGenerator.h:41
armarx::aron::codegenerator::cpp::Generator::ARON_READER_ACCESSOR
static const std::string ARON_READER_ACCESSOR
Definition: Generator.h:151
armarx::aron::codegenerator::cpp::Generator::resolveMaybeWriteBlock
CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:694
armarx::aron::Path::getPath
std::vector< std::string > getPath() const
Definition: Path.cpp:85