IntEnum.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 // Header
25 #include "IntEnum.h"
26 
27 #include <SimoxUtility/meta/type_name.h>
28 
30 {
31  // constructors
33  detail::SpecializedGeneratorBase<type::IntEnum, IntEnum>(
34  e.getEnumName(),
35  e.getEnumName(),
36  simox::meta::get_type_name<data::dto::NDArray>(),
37  simox::meta::get_type_name<type::dto::IntEnum>(),
38  e)
39  {
40  }
41 
42  std::pair<std::vector<std::pair<std::string, std::string>>, bool>
43  IntEnum::getCtorInitializers(const std::string& name) const
44  {
45  return {{{name, type.getDefaultValueName()}}, true};
46  }
47 
49  IntEnum::getResetSoftBlock(const std::string& accessor) const
50  {
51  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
52  block_if_data->addLine(accessor + nextEl() + "resetSoft();");
53  return this->resolveMaybeResetSoftBlock(block_if_data, accessor);
54  }
55 
57  IntEnum::getResetHardBlock(const std::string& accessor) const
58  {
59  CppBlockPtr b = std::make_shared<CppBlock>();
61  {
62  b->addLine(accessor + " = {};");
63  }
64  else
65  {
66  b->addLine(accessor + nextEl() + "resetHard();");
67  }
68  return this->resolveMaybeResetHardBlock(b, accessor);
69  }
70 
72  IntEnum::getWriteTypeBlock(const std::string& typeAccessor,
73  const std::string& cppAccessor,
74  const Path& p,
75  std::string& variantAccessor) const
76  {
77  CppBlockPtr b = std::make_shared<CppBlock>();
78  std::string escaped_accessor = EscapeAccessor(cppAccessor);
79  variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
80 
81  b->addLine("auto " + variantAccessor + " = " + getInstantiatedCppTypename() +
82  "::writeType(" + ARON_WRITER_ACCESSOR + ", " + "{}, " +
83  conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" +
84  ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") +
85  "})); // of " + cppAccessor);
86  return b;
87  }
88 
90  IntEnum::getWriteBlock(const std::string& cppAccessor,
91  const Path& p,
92  std::string& variantAccessor) const
93  {
94  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
95  std::string escaped_accessor = EscapeAccessor(cppAccessor);
96  variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
97 
98  block_if_data->addLine(variantAccessor + " = " + cppAccessor + nextEl() + "write(" +
99  ARON_WRITER_ACCESSOR + ", " + "armarx::aron::Path(" +
100  ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") +
101  "})); // of " + cppAccessor);
102 
103  return resolveMaybeWriteBlock(block_if_data, cppAccessor);
104  }
105 
107  IntEnum::getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const
108  {
109  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
110  if (const auto reset = resolveMaybeGeneratorWithSetter(cppAccessor); !reset.empty())
111  {
112  block_if_data->addLine(reset);
113  }
114  block_if_data->addLine(cppAccessor + nextEl() + "read(" + ARON_READER_ACCESSOR + ", " +
115  variantAccessor + ");");
116  return resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor);
117  }
118 } // namespace armarx::aron::codegenerator::cpp::generator
IntEnum.h
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::IntEnum::getResetHardBlock
CppBlockPtr getResetHardBlock(const std::string &cppAccessor) const final
Definition: IntEnum.cpp:57
armarx::aron::codegenerator::cpp::generator::IntEnum::getReadBlock
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const final
Definition: IntEnum.cpp:107
armarx::aron::type::detail::SpecializedVariantBase::getMaybe
type::Maybe getMaybe() const override
get the maybe type
Definition: SpecializedVariant.h:92
armarx::aron::codegenerator::cpp::generator::IntEnum::getCtorInitializers
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &name) const final
Definition: IntEnum.cpp:43
armarx::aron::codegenerator::cpp::Generator::EscapeAccessor
static std::string EscapeAccessor(const std::string &)
Definition: Generator.cpp:53
armarx::aron::codegenerator::cpp::generator::IntEnum::getResetSoftBlock
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
Definition: IntEnum.cpp:49
armarx::aron::codegenerator::cpp::Generator::resolveMaybeGeneratorWithSetter
std::string resolveMaybeGeneratorWithSetter(const std::string &, const std::string &args="") const
Definition: Generator.cpp:602
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::type::IntEnum
The IntEnum class.
Definition: IntEnum.h:42
armarx::aron::codegenerator::cpp::Generator::ARON_PATH_ACCESSOR
static const std::string ARON_PATH_ACCESSOR
Definition: Generator.h:150
armarx::aron::codegenerator::cpp::generator::IntEnum::getWriteTypeBlock
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
Definition: IntEnum.cpp:72
armarx::aron::type::detail::EnumVariant::getDefaultValueName
std::string getDefaultValueName() const
Definition: EnumVariant.h:147
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::codegenerator::cpp::generator::NDArray
Definition: NDArray.h:33
armarx::aron::codegenerator::cpp::generator::IntEnum::IntEnum
IntEnum(const type::IntEnum &)
Definition: IntEnum.cpp:32
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::codegenerator::cpp::generator::detail::SpecializedGeneratorBase< type::IntEnum, IntEnum >::type
type::IntEnum type
Definition: SpecializedGenerator.h:52
armarx::aron::codegenerator::cpp::generator::IntEnum
Definition: IntEnum.h:37
armarx::aron::codegenerator::cpp::generator::IntEnum::getWriteBlock
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
Definition: IntEnum.cpp:90
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
Definition: AnyObject.cpp:29
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetHardBlock
CppBlockPtr resolveMaybeResetHardBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:655
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
armarx::aron::codegenerator::cpp::Generator::nextEl
std::string nextEl() const
Definition: Generator.cpp:613
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetSoftBlock
CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:677
armarx::aron::codegenerator::cpp::Generator::ARON_READER_ACCESSOR
static const std::string ARON_READER_ACCESSOR
Definition: Generator.h:151
armarx::aron::codegenerator::cpp::Generator::getInstantiatedCppTypename
std::string getInstantiatedCppTypename() const
Definition: Generator.cpp:110
simox
Definition: Impl.cpp:40
armarx::aron::codegenerator::cpp::Generator::resolveMaybeWriteBlock
CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:694
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