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

aron fixes for better code generation. Finalized maybe types. Merged master...

aron fixes for better code generation. Finalized maybe types. Merged master and armem/dev into aron/dev. Fixed build issues. Repaired ArMemMemoryTest test since an update now adds a provider segment (instead of throwing MisingEntryException)
parent c81e80da
No related branches found
No related tags found
2 merge requests!171Periodic merge of armem/dev into master,!151Updates to aron code generation
Showing
with 310 additions and 116 deletions
......@@ -33,7 +33,7 @@
<EigenMatrix rows="4" cols="4" type="float" />
</ObjectChild>
<ObjectChild key='the_ivt_image'>
<IVTCByteImage type="GrayScale" />
<IVTCByteImage type="GrayScale" raw_ptr="true"/>
</ObjectChild>
<ObjectChild key='the_float_list'>
......
......@@ -158,8 +158,8 @@ namespace armarx::armem::server::obj
// {
// std::lock_guard g(server::ComponentPluginUser::workingMemoryMutex);
// // server::ComponentPluginUser::workingMemory.addCoreSegment("ArticulatedObjectInstance"); // TODO , arondto::::toInitialAronType());
// server::ComponentPluginUser::workingMemory.addCoreSegment("ArticulatedObjectClass"); // TODO , arondto::::toInitialAronType());
// // server::ComponentPluginUser::workingMemory.addCoreSegment("ArticulatedObjectInstance"); // TODO , arondto::::toAronType());
// server::ComponentPluginUser::workingMemory.addCoreSegment("ArticulatedObjectClass"); // TODO , arondto::::toAronType());
// }
createRemoteGuiTab();
......
......@@ -32,7 +32,7 @@
// Header
#include "ArmarXCore/core/logging/Logging.h"
#include "RobotAPI/libraries/armem/core/Time.h"
#include "RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h"
#include "RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h"
#include "RobotAPI/libraries/core/Pose.h"
// Simox
......
......@@ -70,8 +70,8 @@ namespace armarx
workingMemory.name() = p.memoryName;
{
armarx::armem::wm::CoreSegment& c = workingMemory.addCoreSegment(p.statechartCoreSegmentName, armarx::armem::arondto::Statechart::Transition::toInitialAronType());
c.addProviderSegment("Transitions", armarx::armem::arondto::Statechart::Transition::toInitialAronType());
armarx::armem::wm::CoreSegment& c = workingMemory.addCoreSegment(p.statechartCoreSegmentName, armarx::armem::arondto::Statechart::Transition::toAronType());
c.addProviderSegment("Transitions", armarx::armem::arondto::Statechart::Transition::toAronType());
}
}
......
......@@ -80,7 +80,7 @@ void armarx::objpose::fromAron(const arondto::ObjectPose& dto, ObjectPose& bo)
bo.confidence = dto.confidence;
bo.timestamp = IceUtil::Time::microSeconds(dto.timestamp);
bo.timestamp = dto.timestamp;
if (dto.localOOBBValid)
{
......@@ -122,7 +122,7 @@ void armarx::objpose::toAron(arondto::ObjectPose& dto, const ObjectPose& bo)
dto.confidence = bo.confidence;
dto.timestamp = bo.timestamp.toMicroSeconds();
dto.timestamp = bo.timestamp;
if (bo.localOOBB)
{
......
......@@ -7,7 +7,7 @@ void armarx::armem::fromAron(const arondto::MemoryID& dto, MemoryID& bo)
bo.coreSegmentName = dto.coreSegmentName;
bo.providerSegmentName = dto.providerSegmentName;
bo.entityName = dto.entityName;
bo.timestamp = IceUtil::Time::microSeconds(dto.timestamp);
bo.timestamp = dto.timestamp;
bo.instanceIndex = dto.instanceIndex;
}
......@@ -17,7 +17,7 @@ void armarx::armem::toAron(arondto::MemoryID& dto, const MemoryID& bo)
dto.coreSegmentName = bo.coreSegmentName;
dto.providerSegmentName = bo.providerSegmentName;
dto.entityName = bo.entityName;
dto.timestamp = bo.timestamp.toMicroSeconds();
dto.timestamp = bo.timestamp;
dto.instanceIndex = bo.instanceIndex;
}
......
......@@ -10,7 +10,7 @@ std::ostream& armarx::armem::wm::operator<<(std::ostream& os, const EntityInstan
<< "\n- t_sent = \t" << armem::toStringMicroSeconds(d.timeSent) << " us"
<< "\n- t_arrived = \t" << armem::toStringMicroSeconds(d.timeArrived) << " us"
<< "\n- confidence = \t" << d.confidence << " us"
;
;
return os;
}
......@@ -28,9 +28,17 @@ namespace armarx::armem::wm
bool EntityInstance::equalsDeep(const EntityInstance& other) const
{
return id() == other.id()
&& _metadata == other.metadata()
&& _data->equalsDeep(other.data());
if (_data and other.data())
{
return id() == other.id()
&& _metadata == other.metadata()
&& *_data == *other.data();
}
if (_data or other.data())
{
return false;
}
return id() == other.id() && _metadata == other.metadata();
}
void EntityInstance::update(const EntityUpdate& update, int index)
......
......@@ -627,8 +627,9 @@ BOOST_AUTO_TEST_CASE(test_segment_setup)
{
update.entityID = armem::MemoryID::fromString("Memory/OtherCoreSegment");
BOOST_CHECK_THROW(coreSegment.update(update), armem::error::ContainerNameMismatch);
update.entityID = armem::MemoryID::fromString("Memory/ImageRGB/MissingProvider");
BOOST_CHECK_THROW(coreSegment.update(update), armem::error::MissingEntry);
// This adds the segment now (changed default behavior)
//update.entityID = armem::MemoryID::fromString("Memory/ImageRGB/MissingProvider");
//BOOST_CHECK_THROW(coreSegment.update(update), armem::error::MissingEntry);
}
armem::wm::ProviderSegment& providerSegment = coreSegment.addProviderSegment("SomeRGBImageProvider");
......
......@@ -48,7 +48,7 @@ namespace armarx::armem::server::obj::articulated_object_class
{
ARMARX_CHECK_NOT_NULL(iceMemory.workingMemory);
coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreClassSegmentName, arondto::RobotDescription::toInitialAronType());
coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreClassSegmentName, arondto::RobotDescription::toAronType());
coreSegment->setMaxHistorySize(p.maxHistorySize);
if (p.loadFromObjectsPackage)
......
......@@ -49,7 +49,7 @@ namespace armarx::armem::server::obj::articulated_object_instance
{
ARMARX_CHECK_NOT_NULL(iceMemory.workingMemory);
coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreInstanceSegmentName, arondto::Robot::toInitialAronType());
coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreInstanceSegmentName, arondto::Robot::toAronType());
coreSegment->setMaxHistorySize(p.maxHistorySize);
}
......
......@@ -8,11 +8,6 @@ namespace armarx::armem::robot
{
/* to be moved */
void fromAron(const long& dto, IceUtil::Time& time)
{
time = IceUtil::Time::microSeconds(dto);
}
void toAron(long& dto, const IceUtil::Time& time)
{
dto = time.toMicroSeconds();
......@@ -51,14 +46,14 @@ namespace armarx::armem::robot
void fromAron(const arondto::RobotState& dto, RobotState& bo)
{
fromAron(dto.timestamp, bo.timestamp);
bo.timestamp = dto.timestamp;
bo.globalPose.matrix() = dto.globalPose;
bo.jointMap = dto.jointMap;
}
void toAron(arondto::RobotState& dto, const RobotState& bo)
{
toAron(dto.timestamp, bo.timestamp);
dto.timestamp = bo.timestamp;
dto.globalPose = bo.globalPose.matrix();
dto.jointMap = bo.jointMap;
}
......
......@@ -16,18 +16,12 @@ namespace armarx
{
/************ fromAron ************/
armem::Time timeFromAron(const int64_t timestamp)
{
return armem::Time::microSeconds(timestamp);
}
SensorHeader fromAron(const arondto::SensorHeader& aronSensorHeader)
{
return {.agent = aronSensorHeader.agent,
.frame = aronSensorHeader.frame,
.timestamp = timeFromAron(aronSensorHeader.timestamp)};
.timestamp = aronSensorHeader.timestamp};
}
void fromAron(const arondto::LaserScanStamped& aronLaserScan,
......@@ -70,7 +64,7 @@ namespace armarx
aronSensorHeader.agent = sensorHeader.agent;
aronSensorHeader.frame = sensorHeader.frame;
aronSensorHeader.timestamp = toAron(sensorHeader.timestamp);
aronSensorHeader.timestamp = sensorHeader.timestamp;
return aronSensorHeader;
}
......@@ -97,4 +91,4 @@ namespace armarx
toAron(laserScanStamped, aronLaserScanStamped);
}
} // namespace armarx
\ No newline at end of file
} // namespace armarx
......@@ -38,7 +38,7 @@ namespace armarx::armem
aron::toAron(dto.parentFrame, bo.parentFrame);
aron::toAron(dto.frame, bo.frame);
aron::toAron(dto.agent, bo.agent);
armarx::toAron(dto.timestamp, bo.timestamp);
dto.timestamp = bo.timestamp;
}
void fromAron(const arondto::TransformHeader& dto, robot_state::TransformHeader& bo)
......@@ -46,7 +46,7 @@ namespace armarx::armem
aron::fromAron(dto.parentFrame, bo.parentFrame);
aron::fromAron(dto.frame, bo.frame);
aron::fromAron(dto.agent, bo.agent);
armarx::fromAron(dto.timestamp, bo.timestamp);
bo.timestamp = dto.timestamp;
}
/* JointState */
......
......@@ -55,7 +55,7 @@ namespace armarx::armem::server::robot_state::description
ARMARX_INFO << "Adding core segment '" << p.coreSegment << "'";
coreSegment = &iceMemory.workingMemory->addCoreSegment(
p.coreSegment, arondto::RobotDescription::toInitialAronType());
p.coreSegment, arondto::RobotDescription::toAronType());
coreSegment->setMaxHistorySize(p.maxHistorySize);
}
......@@ -73,7 +73,7 @@ namespace armarx::armem::server::robot_state::description
const Time now = TimeUtil::GetTime();
const MemoryID providerID = coreSegment->id().withProviderSegmentName(robotDescription.name);
coreSegment->addProviderSegment(providerID.providerSegmentName, arondto::RobotDescription::toInitialAronType());
coreSegment->addProviderSegment(providerID.providerSegmentName, arondto::RobotDescription::toAronType());
EntityUpdate update;
update.entityID = providerID.withEntityName("description");
......
......@@ -61,7 +61,7 @@ namespace armarx::armem::server::robot_state::localization
ARMARX_INFO << "Adding core segment '" << p.coreSegment << "'";
coreSegment = &iceMemory.workingMemory->addCoreSegment(
p.coreSegment, arondto::Transform::toInitialAronType());
p.coreSegment, arondto::Transform::toAronType());
coreSegment->setMaxHistorySize(p.maxHistorySize);
}
......
......@@ -132,22 +132,22 @@ namespace armarx::aron::cppserializer
}
}
std::cout << "Generate Type classes" << std::endl;
//std::cout << "Generate Type classes" << std::endl;
generateInnerTypeObjects(c, publicGenerateObjectType->nestedObjects);
// ctor
c->addCtor(serializer->toCtor(c->getName()));
// Generic methods
std::cout << "Generate equals method" << std::endl;
//std::cout << "Generate equals method" << std::endl;
CppMethodPtr equals = serializer->toEqualsMethod();
c->addMethod(equals);
std::cout << "Generate reset method" << std::endl;
//std::cout << "Generate reset method" << std::endl;
CppMethodPtr resetHard = serializer->toResetHardMethod();
c->addMethod(resetHard);
std::cout << "Generate init method" << std::endl;
//std::cout << "Generate init method" << std::endl;
CppMethodPtr resetSoft = serializer->toResetSoftMethod();
c->addMethod(resetSoft);
......
......@@ -42,12 +42,13 @@ namespace armarx::aron::cppserializer
const std::map<std::string, std::string> Serializer::ESCAPE_ACCESSORS =
{
{"->", "_ptr_"},
{".", "_dot_"},
{"[", "_lbrE_"},
{"]", "_rbrE_"},
{"(", "_lbrR_"},
{")", "_rbrR_"}
{"->", "__ptr__"},
{".", "__dot__"},
{"[", "__lbrC__"},
{"]", "__rbrC__"},
{"(", "__lbrR__"},
{")", "__rbrR__"},
{"*", "__ast__"},
};
const SerializerFactoryPtr Serializer::FACTORY = SerializerFactoryPtr(new SerializerFactory());
......@@ -78,35 +79,54 @@ namespace armarx::aron::cppserializer
CppBlockPtr Serializer::ResolveMaybeWriteBlock(const std::string& accessor, const CppBlockPtr& block_if_data, const typenavigator::NavigatorPtr& typenavigator)
{
CppBlockPtr b = std::make_shared<CppBlock>();
if (!accessor.empty())
{
b->addLine("// Generate WriteInterface API calls for " + accessor);
}
else
{
b->addLine("// Generate WriteInterface API calls for the top level object " + ExtractCppTypename(typenavigator));
}
if (typenavigator->getMaybe() != type::Maybe::eNone)
{
CppBlockPtr b = std::make_shared<CppBlock>();
if (typenavigator->getMaybe() == type::Maybe::eOptional)
{
b->addLine("if (" + accessor + ".has_value())");
b->addBlock(block_if_data);
}
if (typenavigator->getMaybe() == type::Maybe::eRawPointer)
switch (typenavigator->getMaybe())
{
b->addLine("if (" + accessor + " == NULL)");
b->addBlock(block_if_data);
}
if (typenavigator->getMaybe() == type::Maybe::eSharedPointer || typenavigator->getMaybe() == type::Maybe::eUniquePointer)
{
b->addLine("if (" + accessor + " == nullptr)");
b->addBlock(block_if_data);
case type::Maybe::eOptional:
{
b->addLine("if (" + accessor + ".has_value())");
b->addBlock(block_if_data);
break;
}
case type::Maybe::eRawPointer:
{
b->addLine("if (" + accessor + " != NULL)");
b->addBlock(block_if_data);
break;
}
case type::Maybe::eSharedPointer:
case type::Maybe::eUniquePointer:
{
b->addLine("if (" + accessor + " != nullptr)");
b->addBlock(block_if_data);
break;
}
default:
{
throw error::MaybeNotValidException("Serializer", "ResolveMaybeWriteBlock", "Unkown Maybe type (perhaps forgot to add in switch case?)", typenavigator->getMaybe(), typenavigator->getPath());
}
}
b->addLine("else");
CppBlockPtr block_if_no_data = std::make_shared<CppBlock>();
block_if_no_data->addLine("w.writeNull();");
block_if_no_data->addLine("w.writeNull(); // The maybe type '" + accessor + "' has no data, so we simply write NULL (resulting in a AronData nullhandle)");
b->addBlock(block_if_no_data);
return b;
}
else
{
return block_if_data;
}
b->appendBlock(block_if_data);
return b;
}
CppBlockPtr Serializer::ResolveMaybeReadBlock(const std::string& accessor, const std::string& readElement, const CppBlockPtr& block_if_data, const typenavigator::NavigatorPtr& typenavigator)
......@@ -114,22 +134,194 @@ namespace armarx::aron::cppserializer
std::string escaped_accessor = EscapeAccessor(accessor);
std::string read_start_result_accessor = escaped_accessor + READ_START_RETURN_TYPE_ACCESSOR;
CppBlockPtr resolved_block = std::make_shared<CppBlock>();
if (!accessor.empty())
{
resolved_block->addLine("// Generate ReadInterface API calls for " + accessor);
}
else
{
resolved_block->addLine("// Generate ReadInterface API calls for the top level object " + ExtractCppTypename(typenavigator));
}
if (!readElement.empty())
{
resolved_block->addLine("auto " + read_start_result_accessor + " = " + readElement + "; // of " + accessor);
}
if (typenavigator->getMaybe() != type::Maybe::eNone)
{
resolved_block->addLine("if (" + read_start_result_accessor + ".success)");
CppBlockPtr if_success = std::make_shared<CppBlock>();
switch (typenavigator->getMaybe())
{
case type::Maybe::eOptional:
{
auto s = FromAronTypeNaviagtorPtr(typenavigator);
if_success->addLine(accessor + " = " + s->getFullTypenameGenerator() + "();");
if_success->appendBlock(block_if_data);
break;
}
case type::Maybe::eRawPointer:
{
auto s = FromAronTypeNaviagtorPtr(typenavigator);
if_success->addLine(accessor + " = " + s->getFullTypenameGenerator() + "();");
if_success->appendBlock(block_if_data);
break;
}
case type::Maybe::eSharedPointer:
case type::Maybe::eUniquePointer:
{
auto s = FromAronTypeNaviagtorPtr(typenavigator);
if_success->addLine(accessor + " = " + s->getFullTypenameGenerator() + "();");
if_success->appendBlock(block_if_data);
break;
}
default:
{
throw error::MaybeNotValidException("Serializer", "ResolveMaybeReadBlock", "Unkown Maybe type (perhaps forgot to add in switch case?)", typenavigator->getMaybe(), typenavigator->getPath());
}
}
resolved_block->addBlock(if_success);
return resolved_block;
}
resolved_block->appendBlock(block_if_data);
return resolved_block;
}
CppBlockPtr Serializer::ResolveMaybeEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor, const CppBlockPtr& block_if_data, const typenavigator::NavigatorPtr& typenavigator)
{
CppBlockPtr b = std::make_shared<CppBlock>();
b->addLine("auto " + read_start_result_accessor + " = " + readElement + ";");
if (typenavigator->getMaybe() == type::Maybe::eOptional)
if (!accessor.empty())
{
b->addLine("// Comparing " + accessor + " and " + otherInstanceAccessor);
}
else
{
b->addLine("if (" + read_start_result_accessor + ".success)");
b->addLine("// Comparing two objects of type " + ExtractCppTypename(typenavigator));
}
CppBlockPtr b2 = std::make_shared<CppBlock>();
b2->addLine(accessor + ".emplace();");
b2->appendBlock(block_if_data);
if (typenavigator->getMaybe() != type::Maybe::eNone)
{
switch (typenavigator->getMaybe())
{
case type::Maybe::eOptional:
{
b->addLine("if (" + accessor + ".has_value() and " + otherInstanceAccessor + ".has_value()) // both have a value set");
b->addBlock(block_if_data);
b->addLine("if ((" + accessor + ".has_value() and !" + otherInstanceAccessor + ".has_value()) or (!" + accessor + ".has_value() and " + otherInstanceAccessor + ".has_value())) // only one has a value set (XOR)");
b->addLine("\t return false;");
break;
}
case type::Maybe::eRawPointer:
{
b->addLine("if (" + accessor + " != NULL and " + otherInstanceAccessor + " != NULL) // both have a value set");
b->addBlock(block_if_data);
b->addLine("if ((" + accessor + " != NULL and " + otherInstanceAccessor + " == NULL) or (" + accessor + " == NULL and " + otherInstanceAccessor + " != NULL)) // only one has a value set (XOR)");
b->addLine("\t return false;");
break;
}
case type::Maybe::eSharedPointer:
case type::Maybe::eUniquePointer:
{
b->addLine("if (" + accessor + " != nullptr and " + otherInstanceAccessor + " != nullptr) // both have a value set");
b->addBlock(block_if_data);
b->addLine("if ((" + accessor + " != nullptr and " + otherInstanceAccessor + " == nullptr) or (" + accessor + " == nullptr and " + otherInstanceAccessor + " != nullptr)) // only one has a value set (XOR)");
b->addLine("\t return false;");
break;
}
default:
{
throw error::MaybeNotValidException("Serializer", "ResolveMaybeEqualsBlock", "Unkown Maybe type (perhaps forgot to add in switch case?)", typenavigator->getMaybe(), typenavigator->getPath());
}
}
return b;
}
b->appendBlock(block_if_data);
return b;
}
b->addBlock(b2);
CppBlockPtr Serializer::ResolveMaybeResetSoftBlock(const std::string& accessor, const CppBlockPtr& block_if_data, const typenavigator::NavigatorPtr& typenavigator)
{
CppBlockPtr b = std::make_shared<CppBlock>();
if (!accessor.empty())
{
b->addLine("// Resetting soft member " + accessor);
}
else
{
b->appendBlock(block_if_data);
b->addLine("// Ressetting soft the type " + ExtractCppTypename(typenavigator));
}
if (typenavigator->getMaybe() != type::Maybe::eNone)
{
switch (typenavigator->getMaybe())
{
case type::Maybe::eOptional:
{
b->addLine("if (" + accessor + ".has_value())");
b->addBlock(block_if_data);
break;
}
case type::Maybe::eRawPointer:
{
b->addLine("if (" + accessor + " != NULL)");
b->addBlock(block_if_data);
break;
}
case type::Maybe::eSharedPointer:
case type::Maybe::eUniquePointer:
{
b->addLine("if (" + accessor + " != nullptr)");
b->addBlock(block_if_data);
break;
}
default:
{
throw error::MaybeNotValidException("Serializer", "ResolveMaybeResetSoftBlock", "Unkown Maybe type (perhaps forgot to add in switch case?)", typenavigator->getMaybe(), typenavigator->getPath());
}
}
return b;
}
b->appendBlock(block_if_data);
return b;
}
CppBlockPtr Serializer::ResolveMaybeResetHardBlock(const std::string& accessor, const CppBlockPtr& block_if_data, const typenavigator::NavigatorPtr& typenavigator)
{
CppBlockPtr b = std::make_shared<CppBlock>();
if (!accessor.empty())
{
b->addLine("// Resetting hard member " + accessor);
}
else
{
b->addLine("// Ressetting hard the type " + ExtractCppTypename(typenavigator));
}
if (typenavigator->getMaybe() != type::Maybe::eNone)
{
switch (typenavigator->getMaybe())
{
case type::Maybe::eOptional:
case type::Maybe::eRawPointer:
case type::Maybe::eSharedPointer:
case type::Maybe::eUniquePointer:
{
b->addLine(accessor + " = {};");
break;
}
default:
{
throw error::MaybeNotValidException("Serializer", "ResolveMaybeResetSoftBlock", "Unkown Maybe type (perhaps forgot to add in switch case?)", typenavigator->getMaybe(), typenavigator->getPath());
}
}
return b;
}
b->appendBlock(block_if_data);
return b;
}
......@@ -156,7 +348,7 @@ namespace armarx::aron::cppserializer
std::string Serializer::ExtractCppTypename(const typenavigator::NavigatorPtr& n)
{
SerializerPtr cpp = Serializer::FromAronTypeNaviagtorPtr(n);
return cpp->getFullCppTypename();
return cpp->getCoreCppTypename();
}
std::vector<std::string> Serializer::ExtractCppTypenames(const std::vector<typenavigator::NavigatorPtr>& n)
......
......@@ -116,6 +116,9 @@ namespace armarx::aron::cppserializer
static std::string ResolveMaybeAccessor(const std::string&, const typenavigator::NavigatorPtr&);
static CppBlockPtr ResolveMaybeWriteBlock(const std::string&, const CppBlockPtr&, const typenavigator::NavigatorPtr&);
static CppBlockPtr ResolveMaybeReadBlock(const std::string&, const std::string&, const CppBlockPtr&, const typenavigator::NavigatorPtr&);
static CppBlockPtr ResolveMaybeEqualsBlock(const std::string&, const std::string&, const CppBlockPtr&, const typenavigator::NavigatorPtr&);
static CppBlockPtr ResolveMaybeResetSoftBlock(const std::string&, const CppBlockPtr&, const typenavigator::NavigatorPtr&);
static CppBlockPtr ResolveMaybeResetHardBlock(const std::string&, const CppBlockPtr&, const typenavigator::NavigatorPtr&);
protected:
static const std::string READ_START_RETURN_TYPE_ACCESSOR;
......
......@@ -30,45 +30,44 @@ namespace armarx::aron::cppserializer::serializer
// constructors
DictSerializer::DictSerializer(const typenavigator::DictNavigatorPtr& e) :
detail::ContainerSerializerBase<typenavigator::DictNavigator, DictSerializer>("std::map<std::string, " + FromAronTypeNaviagtorPtr(e->getAcceptedType())->getFullCppTypename() + ">",
simox::meta::get_type_name(typeid(data::AronDict)),
simox::meta::get_type_name(typeid(type::AronDict)), e)
simox::meta::get_type_name(typeid(data::AronDict)),
simox::meta::get_type_name(typeid(type::AronDict)), e)
{
}
// virtual implementations
CppBlockPtr DictSerializer::getResetSoftBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine(accessor + " = {};");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
std::string resolved_accessor = ResolveMaybeAccessor(accessor, typenavigator);
block_if_data->addLine(accessor + nextEl() + "clear();");
return ResolveMaybeResetSoftBlock(accessor, block_if_data, typenavigator);
}
CppBlockPtr DictSerializer::getResetHardBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine(accessor + " = {};");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
block_if_data->addLine(accessor + " = " + this->getFullTypenameGenerator() + "();");
return ResolveMaybeResetHardBlock(accessor, block_if_data, typenavigator);
}
CppBlockPtr DictSerializer::getWriteTypeBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine("w.writeStartDict({" + MAYBE_TO_STRING(typenavigator->getMaybe()) + "});");
std::string escaped_accessor = EscapeAccessor(accessor);
std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR;
b->addLine("w.writeStartDict({" + MAYBE_TO_STRING(typenavigator->getMaybe()) + "}); // of " + accessor);
auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType());
CppBlockPtr b2 = type_s->getWriteTypeBlock(type_s->getFullCppTypename());
b->appendBlock(b2);
b->addLine("w.writeEndDict();");
b->addLine("w.writeEndDict(); // of " + accessor);
return b;
}
CppBlockPtr DictSerializer::getWriteBlock(const std::string& accessor) const
{
CppBlockPtr block_if_data = std::make_shared<CppBlock>();
block_if_data->addLine("w.writeStartDict();");
block_if_data->addLine("w.writeStartDict(); // of " + accessor);
std::string escaped_accessor = EscapeAccessor(accessor);
std::string accessor_iterator_key = escaped_accessor + DICT_KEY_ACCESSOR;
......@@ -83,7 +82,7 @@ namespace armarx::aron::cppserializer::serializer
b2->addLine("w.writeKey(" + accessor_iterator_key + ");");
b2->appendBlock(type_s->getWriteBlock(accessor_iterator_val));
block_if_data->addBlock(b2);
block_if_data->addLine("w.writeEndDict();");
block_if_data->addLine("w.writeEndDict(); // of " + accessor);
return ResolveMaybeWriteBlock(accessor, block_if_data, typenavigator);
}
......@@ -98,10 +97,10 @@ namespace armarx::aron::cppserializer::serializer
auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType());
block_if_data->addLine("while(!r.readEndDict())");
block_if_data->addLine("while(!r.readEndDict()) // of " + accessor);
CppBlockPtr b2 = CppBlockPtr(new CppBlock());
b2->addLine("std::string " + accessor_iterator_key + " = r.readKey();");
b2->addLine("std::string " + accessor_iterator_key + " = r.readKey(); // in dict " + accessor);
b2->addLine(type_s->getFullCppTypename() + " " + accessor_iterator + ";");
b2->appendBlock(type_s->getReadBlock(accessor_iterator));
b2->addLine(accessor + nextEl() + "insert({" + accessor_iterator_key + ", " + accessor_iterator + "});");
......@@ -112,10 +111,10 @@ namespace armarx::aron::cppserializer::serializer
CppBlockPtr DictSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))");
b->addLine("\t return false;");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
block_if_data->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))");
block_if_data->addLine("\t return false;");
return ResolveMaybeEqualsBlock(accessor, otherInstanceAccessor, block_if_data, typenavigator);
}
}
......@@ -29,43 +29,45 @@ namespace armarx::aron::cppserializer::serializer
// constructors
ListSerializer::ListSerializer(const typenavigator::ListNavigatorPtr& e) :
detail::ContainerSerializerBase<typenavigator::ListNavigator, ListSerializer>("std::vector<" + FromAronTypeNaviagtorPtr(e->getAcceptedType())->getFullCppTypename() + ">",
simox::meta::get_type_name(typeid(data::AronList)),
simox::meta::get_type_name(typeid(type::AronList)), e)
simox::meta::get_type_name(typeid(data::AronList)),
simox::meta::get_type_name(typeid(type::AronList)), e)
{
}
CppBlockPtr ListSerializer::getResetSoftBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine(accessor + " = {};");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
std::string resolved_accessor = ResolveMaybeAccessor(accessor, typenavigator);
block_if_data->addLine(accessor + nextEl() + "clear();");
return ResolveMaybeResetSoftBlock(accessor, block_if_data, typenavigator);
}
CppBlockPtr ListSerializer::getResetHardBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine(accessor + " = {};");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
block_if_data->addLine(accessor + " = " + this->getFullTypenameGenerator() + "();");
return ResolveMaybeResetHardBlock(accessor, block_if_data, typenavigator);
}
CppBlockPtr ListSerializer::getWriteTypeBlock(const std::string&) const
CppBlockPtr ListSerializer::getWriteTypeBlock(const std::string& accessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine("w.writeStartList({" + MAYBE_TO_STRING(typenavigator->getMaybe()) + "});");
b->addLine("w.writeStartList({" + MAYBE_TO_STRING(typenavigator->getMaybe()) + "}); // of " + accessor);
auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType());
CppBlockPtr b2 = type_s->getWriteTypeBlock(type_s->getFullCppTypename());
b->appendBlock(b2);
b->addLine("w.writeEndList();");
b->addLine("w.writeEndList(); // of " + accessor);
return b;
}
CppBlockPtr ListSerializer::getWriteBlock(const std::string& accessor) const
{
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
block_if_data->addLine("w.writeStartList();");
block_if_data->addLine("w.writeStartList(); // of " + accessor);
std::string escaped_accessor = EscapeAccessor(accessor);
std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR;
......@@ -73,7 +75,7 @@ namespace armarx::aron::cppserializer::serializer
auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType());
block_if_data->addLine("for(unsigned int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + nextEl() + "size(); ++" + accessor_iterator + ")");
block_if_data->addBlock(type_s->getWriteBlock(accessor + nextEl() + "at(" + accessor_iterator + ")"));
block_if_data->addLine("w.writeEndList();");
block_if_data->addLine("w.writeEndList(); // of " + accessor);
return ResolveMaybeWriteBlock(accessor, block_if_data, typenavigator);
}
......@@ -85,7 +87,7 @@ namespace armarx::aron::cppserializer::serializer
std::string escaped_accessor = EscapeAccessor(accessor);
std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR;
block_if_data->addLine("while(!r.readEndList())");
block_if_data->addLine("while(!r.readEndList()) // of " + accessor);
CppBlockPtr b2 = CppBlockPtr(new CppBlock());
auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType());
......@@ -99,9 +101,9 @@ namespace armarx::aron::cppserializer::serializer
CppBlockPtr ListSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const
{
CppBlockPtr b = CppBlockPtr(new CppBlock());
b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))");
b->addLine("\t return false;");
return b;
CppBlockPtr block_if_data = CppBlockPtr(new CppBlock());
block_if_data->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))");
block_if_data->addLine("\t return false;");
return ResolveMaybeEqualsBlock(accessor, otherInstanceAccessor, block_if_data, typenavigator);
}
}
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