Generator.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 <RobotAPI/interface/aron.h>
31 
37 
38 #include <memory>
39 #include <map>
40 #include <string>
41 #include <vector>
42 
43 
45 {
46 
47  namespace conversion
48  {
49  const std::map<type::Maybe, std::string> Maybe2CppString =
50  {
51  {type::Maybe::NONE, "::armarx::aron::type::Maybe::NONE"},
52  {type::Maybe::OPTIONAL, "::armarx::aron::type::Maybe::OPTIONAL"},
53  {type::Maybe::RAW_PTR, "::armarx::aron::type::Maybe::RAW_PTR"},
54  {type::Maybe::SHARED_PTR, "::armarx::aron::type::Maybe::SHARED_PTR"},
55  {type::Maybe::UNIQUE_PTR, "::armarx::aron::type::Maybe::UNIQUE_PTR"}
56  };
57  }
58 
60  typedef std::shared_ptr<GeneratorFactory> SerializerFactoryPtr;
61 
62  class Generator;
63  typedef std::shared_ptr<Generator> GeneratorPtr;
64 
65  class Generator
66  {
67  public:
69 
70  public:
71  // constructors
72  Generator() = delete;
73  Generator(const std::string& instantiatedCppTypename /* used for templates, e.g. vector<string> */, const std::string& classCppTypename /* the raw typename, e.g. vector<T> */, const std::string& aronDataTypename, const std::string& aronTypeTypename);
74  virtual ~Generator() = default;
75 
76  // public member methods
77  std::string getInstantiatedCppTypename() const;
78  std::string getFullInstantiatedCppTypename() const;
79  std::string getFullInstantiatedCppTypenameGenerator() const;
80 
81  std::string getClassCppTypename() const;
82  std::string getFullClassCppTypename() const;
83 
88 
89  // virtual override definitions
90  virtual std::vector<std::string> getRequiredIncludes() const;
91  virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const;
92 
93  CppCtorPtr toCtor(const std::string&) const;
94  virtual std::pair<std::vector<std::pair<std::string, std::string>>, bool> getCtorInitializers(const std::string&) const;
95  virtual CppBlockPtr getCtorBlock(const std::string&) const;
96 
97  CppCtorPtr toCopyCtor(const std::string&) const;
98  virtual std::pair<std::vector<std::pair<std::string, std::string>>, bool> getCopyCtorInitializers(const std::string&) const;
99  virtual CppBlockPtr getCopyCtorBlock(const std::string&) const;
100 
101  CppMethodPtr toDtor(const std::string&) const;
102  virtual CppBlockPtr getDtorBlock(const std::string&) const;
103 
105  virtual CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const;
106 
108  virtual CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const;
109 
111  virtual CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path&, std::string& variantAccessor) const = 0;
112 
113  CppMethodPtr toWriteMethod() const;
114  virtual CppBlockPtr getWriteBlock(const std::string& cppAccessor, const Path&, std::string& variantAccessor) const = 0;
115 
116  CppMethodPtr toReadMethod() const;
117  virtual CppBlockPtr getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const = 0;
118 
120  virtual CppBlockPtr getEqualsBlock(const std::string& cppAccessorThis, const std::string& cppAccessorOther) const;
121 
122  virtual const type::Variant& getType() const = 0;
123 
124  // static methods
125  static std::string EscapeAccessor(const std::string&);
126 
127  static std::string ExtractCppTypename(const type::Variant&);
128  static std::vector<std::string> ExtractCppTypenames(const std::vector<type::VariantPtr>&);
129 
130  static std::unique_ptr<Generator> FromAronType(const type::Variant&);
131 
132  protected:
133  std::string nextEl() const;
134  std::string toPointerAccessor(const std::string&) const;
135 
136  std::string resolveMaybeAccessor(const std::string&) const;
137  std::string resolveMaybeGenerator(const std::string& args = "") const;
138  std::string resolveMaybeGeneratorWithSetter(const std::string&, const std::string& args = "") const;
139 
140  CppBlockPtr resolveMaybeResetHardBlock(const CppBlockPtr&, const std::string&) const;
141  CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr&, const std::string&) const;
142  CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr&, const std::string&) const;
143  CppBlockPtr resolveMaybeReadBlock(const CppBlockPtr&, const std::string&, const std::string&) const;
144  CppBlockPtr resolveMaybeEqualsBlock(const CppBlockPtr&, const std::string&, const std::string&) const;
145 
146  protected:
147  static const std::string ARON_VARIABLE_PREFIX;
148 
149  static const std::string ARON_MAYBE_TYPE_ACCESSOR;
150  static const std::string ARON_PATH_ACCESSOR;
151  static const std::string ARON_READER_ACCESSOR;
152  static const std::string ARON_WRITER_ACCESSOR;
153  static const std::string ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR;
154  static const std::string ARON_VARIANT_RETURN_ACCESSOR;
155  static const std::string ARON_OTHER_ACCESSOR;
156 
157  private:
158  static const SerializerFactoryPtr FACTORY;
159 
160  std::string instantiatedCppTypename;
161  std::string classCppTypename;
162  std::string aronDataTypename;
163  std::string aronTypeTypename;
164  };
165 }
armarx::aron::codegenerator::cpp::Generator::getFullInstantiatedCppTypename
std::string getFullInstantiatedCppTypename() const
Definition: Generator.cpp:116
armarx::aron::codegenerator::cpp::Generator::toResetHardMethod
CppMethodPtr toResetHardMethod() const
Definition: Generator.cpp:264
armarx::aron::codegenerator::cpp::Generator::ARON_MAYBE_TYPE_ACCESSOR
static const std::string ARON_MAYBE_TYPE_ACCESSOR
Definition: Generator.h:149
armarx::aron::codegenerator::cpp
Definition: AnyObject.cpp:29
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::getFullClassCppTypename
std::string getFullClassCppTypename() const
Definition: Generator.cpp:168
CppMethod.h
armarx::aron::codegenerator::cpp::Generator::toCtor
CppCtorPtr toCtor(const std::string &) const
Definition: Generator.cpp:191
armarx::aron::codegenerator::cpp::Generator::getReadBlock
virtual CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const =0
armarx::aron::codegenerator::cpp::Generator::getCopyCtorInitializers
virtual std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCopyCtorInitializers(const std::string &) const
Definition: Generator.cpp:501
armarx::CppCtorPtr
std::shared_ptr< CppCtor > CppCtorPtr
Definition: CppCtor.h:31
armarx::aron::codegenerator::cpp::Generator::toSpecializedDataWriterMethod
CppMethodPtr toSpecializedDataWriterMethod(const WriterInfo &info) const
Definition: Generator.cpp:374
armarx::aron::codegenerator::cpp::Generator::FromAronType
static std::unique_ptr< Generator > FromAronType(const type::Variant &)
Definition: Generator.cpp:91
CppCtor.h
armarx::aron::codegenerator::cpp::Generator::EscapeAccessor
static std::string EscapeAccessor(const std::string &)
Definition: Generator.cpp:53
armarx::aron::codegenerator::cpp::Generator::resolveMaybeGeneratorWithSetter
std::string resolveMaybeGeneratorWithSetter(const std::string &, const std::string &args="") const
Definition: Generator.cpp:602
CppBlock.h
armarx::aron::codegenerator::cpp::SerializerFactoryPtr
std::shared_ptr< GeneratorFactory > SerializerFactoryPtr
Definition: Generator.h:59
armarx::aron::codegenerator::cpp::Generator::ARON_VARIABLE_PREFIX
static const std::string ARON_VARIABLE_PREFIX
Definition: Generator.h:147
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
armarx::aron::codegenerator::cpp::Generator::toResetSoftMethod
CppMethodPtr toResetSoftMethod() const
Definition: Generator.cpp:247
armarx::aron::codegenerator::cpp::Generator::Generator
Generator()=delete
ReaderInfo.h
armarx::aron::codegenerator::cpp::Generator::getEqualsBlock
virtual CppBlockPtr getEqualsBlock(const std::string &cppAccessorThis, const std::string &cppAccessorOther) const
Definition: Generator.cpp:547
armarx::aron::codegenerator::cpp::Generator::toDtor
CppMethodPtr toDtor(const std::string &) const
Definition: Generator.cpp:229
armarx::aron::codegenerator::cpp::Generator::ARON_PATH_ACCESSOR
static const std::string ARON_PATH_ACCESSOR
Definition: Generator.h:150
armarx::aron::codegenerator::ReaderInfo
Definition: ReaderInfo.h:32
armarx::aron::codegenerator::cpp::Generator::toWriteTypeMethod
CppMethodPtr toWriteTypeMethod() const
Definition: Generator.cpp:281
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::Variant
The Variant class.
Definition: Variant.h:59
armarx::aron::codegenerator::cpp::Generator::resolveMaybeGenerator
std::string resolveMaybeGenerator(const std::string &args="") const
Definition: Generator.cpp:579
armarx::aron::codegenerator::cpp::Generator::toSpecializedStaticDataReaderMethod
CppMethodPtr toSpecializedStaticDataReaderMethod(const StaticReaderInfo &info) const
Definition: Generator.cpp:416
Variant.h
CppClass.h
armarx::aron::codegenerator::cpp::Generator::ARON_OTHER_ACCESSOR
static const std::string ARON_OTHER_ACCESSOR
Definition: Generator.h:155
armarx::aron::codegenerator::cpp::Generator::getFullInstantiatedCppTypenameGenerator
std::string getFullInstantiatedCppTypenameGenerator() const
Definition: Generator.cpp:139
armarx::aron::codegenerator::cpp::GeneratorFactory
Definition: Factory.h:37
armarx::aron::codegenerator::cpp::Generator::getCtorBlock
virtual CppBlockPtr getCtorBlock(const std::string &) const
Definition: Generator.cpp:495
armarx::aron::codegenerator::cpp::Generator::~Generator
virtual ~Generator()=default
CppField.h
armarx::CppMethodPtr
std::shared_ptr< CppMethod > CppMethodPtr
Definition: CppMethod.h:32
armarx::aron::codegenerator::cpp::Generator::getRequiredIncludes
virtual std::vector< std::string > getRequiredIncludes() const
Definition: Generator.cpp:476
armarx::aron::codegenerator::cpp::Generator::toReadMethod
CppMethodPtr toReadMethod() const
Definition: Generator.cpp:339
armarx::aron::codegenerator::cpp::Generator::getPublicVariableDeclarations
virtual std::vector< CppFieldPtr > getPublicVariableDeclarations(const std::string &) const
Definition: Generator.cpp:482
WriterInfo.h
armarx::aron::codegenerator::cpp::Generator::getCopyCtorBlock
virtual CppBlockPtr getCopyCtorBlock(const std::string &) const
Definition: Generator.cpp:517
armarx::aron::codegenerator::cpp::Generator::toEqualsMethod
CppMethodPtr toEqualsMethod() const
Definition: Generator.cpp:456
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::toPointerAccessor
std::string toPointerAccessor(const std::string &) const
Definition: Generator.cpp:633
armarx::aron::codegenerator::cpp::GeneratorPtr
std::shared_ptr< Generator > GeneratorPtr
Definition: Generator.h:62
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetHardBlock
CppBlockPtr resolveMaybeResetHardBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:655
armarx::aron::codegenerator::cpp::Generator::resolveMaybeEqualsBlock
CppBlockPtr resolveMaybeEqualsBlock(const CppBlockPtr &, const std::string &, const std::string &) const
Definition: Generator.cpp:735
Exception.h
armarx::aron::codegenerator::StaticReaderInfo
Definition: ReaderInfo.h:44
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
armarx::aron::codegenerator::cpp::Generator::ExtractCppTypename
static std::string ExtractCppTypename(const type::Variant &)
Definition: Generator.cpp:72
armarx::aron::codegenerator::cpp::Generator::getDtorBlock
virtual CppBlockPtr getDtorBlock(const std::string &) const
Definition: Generator.cpp:523
armarx::aron::codegenerator::cpp::Generator::getType
virtual const type::Variant & getType() const =0
armarx::aron::codegenerator::cpp::Generator::getCtorInitializers
virtual std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const
Definition: Generator.cpp:489
armarx::aron::codegenerator::cpp::Generator::ExtractCppTypenames
static std::vector< std::string > ExtractCppTypenames(const std::vector< type::VariantPtr > &)
Definition: Generator.cpp:80
armarx::aron::codegenerator::cpp::Generator::toSpecializedDataReaderMethod
CppMethodPtr toSpecializedDataReaderMethod(const ReaderInfo &info) const
Definition: Generator.cpp:395
armarx::aron::codegenerator::cpp::Generator::toSpecializedTypeWriterMethod
CppMethodPtr toSpecializedTypeWriterMethod(const WriterInfo &info) const
Definition: Generator.cpp:437
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::getWriteBlock
virtual CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &, std::string &variantAccessor) const =0
armarx::aron::codegenerator::cpp::Generator::toWriteMethod
CppMethodPtr toWriteMethod() const
Definition: Generator.cpp:308
armarx::aron::codegenerator::cpp::Generator::getResetHardBlock
virtual CppBlockPtr getResetHardBlock(const std::string &cppAccessor) const
Definition: Generator.cpp:529
armarx::aron::codegenerator::cpp::Generator
Definition: Generator.h:65
armarx::aron::codegenerator::cpp::Generator::getClassCppTypename
std::string getClassCppTypename() const
Definition: Generator.cpp:162
armarx::aron::codegenerator::cpp::Generator::getInstantiatedCppTypename
std::string getInstantiatedCppTypename() const
Definition: Generator.cpp:110
armarx::aron::codegenerator::cpp::Generator::toCopyCtor
CppCtorPtr toCopyCtor(const std::string &) const
Definition: Generator.cpp:209
armarx::aron::codegenerator::cpp::Generator::getResetSoftBlock
virtual CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const
Definition: Generator.cpp:538
armarx::aron::codegenerator::cpp::Generator::resolveMaybeWriteBlock
CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:694
armarx::aron::codegenerator::WriterInfo
Definition: WriterInfo.h:32
armarx::aron::codegenerator::cpp::conversion::Maybe2CppString
const std::map< type::Maybe, std::string > Maybe2CppString
Definition: Generator.h:49
armarx::aron::codegenerator::cpp::Generator::ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR
static const std::string ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR
Definition: Generator.h:153
armarx::aron::codegenerator::cpp::Generator::getWriteTypeBlock
virtual CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &, std::string &variantAccessor) const =0
armarx::aron::codegenerator::cpp::Generator::PointerType
GeneratorPtr PointerType
Definition: Generator.h:68