Skip to content
Snippets Groups Projects
Commit 7bfdb41c authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

Merge remote-tracking branch 'origin/master' into fabianpk

parents b010670c 8eb1e505
No related branches found
No related tags found
1 merge request!337Merge fabianpk dev branch
Showing
with 616 additions and 166 deletions
...@@ -177,7 +177,39 @@ int main(int argc, char* argv[]) ...@@ -177,7 +177,39 @@ int main(int argc, char* argv[])
} }
} }
auto w = CppWriterPtr(new CppWriter()); std::time_t current_time = std::time(0);
std::tm* now = std::localtime(&current_time);
std::string current_year = std::to_string(now->tm_year + 1900);
std::string fileDoc = std::string("* This file is part of ArmarX. \n") +
"* \n" +
"* Copyright (C) 2012-" + current_year + ", High Performance Humanoid Technologies (H2T), \n" +
"* Karlsruhe Institute of Technology (KIT), all rights reserved. \n" +
"* \n" +
"* ArmarX is free software; you can redistribute it and/or modify \n" +
"* it under the terms of the GNU General Public License version 2 as \n" +
"* published by the Free Software Foundation. \n" +
"* \n" +
"* ArmarX is distributed in the hope that it will be useful, but \n" +
"* WITHOUT ANY WARRANTY; without even the implied warranty of \n" +
"* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" +
"* GNU General Public License for more details. \n" +
"* \n" +
"* You should have received a copy of the GNU General Public License \n" +
"* along with this program. If not, see <http://www.gnu.org/licenses/>. \n" +
"* \n" +
"* @copyright http://www.gnu.org/licenses/gpl-2.0.txt \n" +
"* GNU General Public License \n" +
"* *********************************************************************** \n" +
"* WARNING: This file is autogenerated. \n" +
"* Original file: " + filename + " \n" +
"* Please do not edit since your changes may be overwritten on the next generation \n" +
"* If you have any questions please contact: Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) \n" +
"* ***********************************************************************";
auto w = CppWriterPtr(new CppWriter(true, fileDoc));
w->header.line();
w->header.line();
// Generate enums at top of generated header file // Generate enums at top of generated header file
std::vector<MetaEnumPtr> enums = writer.getTypeEnums(); std::vector<MetaEnumPtr> enums = writer.getTypeEnums();
...@@ -186,7 +218,12 @@ int main(int argc, char* argv[]) ...@@ -186,7 +218,12 @@ int main(int argc, char* argv[])
std::cout << "Now exporting enums..." << std::endl; std::cout << "Now exporting enums..." << std::endl;
} }
w->body.line("/*************************************************************************");
w->body.line(" * ALL GENERATED ENUMS ***************************************************");
w->body.line(" ************************************************************************/");
MetaEnum::Write(enums, w); MetaEnum::Write(enums, w);
w->body.line();
w->body.line();
std::string enum_file_generation_content = w->getString(); std::string enum_file_generation_content = w->getString();
...@@ -208,7 +245,12 @@ int main(int argc, char* argv[]) ...@@ -208,7 +245,12 @@ int main(int argc, char* argv[])
std::cout << "Now exporting classes..." << std::endl; std::cout << "Now exporting classes..." << std::endl;
} }
w->body.line("/* ************************************************************************");
w->body.line(" * ALL GENERATED CLASSES *************************************************");
w->body.line(" * ***********************************************************************/");
CppClass::Write(classes, w); CppClass::Write(classes, w);
w->body.line();
w->body.line();
std::string class_file_generation_content = simox::alg::remove_prefix(w->getString(), enum_file_generation_content); std::string class_file_generation_content = simox::alg::remove_prefix(w->getString(), enum_file_generation_content);
...@@ -223,39 +265,7 @@ int main(int argc, char* argv[]) ...@@ -223,39 +265,7 @@ int main(int argc, char* argv[])
exit(1); exit(1);
} }
std::time_t current_time = std::time(0); std::string new_file_full_content = w->getString();
std::tm* now = std::localtime(&current_time);
std::string current_year = std::to_string(now->tm_year + 1900);
std::string new_file_header = "\
/* \n\
* This file is part of ArmarX. \n\
* \n\
* Copyright (C) 2012-" + current_year + ", High Performance Humanoid Technologies (H2T), \n\
* Karlsruhe Institute of Technology (KIT), all rights reserved. \n\
* \n\
* ArmarX is free software; you can redistribute it and/or modify \n\
* it under the terms of the GNU General Public License version 2 as \n\
* published by the Free Software Foundation. \n\
* \n\
* ArmarX is distributed in the hope that it will be useful, but \n\
* WITHOUT ANY WARRANTY; without even the implied warranty of \n\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n\
* GNU General Public License for more details. \n\
* \n\
* You should have received a copy of the GNU General Public License \n\
* along with this program. If not, see <http://www.gnu.org/licenses/>. \n\
* \n\
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt \n\
* GNU General Public License \n\
************************************************************************* \n\
* WARNING: This file is autogenerated. \n\
* Original file: " + filename + " \n\
* Please do not edit since your changes may be overwritten on the next generation \n\
* If you have any questions please contact: Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) \n\
************************************************************************* \n\
*/\n\n\n";
std::string new_file_full_content = new_file_header + w->getString();
std::string new_name_with_extension = input_file.filename().replace_extension("").string(); std::string new_name_with_extension = input_file.filename().replace_extension("").string();
new_name_with_extension += ".aron.generated.h"; new_name_with_extension += ".aron.generated.h";
......
...@@ -76,10 +76,18 @@ namespace armarx::aron::codegenerator ...@@ -76,10 +76,18 @@ namespace armarx::aron::codegenerator
std::vector<MetaEnumPtr> typeEnums; std::vector<MetaEnumPtr> typeEnums;
std::string producerName; std::string producerName;
std::vector<codegenerator::WriterInfo> dataWriters; std::vector<codegenerator::WriterInfo> dictDataWriters;
std::vector<codegenerator::ReaderInfo> dataReaders; std::vector<codegenerator::WriterInfo> intEnumDataWriters;
std::vector<codegenerator::StaticReaderInfo> staticDataReaders;
std::vector<codegenerator::WriterInfo> initialTypeWriters; std::vector<codegenerator::ReaderInfo> dictDataReaders;
std::vector<codegenerator::ReaderInfo> intEnumDataReaders;
std::vector<codegenerator::StaticReaderInfo> staticDictDataReaders;
std::vector<codegenerator::StaticReaderInfo> staticIntEnumDataReaders;
std::vector<codegenerator::WriterInfo> initialDictTypeWriters;
std::vector<codegenerator::WriterInfo> initialIntEnumTypeWriters;
std::vector<std::string> additionalIncludes; std::vector<std::string> additionalIncludes;
}; };
} }
...@@ -317,7 +317,7 @@ namespace armarx::aron::codegenerator::cpp ...@@ -317,7 +317,7 @@ namespace armarx::aron::codegenerator::cpp
doc << "@brief " << info.methodName << "() - This method returns a new data from the member data types using a writer implementation. \n"; doc << "@brief " << info.methodName << "() - This method returns a new data from the member data types using a writer implementation. \n";
doc << "@return - the result of the writer implementation"; doc << "@return - the result of the writer implementation";
CppMethodPtr m = CppMethodPtr(new CppMethod(info.returnType + " " + info.methodName + "() const", doc.str())); CppMethodPtr m = CppMethodPtr(new CppMethod(info.returnType + " " + info.methodName + "() const" + (info.override ? " override" : ""), doc.str()));
m->addLine(info.writerClassType + " writer;"); m->addLine(info.writerClassType + " writer;");
m->addLine("return " + info.enforceConversion + "(this->write(writer))" + info.enforceMemberAccess + ";"); m->addLine("return " + info.enforceConversion + "(this->write(writer))" + info.enforceMemberAccess + ";");
...@@ -331,7 +331,7 @@ namespace armarx::aron::codegenerator::cpp ...@@ -331,7 +331,7 @@ namespace armarx::aron::codegenerator::cpp
doc << "@brief " << info.methodName << " - This method sets the struct members to new values given in a reader implementation. \n"; doc << "@brief " << info.methodName << " - This method sets the struct members to new values given in a reader implementation. \n";
doc << "@return - nothing"; doc << "@return - nothing";
CppMethodPtr m = CppMethodPtr(new CppMethod("void " + info.methodName + "(const " + info.argumentType + "& input)", doc.str())); CppMethodPtr m = CppMethodPtr(new CppMethod("void " + info.methodName + "(const " + info.argumentType + "& input)" + (info.override ? " override" : ""), doc.str()));
m->addLine(info.readerClassType + " reader;"); m->addLine(info.readerClassType + " reader;");
m->addLine("this->read(reader, " + info.enforceConversion + "(input)" + info.enforceMemberAccess + ");"); m->addLine("this->read(reader, " + info.enforceConversion + "(input)" + info.enforceMemberAccess + ");");
...@@ -395,9 +395,9 @@ namespace armarx::aron::codegenerator::cpp ...@@ -395,9 +395,9 @@ namespace armarx::aron::codegenerator::cpp
return {field}; return {field};
} }
std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCtorInitializers(const std::string&) const std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCtorInitializers(const std::string& name) const
{ {
return {{}, false}; return {{{name, "{}"}}, false};
} }
CppBlockPtr Generator::getCtorBlock(const std::string&) const CppBlockPtr Generator::getCtorBlock(const std::string&) const
...@@ -408,7 +408,7 @@ namespace armarx::aron::codegenerator::cpp ...@@ -408,7 +408,7 @@ namespace armarx::aron::codegenerator::cpp
std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCopyCtorInitializers(const std::string& name) const std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCopyCtorInitializers(const std::string& name) const
{ {
const auto& t = getType(); const auto& t = getType();
if (t.getMaybe() == type::Maybe::UNIQUE_PTR || t.getMaybe() == type::Maybe::RAW_PTR) if (t.getMaybe() == type::Maybe::UNIQUE_PTR) // unique ptrs cant be copied
{ {
return {{{name, ARON_OTHER_ACCESSOR + "." + name + " ? " + resolveMaybeGenerator("*" + ARON_OTHER_ACCESSOR + "." + name) + " : nullptr"}}, true}; return {{{name, ARON_OTHER_ACCESSOR + "." + name + " ? " + resolveMaybeGenerator("*" + ARON_OTHER_ACCESSOR + "." + name) + " : nullptr"}}, true};
} }
......
...@@ -55,6 +55,8 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -55,6 +55,8 @@ namespace armarx::aron::codegenerator::cpp::generator
// add legacy typedef // add legacy typedef
fields.push_back(std::make_shared<CppField>("using", std::string(IMPL_ENUM), simox::alg::to_lower(className) + "_details::Enum", "Legacy typedef of enum")); fields.push_back(std::make_shared<CppField>("using", std::string(IMPL_ENUM), simox::alg::to_lower(className) + "_details::Enum", "Legacy typedef of enum"));
ARMARX_CHECK(type.getAcceptedValueMap().size() > 0);
enum_to_name << "{" << std::endl; enum_to_name << "{" << std::endl;
name_to_enum << "{" << std::endl; name_to_enum << "{" << std::endl;
enum_to_value << "{" << std::endl; enum_to_value << "{" << std::endl;
...@@ -81,7 +83,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -81,7 +83,7 @@ namespace armarx::aron::codegenerator::cpp::generator
fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value")); fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value"));
fields.push_back(std::make_shared<CppField>("static inline const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum")); fields.push_back(std::make_shared<CppField>("static inline const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum"));
fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", "", "The current value of the enum object")); fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", type.getAcceptedValueNames()[0], "The current value of the enum object"));
return fields; return fields;
} }
...@@ -162,11 +164,6 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -162,11 +164,6 @@ namespace armarx::aron::codegenerator::cpp::generator
return c; return c;
}*/ }*/
std::pair<std::vector<std::pair<std::string, std::string>>, bool> IntEnumClass::getCopyCtorInitializers(const std::string&) const
{
return {{{"value", ARON_OTHER_ACCESSOR + ".value"}}, false};
}
CppCtorPtr IntEnumClass::toEnumCtor(const std::string& name) const CppCtorPtr IntEnumClass::toEnumCtor(const std::string& name) const
{ {
CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + std::string(IMPL_ENUM) + " e)"); CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + std::string(IMPL_ENUM) + " e)");
......
...@@ -43,8 +43,6 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -43,8 +43,6 @@ namespace armarx::aron::codegenerator::cpp::generator
// virtual implementations // virtual implementations
std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const final; std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const final;
std::pair<std::vector<std::pair<std::string, std::string>>, bool> getCopyCtorInitializers(const std::string&) const final;
CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final;
CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final;
CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final; CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final;
......
...@@ -47,7 +47,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -47,7 +47,7 @@ namespace armarx::aron::codegenerator::cpp::generator
std::vector<std::string> ObjectClass::getRequiredIncludes() const std::vector<std::string> ObjectClass::getRequiredIncludes() const
{ {
std::vector<std::string> ret; std::vector<std::string> ret;
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
(void) key; (void) key;
auto child_s = FromAronType(*child); auto child_s = FromAronType(*child);
...@@ -59,7 +59,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -59,7 +59,7 @@ namespace armarx::aron::codegenerator::cpp::generator
std::vector<CppFieldPtr> ObjectClass::getPublicVariableDeclarations(const std::string&) const std::vector<CppFieldPtr> ObjectClass::getPublicVariableDeclarations(const std::string&) const
{ {
std::vector<CppFieldPtr> fields; std::vector<CppFieldPtr> fields;
for (const auto& [key, member] : type.getMemberTypes()) for (const auto& [key, member] : type.getDirectMemberTypes())
{ {
auto member_s = FromAronType(*member); auto member_s = FromAronType(*member);
std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key); std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key);
...@@ -77,7 +77,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -77,7 +77,7 @@ namespace armarx::aron::codegenerator::cpp::generator
block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetSoft();"); block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetSoft();");
} }
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
auto child_s = FromAronType(*child); auto child_s = FromAronType(*child);
CppBlockPtr b2 = child_s->getResetSoftBlock(key); CppBlockPtr b2 = child_s->getResetSoftBlock(key);
...@@ -95,7 +95,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -95,7 +95,7 @@ namespace armarx::aron::codegenerator::cpp::generator
block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetHard();"); block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetHard();");
} }
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
const auto child_s = FromAronType(*child); const auto child_s = FromAronType(*child);
CppBlockPtr b2 = child_s->getResetHardBlock(key); CppBlockPtr b2 = child_s->getResetHardBlock(key);
...@@ -127,7 +127,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -127,7 +127,7 @@ namespace armarx::aron::codegenerator::cpp::generator
} }
b->addLine("// members of " + this->getFullInstantiatedCppTypename()); b->addLine("// members of " + this->getFullInstantiatedCppTypename());
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
const auto child_s = FromAronType(*child); const auto child_s = FromAronType(*child);
std::string child_return_variant; std::string child_return_variant;
...@@ -176,7 +176,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -176,7 +176,7 @@ namespace armarx::aron::codegenerator::cpp::generator
} }
block_if_data->addLine("// members of " + this->getFullInstantiatedCppTypename()); block_if_data->addLine("// members of " + this->getFullInstantiatedCppTypename());
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
const auto child_s = FromAronType(*child); const auto child_s = FromAronType(*child);
std::string child_return_variant; std::string child_return_variant;
...@@ -210,7 +210,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -210,7 +210,7 @@ namespace armarx::aron::codegenerator::cpp::generator
block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readDict("+variantAccessor+", "+OBJECT_MEMBERS_ACCESSOR+"); // of top level object " + getInstantiatedCppTypename()); block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readDict("+variantAccessor+", "+OBJECT_MEMBERS_ACCESSOR+"); // of top level object " + getInstantiatedCppTypename());
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
const auto child_s = FromAronType(*child); const auto child_s = FromAronType(*child);
std::string child_accessor = OBJECT_MEMBERS_ACCESSOR + "_" + key + "_iterator"; std::string child_accessor = OBJECT_MEMBERS_ACCESSOR + "_" + key + "_iterator";
...@@ -230,7 +230,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -230,7 +230,7 @@ namespace armarx::aron::codegenerator::cpp::generator
block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + "::operator== (" + otherInstanceAccessor + ")))"); block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + "::operator== (" + otherInstanceAccessor + ")))");
block_if_data->addLineAsBlock("return false;"); block_if_data->addLineAsBlock("return false;");
} }
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
auto child_s = FromAronType(*child); auto child_s = FromAronType(*child);
CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key); CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key);
...@@ -250,7 +250,7 @@ namespace armarx::aron::codegenerator::cpp::generator ...@@ -250,7 +250,7 @@ namespace armarx::aron::codegenerator::cpp::generator
} }
bool anyComplex = false; bool anyComplex = false;
for (const auto& [key, child] : type.getMemberTypes()) for (const auto& [key, child] : type.getDirectMemberTypes())
{ {
auto child_s = FromAronType(*child); auto child_s = FromAronType(*child);
auto initList = child_s->getCopyCtorInitializers(key); auto initList = child_s->getCopyCtorInitializers(key);
......
...@@ -37,6 +37,7 @@ namespace armarx::aron::codegenerator ...@@ -37,6 +37,7 @@ namespace armarx::aron::codegenerator
std::string include; std::string include;
std::string enforceConversion = ""; std::string enforceConversion = "";
std::string enforceMemberAccess = ""; std::string enforceMemberAccess = "";
bool override = false;
}; };
......
...@@ -37,5 +37,6 @@ namespace armarx::aron::codegenerator ...@@ -37,5 +37,6 @@ namespace armarx::aron::codegenerator
std::string include; std::string include;
std::string enforceConversion = ""; std::string enforceConversion = "";
std::string enforceMemberAccess = ""; std::string enforceMemberAccess = "";
bool override = false;
}; };
} }
...@@ -106,6 +106,24 @@ armarx_add_test( ...@@ -106,6 +106,24 @@ armarx_add_test(
${Simox_INCLUDE_DIR} ${Simox_INCLUDE_DIR}
) )
######################
# ARON CONVERSION TEST
######################
armarx_add_test(
TEST_NAME
aronConversionTest
TEST_FILE
aronConversionTest.cpp
LIBS
SimoxUtility # Simox::SimoxUtility
ArmarXCore
RobotAPI::aron
ARON_FILES
aron/HumanPoseTest.xml
INCLUDE_DIRECTORIES
${Simox_INCLUDE_DIR}
)
###################### ######################
# ARON JSON EXPORT TEST # ARON JSON EXPORT TEST
###################### ######################
......
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::ArmarXObjects::aron
* @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
* @date 2019
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron
#define ARMARX_BOOST_TEST
// STD/STL
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <numeric>
// Test
#include <RobotAPI/Test.h>
// Aron
#include <RobotAPI/libraries/aron/core/data/variant/All.h>
#include <RobotAPI/libraries/aron/codegeneration/test/aron/HumanPoseTest.aron.generated.h>
using namespace armarx;
using namespace aron;
namespace armarx
{
class HumanPoseBO
{
public:
std::vector<float> jointValues;
bool reached;
HumanPoseBO() = default;
void fromAron(const HumanPoseTest& aron)
{
jointValues = aron.jointValues;
reached = aron.reached;
}
HumanPoseTest toAron()
{
HumanPoseTest aron;
aron.jointValues = jointValues;
aron.reached = reached;
return aron;
}
};
void fromAron(const HumanPoseTest& aron, HumanPoseBO& bo)
{
bo.jointValues = aron.jointValues;
bo.reached = aron.reached;
}
void toAron(HumanPoseTest& aron, const HumanPoseBO& bo)
{
aron.jointValues = bo.jointValues;
aron.reached = bo.reached;
}
BOOST_AUTO_TEST_CASE(AronAssignmentTest)
{
armarx::HumanPoseTest aron;
aron.jointValues = {1,2,3,4};
aron.reached = true;
HumanPoseBO bo;
aron.to(bo);
BOOST_CHECK((aron.jointValues == bo.jointValues));
HumanPoseBO bo2;
aron.to(bo, &fromAron);
BOOST_CHECK((aron.jointValues == bo2.jointValues));
}
}
...@@ -107,6 +107,8 @@ set(LIB_HEADERS ...@@ -107,6 +107,8 @@ set(LIB_HEADERS
Path.h Path.h
codegeneration/cpp/AronGeneratedClass.h codegeneration/cpp/AronGeneratedClass.h
codegeneration/cpp/AronGeneratedObject.h
codegeneration/cpp/AronGeneratedIntEnum.h
aron_conversions.h aron_conversions.h
rw.h rw.h
......
/*
* This file is part of ArmarX.
*
* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
* Karlsruhe Institute of Technology (KIT), all rights reserved.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include "AronGeneratedClass.h"
namespace armarx::aron::cpp
{
class AronGeneratedIntEnumBase : public AronGeneratedClass
{
public:
AronGeneratedIntEnumBase() = default;
virtual ~AronGeneratedIntEnumBase() = default;
/// Convert the current bo to an aron variant data dict
virtual armarx::aron::data::IntPtr toAron() const = 0;
/// Convert the current bo to the ice representation of an aron variant data dict
virtual armarx::aron::data::dto::AronIntPtr toAronDTO() const = 0;
/// Set all members of the current bo according to the aron variant data dict
virtual void fromAron(const armarx::aron::data::IntPtr& input) = 0;
/// Set all members of the current bo according to the ice representation of an aron variant data dict
virtual void fromAron(const armarx::aron::data::dto::AronIntPtr& input) = 0;
};
template <class Derived>
class AronGeneratedIntEnum :
public AronGeneratedIntEnumBase
{
public:
};
template <class T>
concept isAronGeneratedIntEnum = std::is_base_of<AronGeneratedIntEnumBase, T>::value;
}
namespace armarx::aron::codegenerator::cpp
{
using AronGeneratedIntEnumBase = aron::cpp::AronGeneratedIntEnumBase;
template <class Derived>
using AronGeneratedIntEnum = aron::cpp::AronGeneratedIntEnum<Derived>;
}
/*
* This file is part of ArmarX.
*
* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
* Karlsruhe Institute of Technology (KIT), all rights reserved.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include "AronGeneratedClass.h"
namespace armarx::aron::cpp
{
class AronGeneratedObjectBase :
public AronGeneratedClass
{
public:
AronGeneratedObjectBase() = default;
virtual ~AronGeneratedObjectBase() = default;
/// Convert the current bo to an aron variant data dict
virtual armarx::aron::data::DictPtr toAron() const = 0;
/// Convert the current bo to the ice representation of an aron variant data dict
virtual armarx::aron::data::dto::DictPtr toAronDTO() const = 0;
/// Set all members of the current bo according to the aron variant data dict
virtual void fromAron(const armarx::aron::data::DictPtr& input) = 0;
/// Set all members of the current bo according to the ice representation of an aron variant data dict
virtual void fromAron(const armarx::aron::data::dto::DictPtr& input) = 0;
};
template <class Derived>
class AronGeneratedObject :
public AronGeneratedObjectBase
{
public:
AronGeneratedObject() = default;
virtual ~AronGeneratedObject() = default;
template <class T>
void to(T& t) const
{
const Derived* d = dynamic_cast<const Derived*>(this);
if (d)
{
t.fromAron(*d);
}
}
template <class T>
void from(const T& t)
{
Derived* d = dynamic_cast<Derived*>(this);
if (d)
{
t.toAron(*d);
}
}
template <class T>
void to(T& t, void(*fromAron)(const Derived&, T&)) const
{
const Derived* d = dynamic_cast<const Derived*>(this);
if (d)
{
fromAron(*d, t);
}
}
template <class T>
void from(const T& t, void(*toAron)(Derived&, const T&))
{
Derived* d = dynamic_cast<Derived*>(this);
if (d)
{
toAron(*d, t);
}
}
};
template <class T>
concept isAronGeneratedObject = std::is_base_of<AronGeneratedObjectBase, T>::value;
}
namespace armarx::aron::codegenerator::cpp
{
using AronGeneratedObjectBase = aron::cpp::AronGeneratedObjectBase;
template <class Derived>
using AronGeneratedObject = aron::cpp::AronGeneratedObject<Derived>;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment