Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sw/armarx/robot-api
  • uwkce_singer/robot-api
  • untcg_hofmann/robot-api
  • ulqba_korosakov/RobotAPI
4 results
Show changes
Showing
with 636 additions and 29 deletions
......@@ -47,7 +47,7 @@ namespace armarx::aron::codegenerator::cpp::generator
std::vector<std::string> ObjectClass::getRequiredIncludes() const
{
std::vector<std::string> ret;
for (const auto& [key, child] : type.getMemberTypes())
for (const auto& [key, child] : type.getDirectMemberTypes())
{
(void) key;
auto child_s = FromAronType(*child);
......@@ -59,7 +59,7 @@ namespace armarx::aron::codegenerator::cpp::generator
std::vector<CppFieldPtr> ObjectClass::getPublicVariableDeclarations(const std::string&) const
{
std::vector<CppFieldPtr> fields;
for (const auto& [key, member] : type.getMemberTypes())
for (const auto& [key, member] : type.getDirectMemberTypes())
{
auto member_s = FromAronType(*member);
std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key);
......@@ -77,7 +77,7 @@ namespace armarx::aron::codegenerator::cpp::generator
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);
CppBlockPtr b2 = child_s->getResetSoftBlock(key);
......@@ -95,7 +95,7 @@ namespace armarx::aron::codegenerator::cpp::generator
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);
CppBlockPtr b2 = child_s->getResetHardBlock(key);
......@@ -127,7 +127,7 @@ namespace armarx::aron::codegenerator::cpp::generator
}
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);
std::string child_return_variant;
......@@ -176,7 +176,7 @@ namespace armarx::aron::codegenerator::cpp::generator
}
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);
std::string child_return_variant;
......@@ -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());
for (const auto& [key, child] : type.getMemberTypes())
for (const auto& [key, child] : type.getDirectMemberTypes())
{
const auto child_s = FromAronType(*child);
std::string child_accessor = OBJECT_MEMBERS_ACCESSOR + "_" + key + "_iterator";
......@@ -230,7 +230,7 @@ namespace armarx::aron::codegenerator::cpp::generator
block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + "::operator== (" + otherInstanceAccessor + ")))");
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);
CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key);
......@@ -250,7 +250,7 @@ namespace armarx::aron::codegenerator::cpp::generator
}
bool anyComplex = false;
for (const auto& [key, child] : type.getMemberTypes())
for (const auto& [key, child] : type.getDirectMemberTypes())
{
auto child_s = FromAronType(*child);
auto initList = child_s->getCopyCtorInitializers(key);
......
......@@ -37,6 +37,7 @@ namespace armarx::aron::codegenerator
std::string include;
std::string enforceConversion = "";
std::string enforceMemberAccess = "";
bool override = false;
};
......
......@@ -37,5 +37,6 @@ namespace armarx::aron::codegenerator
std::string include;
std::string enforceConversion = "";
std::string enforceMemberAccess = "";
bool override = false;
};
}
......@@ -106,6 +106,24 @@ armarx_add_test(
${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
######################
......
/*
* 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));
}
}
......@@ -10,11 +10,13 @@ set(LIBS
set(LIB_FILES
Converter.cpp
VectorConverter.cpp
DatatypeConverter.cpp
)
set(LIB_HEADERS
Converter.h
VectorConverter.h
DatatypeConverter.h
)
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
......
#include "DatatypeConverter.h"
namespace armarx::aron::converter
{
void DatatypeConverter::visitAronVariant(const type::ObjectPtr& el)
{
auto dict = aron::make_dict(el->getPath());
auto type = aron::make_string(el->getFullName(), Path(el->getPath(), {typeMemberName}));
dict->addElement(typeMemberName, type);
for (const auto& [key, child] : el->getMemberTypes())
{
DatatypeConverter converter;
aron::type::visit(converter, child);
dict->addElement(key, converter.latest);
}
latest = dict;
}
void DatatypeConverter::visitAronVariant(const type::DictPtr& el)
{
auto dict = aron::make_dict(el->getPath());
auto type = aron::make_string(el->getFullName(), Path(el->getPath(), {typeMemberName}));
dict->addElement(typeMemberName, type);
auto acceptedType = el->getAcceptedType();
DatatypeConverter converter;
aron::type::visit(converter, acceptedType);
dict->addElement(acceptedTypeMemberName, converter.latest);
latest = dict;
}
void DatatypeConverter::visitAronVariant(const type::ListPtr& el)
{
auto dict = aron::make_dict(el->getPath());
auto type = aron::make_string(el->getFullName(), Path(el->getPath(), {typeMemberName}));
dict->addElement(typeMemberName, type);
auto acceptedType = el->getAcceptedType();
DatatypeConverter converter;
aron::type::visit(converter, acceptedType);
dict->addElement(acceptedTypeMemberName, converter.latest);
latest = dict;
}
void DatatypeConverter::visitAronVariant(const type::PairPtr& el)
{
auto dict = aron::make_dict(el->getPath());
auto type = aron::make_string(el->getFullName(), Path(el->getPath(), {typeMemberName}));
dict->addElement(typeMemberName, type);
auto acceptedType1 = el->getFirstAcceptedType();
DatatypeConverter converter1;
aron::type::visit(converter1, acceptedType1);
dict->addElement(firstAcceptedTypeMemberName, converter1.latest);
auto acceptedType2 = el->getSecondAcceptedType();
DatatypeConverter converter2;
aron::type::visit(converter2, acceptedType2);
dict->addElement(secondAcceptedTypeMemberName, converter2.latest);
latest = dict;
}
void DatatypeConverter::visitAronVariant(const type::TuplePtr& el)
{
auto dict = aron::make_dict(el->getPath());
auto type = aron::make_string(el->getFullName(), Path(el->getPath(), {typeMemberName}));
dict->addElement(typeMemberName, type);
int i = 0;
for (const auto& child : el->getAcceptedTypes())
{
DatatypeConverter converter;
aron::type::visit(converter, child);
dict->addElement(acceptedTypeMemberName + "_" + std::to_string(i++), converter.latest);
}
latest = dict;
}
void DatatypeConverter::visitAronVariant(const type::MatrixPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::NDArrayPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::QuaternionPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::PointCloudPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::ImagePtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::IntEnumPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::IntPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::LongPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::FloatPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::DoublePtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::BoolPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::StringPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
void DatatypeConverter::visitAronVariant(const type::AnyObjectPtr& el)
{
latest = aron::make_string(el->getFullName(), el->getPath());
}
}
/*
* 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/>.
*
* @author Fabian Peller ( fabian dot peller at kit dot edu )
* @date 2023
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <algorithm>
#include <vector>
#include <RobotAPI/libraries/aron/core/data/variant/All.h>
#include <RobotAPI/libraries/aron/core/type/visitor/variant/VariantVisitor.h>
namespace armarx::aron::converter
{
class DatatypeConverter :
public aron::type::ConstVariantVisitor
{
const std::string typeMemberName = "_aron_type";
const std::string acceptedTypeMemberName = "_aron_accepted_type";
const std::string firstAcceptedTypeMemberName = "_aron_first_accepted_type";
const std::string secondAcceptedTypeMemberName = "_aron_second_accepted_type";
void visitAronVariant(const type::ObjectPtr&) override;
void visitAronVariant(const type::DictPtr&) override;
void visitAronVariant(const type::ListPtr&) override;
void visitAronVariant(const type::PairPtr&) override;
void visitAronVariant(const type::TuplePtr&) override;
void visitAronVariant(const type::MatrixPtr&) override;
void visitAronVariant(const type::NDArrayPtr&) override;
void visitAronVariant(const type::QuaternionPtr&) override;
void visitAronVariant(const type::PointCloudPtr&) override;
void visitAronVariant(const type::ImagePtr&) override;
void visitAronVariant(const type::IntEnumPtr&) override;
void visitAronVariant(const type::IntPtr&) override;
void visitAronVariant(const type::LongPtr&) override;
void visitAronVariant(const type::FloatPtr&) override;
void visitAronVariant(const type::DoublePtr&) override;
void visitAronVariant(const type::BoolPtr&) override;
void visitAronVariant(const type::StringPtr&) override;
void visitAronVariant(const type::AnyObjectPtr&) override;
public:
aron::data::VariantPtr latest;
};
}
......@@ -37,37 +37,97 @@ namespace armarx::aron::converter
{
class AronVectorConverter
{
private:
template<typename T>
static std::vector<T> convert_to_1d_vector(const unsigned char* data, const int elements, const int offset, const int size)
{
ARMARX_CHECK_NOT_NULL(data);
ARMARX_CHECK(elements * sizeof(T) == size);
std::vector<T> v(elements);
memcpy(v.data(), data, size);
return v;
}
public:
AronVectorConverter() = delete;
template<typename T>
static std::vector<T> ConvertToVector(const data::NDArrayPtr& nav)
static std::vector<std::vector<T>> ConvertTo2DVector(const data::NDArray& nav)
{
ARMARX_CHECK_NOT_NULL(nav);
const auto& dims = nav.getShape();
const auto& dims = nav->getShape();
if (dims.size() != 3)
{
throw error::AronException(__PRETTY_FUNCTION__, "The NDArray must have 3 dimensions.", nav.getPath());
}
if (dims.size() != 2)
if (dims.at(dims.size()-1) != sizeof(T))
{
throw error::AronException(__PRETTY_FUNCTION__, "The NDArray must have two dimensions.", nav->getPath());
throw error::AronException(__PRETTY_FUNCTION__, "Last dimension of the array has to match the element size.", nav.getPath());
}
if (dims.at(1) != sizeof(T))
const int one_row_size = dims.at(1) * dims.at(2);
std::vector<std::vector<T>> v(dims.at(0));
for (int i = 0; i < dims.at(0); i++)
{
throw error::AronException(__PRETTY_FUNCTION__, "Dimension 1 of the array has to match the element size.", nav->getPath());
v[i] = convert_to_1d_vector<T>(nav.getData(), dims.at(1), i * one_row_size, one_row_size);
}
const int size = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<>());
return v;
}
template<typename T>
static std::vector<std::vector<T>> ConvertTo2DVector(const data::NDArrayPtr& nav)
{
ARMARX_CHECK_NOT_NULL(nav);
std::vector<T> v(dims.at(0));
memcpy(v.data(), nav->getData(), size);
return ConvertTo2DVector<T>(*nav);
}
template<typename T>
static std::vector<T> ConvertTo1DVector(const data::NDArray& nav, const bool allowFlatten = false)
{
const auto& dims = nav.getShape();
if (!allowFlatten && dims.size() != 2)
{
throw error::AronException(__PRETTY_FUNCTION__, "The NDArray must have 2 dimensions.", nav.getPath());
}
if (dims.at(dims.size()-1) != sizeof(T))
{
throw error::AronException(__PRETTY_FUNCTION__, "Last dimension of the array has to match the element size.", nav.getPath());
}
ARMARX_CHECK(dims.size() >= 1);
const int elements = std::accumulate(std::begin(dims), std::prev(std::end(dims)), 1, std::multiplies<>());
const int all_size = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<>());
std::vector<T> v = convert_to_1d_vector<T>(nav.getData(), elements, 0, all_size);
return v;
}
template<typename T>
static std::vector<T> ConvertTo1DVector(const data::NDArrayPtr& nav, const bool allowFlatten = false)
{
ARMARX_CHECK_NOT_NULL(nav);
return ConvertTo1DVector<T>(*nav, allowFlatten);
}
// alias
template<typename T>
static data::NDArrayPtr ConvertFromVector(const std::vector<T>& data)
static std::vector<T> ConvertToVector(const data::NDArrayPtr& nav, const bool allowFlatten = false)
{
return ConvertTo1DVector<T>(nav, allowFlatten);
}
// Attention: If a vector was flattened, the reconstruction is flattened as well!
template<typename T>
static data::NDArrayPtr ConvertFrom1DVector(const std::vector<T>& data)
{
data::NDArrayPtr ndArr(new data::NDArray);
......@@ -77,6 +137,13 @@ namespace armarx::aron::converter
return ndArr;
}
// alias
template<typename T>
static data::NDArrayPtr ConvertFromVector(const std::vector<T>& data)
{
return ConvertFrom1DVector<T>(data);
}
};
} // namespace armarx::aron::converter
......@@ -28,18 +28,19 @@ namespace armarx::aron::converter
j = aron::type::readAndWrite<type::FromVariantConverter<type::writer::NlohmannJSONWriter>>(aron);
}
data::DictPtr AronNlohmannJSONConverter::ConvertFromNlohmannJSONObject(const nlohmann::json& j)
data::DictPtr AronNlohmannJSONConverter::ConvertFromNlohmannJSONObject(const nlohmann::json& j, const armarx::aron::Path& p)
{
// TODO Switch case over json type and add other methods, e.g. for float, array, ...
// TODO add check if json is object_t
data::VariantPtr aron = std::make_shared<aron::data::Dict>();
data::VariantPtr aron = std::make_shared<aron::data::Dict>(p);
ConvertFromNlohmannJSON(aron, j);
return data::Dict::DynamicCastAndCheck(aron);
}
type::ObjectPtr AronNlohmannJSONConverter::ConvertFromNlohmannJSONTypeObject(const nlohmann::json& j)
type::ObjectPtr AronNlohmannJSONConverter::ConvertFromNlohmannJSONTypeObject(const nlohmann::json& j, const armarx::aron::Path& p)
{
type::VariantPtr aron = std::make_shared<aron::type::Object>("foo"); // foo is just a placeholder
type::ObjectPtr foo = std::make_shared<aron::type::Object>("foo"); // foo is just a placeholder
type::VariantPtr aron = std::make_shared<aron::type::Object>(*foo, p);
ConvertFromNlohmannJSON(aron, j);
return type::Object::DynamicCastAndCheck(aron);
}
......
......@@ -38,10 +38,10 @@ namespace armarx::aron::converter
static nlohmann::json ConvertToNlohmannJSON(const type::VariantPtr&);
static void ConvertToNlohmannJSON(const type::VariantPtr&, nlohmann::json&);
static data::DictPtr ConvertFromNlohmannJSONObject(const nlohmann::json&);
static data::DictPtr ConvertFromNlohmannJSONObject(const nlohmann::json&, const armarx::aron::Path& p = {});
static void ConvertFromNlohmannJSON(data::VariantPtr&, const nlohmann::json&, const aron::type::VariantPtr& = nullptr);
static type::ObjectPtr ConvertFromNlohmannJSONTypeObject(const nlohmann::json& j);
static type::ObjectPtr ConvertFromNlohmannJSONTypeObject(const nlohmann::json& j, const armarx::aron::Path& p = {});
static void ConvertFromNlohmannJSON(aron::type::VariantPtr& a, const nlohmann::json& e);
};
}
......@@ -45,7 +45,7 @@ namespace armarx::aron::converter
return ret;
}
data::NDArrayPtr AronOpenCVConverter::ConvertFromMat(const cv::Mat& mat)
data::NDArrayPtr AronOpenCVConverter::ConvertFromMat(const cv::Mat& mat, const armarx::aron::Path& p)
{
std::vector<int> dims;
for (int i = 0; i < mat.dims; ++i)
......@@ -54,7 +54,7 @@ namespace armarx::aron::converter
}
dims.push_back(mat.elemSize());
auto ret = std::make_shared<data::NDArray>();
auto ret = std::make_shared<data::NDArray>(p);
ret->setShape(dims);
ret->setType(std::to_string(mat.type()));
ret->setData(std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()), reinterpret_cast<const unsigned char*>(mat.data));
......
......@@ -41,7 +41,7 @@ namespace armarx::aron::converter
public:
static cv::Mat ConvertToMat(const data::NDArrayPtr&);
static data::NDArrayPtr ConvertFromMat(const cv::Mat&);
static data::NDArrayPtr ConvertFromMat(const cv::Mat&, const armarx::aron::Path& = {});
};
}
......@@ -107,6 +107,8 @@ set(LIB_HEADERS
Path.h
codegeneration/cpp/AronGeneratedClass.h
codegeneration/cpp/AronGeneratedObject.h
codegeneration/cpp/AronGeneratedIntEnum.h
aron_conversions.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>;
}
......@@ -80,6 +80,16 @@ namespace armarx::aron::type
return "armarx::aron::type::Dict<" + acceptedType->getFullName() + ">";
}
std::string Dict::GetFullNamePrefix()
{
return "armarx::aron::type::Dict";
}
std::string Dict::GetNamePrefix()
{
return "Dict";
}
VariantPtr Dict::navigateAbsolute(const Path& path) const
{
if (!path.hasElement())
......
......@@ -59,6 +59,9 @@ namespace armarx::aron::type
std::vector<VariantPtr> getChildren() const override;
size_t childrenSize() const override;
static std::string GetFullNamePrefix();
static std::string GetNamePrefix();
private:
// members
VariantPtr acceptedType;
......
......@@ -80,6 +80,16 @@ namespace armarx::aron::type
return "armarx::aron::type::List<" + acceptedType->getFullName() + ">";
}
std::string List::GetFullNamePrefix()
{
return "armarx::aron::type::List";
}
std::string List::GetNamePrefix()
{
return "List";
}
VariantPtr List::navigateAbsolute(const Path& path) const
{
if (!path.hasElement())
......
......@@ -58,6 +58,9 @@ namespace armarx::aron::type
std::vector<VariantPtr> getChildren() const override;
size_t childrenSize() const override;
static std::string GetFullNamePrefix();
static std::string GetNamePrefix();
private:
// members
VariantPtr acceptedType;
......