Int.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 "Int.h"
25 
26 #include <SimoxUtility/meta/type_name.h>
27 
29 {
30  /* constructors */
31  Int::Int(const type::Int& e) :
32  detail::PrimitiveGenerator<type::Int, Int>("int",
33  "int",
34  simox::meta::get_type_name<data::dto::AronInt>(),
35  simox::meta::get_type_name<type::dto::AronInt>(),
36  e)
37  {
38  }
39 
40  /* virtual implementations */
41  std::pair<std::vector<std::pair<std::string, std::string>>, bool>
42  Int::getCtorInitializers(const std::string& name) const
43  {
44  if (auto def = type.getDefaultValue(); def.has_value())
45  {
46  return {{{name, std::to_string(*def)}}, true};
47  }
48  return {{}, false};
49  }
50 
52  Int::getWriteTypeBlock(const std::string& typeAccessor,
53  const std::string& accessor,
54  const Path& p,
55  std::string& variantAccessor) const
56  {
57  CppBlockPtr b = std::make_shared<CppBlock>();
58  std::string escaped_accessor = EscapeAccessor(accessor);
59  variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
60 
61  std::string defaultValue = type.getDefaultValue().has_value()
63  : "std::nullopt";
64 
65  b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeInt(" +
66  defaultValue + ", " + conversion::Maybe2CppString.at(type.getMaybe()) + ", " +
67  "armarx::aron::Path(" + ARON_PATH_ACCESSOR + ", {" +
68  simox::alg::join(p.getPath(), ", ") + "})); // of " + typeAccessor);
69  return b;
70  }
71 
73  Int::getResetHardBlock(const std::string& cppAccessor) const
74  {
75  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
76  block_if_data->addLine(cppAccessor + " = 0;");
77  return resolveMaybeResetHardBlock(block_if_data, cppAccessor);
78  }
79 
81  Int::getResetSoftBlock(const std::string& cppAccessor) const
82  {
83  auto block_if_data = std::make_shared<CppBlock>();
84  block_if_data->addLine(cppAccessor + " = 0;");
85  return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor);
86  }
87 } // namespace armarx::aron::codegenerator::cpp::generator
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::Int::getCtorInitializers
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const final
Definition: Int.cpp:42
armarx::aron::codegenerator::cpp::generator::Int::Int
Int(const type::Int &e)
Definition: Int.cpp:31
armarx::aron::codegenerator::cpp::generator::Int::getWriteTypeBlock
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &p, std::string &variantAccessor) const final
Definition: Int.cpp:52
armarx::aron::type::detail::SpecializedVariantBase::getMaybe
type::Maybe getMaybe() const override
get the maybe type
Definition: SpecializedVariant.h:92
armarx::aron::codegenerator::cpp::generator::Int
Definition: Int.h:31
armarx::aron::codegenerator::cpp::generator::Int::getResetHardBlock
CppBlockPtr getResetHardBlock(const std::string &cppAccessor) const final
Definition: Int.cpp:73
armarx::aron::codegenerator::cpp::Generator::EscapeAccessor
static std::string EscapeAccessor(const std::string &)
Definition: Generator.cpp:53
armarx::aron::type::Int
The Int class.
Definition: Int.h:37
detail
Definition: OpenCVUtil.cpp:127
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
armarx::aron::codegenerator::cpp::Generator::ARON_PATH_ACCESSOR
static const std::string ARON_PATH_ACCESSOR
Definition: Generator.h:150
armarx::aron::codegenerator::cpp::generator::Int::getResetSoftBlock
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
Definition: Int.cpp:81
armarx::aron::Path
The Path class.
Definition: Path.h:36
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::codegenerator::cpp::generator::detail::SpecializedGeneratorBase< type::Int, Int >::type
type::Int type
Definition: SpecializedGenerator.h:52
armarx::aron::type::detail::PrimitiveVariant::getDefaultValue
std::optional< ValueType > getDefaultValue() const
Definition: PrimitiveVariant.h:74
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::codegenerator::cpp::generator
Definition: AnyObject.cpp:29
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetHardBlock
CppBlockPtr resolveMaybeResetHardBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:655
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetSoftBlock
CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:677
simox
Definition: Impl.cpp:40
armarx::aron::codegenerator::cpp::conversion::Maybe2CppString
const std::map< type::Maybe, std::string > Maybe2CppString
Definition: Generator.h:49
armarx::aron::Path::getPath
std::vector< std::string > getPath() const
Definition: Path.cpp:85
Int.h