27#include <SimoxUtility/algorithm/vector.hpp>
28#include <SimoxUtility/meta/type_name.h>
35 e.getObjectNameWithTemplateInstantiations(),
36 e.getObjectNameWithTemplates(),
41 if (
type.getMaybe() != type::Maybe::NONE)
43 throw error::ValueNotValidException(
45 "Somehow the maybe flag of a top level object declaration is set. This is not "
47 std::to_string((int)type.getMaybe()) +
" aka " +
48 type::defaultconversion::string::Maybe2String.at(type.getMaybe()),
53 std::pair<std::vector<std::pair<std::string, std::string>>,
bool>
56 std::vector<std::pair<std::string, std::string>> ret;
58 for (
const auto& [key, child] :
type.getDirectMemberTypes())
61 auto p = child_s->getCtorInitializers(key);
62 for (
const auto& el : p.first)
66 any = any or p.second;
71 std::vector<std::string>
74 std::vector<std::string> ret;
75 for (
const auto& [key, child] :
type.getDirectMemberTypes())
79 ret = simox::alg::appended(ret, child_s->getRequiredIncludes());
84 std::vector<CppFieldPtr>
87 std::vector<CppFieldPtr> fields;
88 for (
const auto& [key, member] :
type.getDirectMemberTypes())
91 std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key);
92 fields.insert(fields.end(), member_fields.begin(), member_fields.end());
100 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
101 if (
type.getExtends() !=
nullptr)
104 block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() +
"::resetSoft();");
107 for (
const auto& [key, child] :
type.getDirectMemberTypes())
111 block_if_data->appendBlock(b2);
113 return block_if_data;
119 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
120 if (
type.getExtends() !=
nullptr)
123 block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() +
"::resetHard();");
126 for (
const auto& [key, child] :
type.getDirectMemberTypes())
130 block_if_data->appendBlock(b2);
132 return block_if_data;
145 b->addLine(
"std::map<std::string, _Aron_T> " + OBJECT_MEMBERS_ACCESSOR +
";");
147 if (
type.getExtends() !=
nullptr)
151 b->addLine(
"auto " + OBJECT_EXTENDS_ACCESSOR +
" = " +
152 extends_s->getFullInstantiatedCppTypename() +
"::writeType(" +
154 simox::alg::join(
type.getExtends()->getTemplateInstantiations(),
", ") +
155 "}, " +
"::armarx::aron::type::Maybe::NONE);");
159 b->addLine(
"auto " + OBJECT_EXTENDS_ACCESSOR +
" = std::nullopt;");
163 for (
const auto& [key, child] :
type.getDirectMemberTypes())
166 std::string child_return_variant;
169 child_s->getFullInstantiatedCppTypename(), key, nextPath, child_return_variant);
170 b->appendBlock(child_b);
171 b->addLine(OBJECT_MEMBERS_ACCESSOR +
".emplace(\"" + key +
"\", " +
172 child_return_variant +
");");
174 std::vector<std::string> templatesQuoted;
175 std::vector<std::string> templateIntantiationsQuoted;
176 for (
const auto& t :
type.getTemplates())
178 templatesQuoted.push_back(
"\"" + t +
"\"");
180 for (
const auto& t :
type.getTemplateInstantiations())
182 templateIntantiationsQuoted.push_back(
"\"" + t +
"\"");
186 "\", " +
"{" + simox::alg::join(templatesQuoted,
", ") +
"}, " +
202 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
204 block_if_data->addLine(
"std::map<std::string, _Aron_T> " + OBJECT_MEMBERS_ACCESSOR +
";");
206 block_if_data->addLine(
"std::optional<_Aron_T> " + OBJECT_EXTENDS_ACCESSOR +
";");
207 if (
type.getExtends() !=
nullptr)
210 block_if_data->addLine(
"// write base class of " +
212 block_if_data->addLine(OBJECT_EXTENDS_ACCESSOR +
" = " +
213 extends_s->getFullInstantiatedCppTypename() +
"::write(" +
218 for (
const auto& [key, child] :
type.getDirectMemberTypes())
221 std::string child_return_variant;
224 CppBlockPtr child_b = child_s->getWriteBlock(key, nextPath, child_return_variant);
227 block_if_data->appendBlock(child_b);
228 block_if_data->addLine(OBJECT_MEMBERS_ACCESSOR +
".emplace(\"" + key +
"\", " +
229 child_return_variant +
");");
233 OBJECT_MEMBERS_ACCESSOR +
", " + OBJECT_EXTENDS_ACCESSOR +
", " +
236 return block_if_data;
245 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
246 block_if_data->addLine(
"std::map<std::string, _Aron_TNonConst> " + OBJECT_MEMBERS_ACCESSOR +
249 if (
type.getExtends() !=
nullptr)
252 block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() +
"::read(" +
257 OBJECT_MEMBERS_ACCESSOR +
"); // of top level object " +
260 for (
const auto& [key, child] :
type.getDirectMemberTypes())
263 std::string child_accessor = OBJECT_MEMBERS_ACCESSOR +
"_" + key +
"_iterator";
264 block_if_data->addLine(
"auto " + child_accessor +
" = " + OBJECT_MEMBERS_ACCESSOR +
265 ".find(\"" + key +
"\");");
266 block_if_data->addLine(
267 "ARMARX_CHECK_AND_THROW(" + child_accessor +
" != " + OBJECT_MEMBERS_ACCESSOR +
268 ".end(), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing "
271 block_if_data->appendBlock(child_s->getReadBlock(key, child_accessor +
"->second"));
273 return block_if_data;
278 const std::string& otherInstanceAccessor)
const
280 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
281 if (
type.getExtends() !=
nullptr)
284 block_if_data->addLine(
"if (not (" + extends_s->getFullInstantiatedCppTypename() +
285 "::operator== (" + otherInstanceAccessor +
")))");
286 block_if_data->addLineAsBlock(
"return false;");
288 for (
const auto& [key, child] :
type.getDirectMemberTypes())
291 CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor +
"." + key);
292 block_if_data->appendBlock(b2);
294 return block_if_data;
297 std::pair<std::vector<std::pair<std::string, std::string>>,
bool>
300 std::vector<std::pair<std::string, std::string>> ret;
302 if (
type.getExtends() !=
nullptr)
308 bool anyComplex =
false;
309 for (
const auto& [key, child] :
type.getDirectMemberTypes())
312 auto initList = child_s->getCopyCtorInitializers(key);
313 simox::alg::append(ret, initList.first);
314 anyComplex = anyComplex || initList.second;
316 return {ret, anyComplex};
Path withElement(const std::string &, bool escape=false) const
static const std::string ARON_OTHER_ACCESSOR
static const std::string ARON_READER_ACCESSOR
std::string getInstantiatedCppTypename() const
static const std::string ARON_PATH_ACCESSOR
std::string getFullClassCppTypename() const
std::string getFullInstantiatedCppTypename() const
static const std::string ARON_VARIABLE_PREFIX
static const std::string ARON_WRITER_ACCESSOR
static std::unique_ptr< Generator > FromAronType(const type::Variant &)
static const std::string ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR
static const std::string ARON_MAYBE_TYPE_ACCESSOR
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCopyCtorInitializers(const std::string &) const final
std::vector< std::string > getRequiredIncludes() const final
CppBlockPtr getEqualsBlock(const std::string &, const std::string &) const final
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &, std::string &) const final
CppBlockPtr getResetHardBlock(const std::string &cppAccessor) const final
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &) const final
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
ObjectClass(const type::Object &)
std::vector< CppFieldPtr > getPublicVariableDeclarations(const std::string &) const final
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const final
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
SpecializedGeneratorBase(const std::string &instantiatedCppTypename, const std::string &classCppTypename, const std::string &aronDataTypename, const std::string &aronTypeTypename, const type::Object &t)
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< CppBlock > CppBlockPtr