如何在C++Actor框架中使用Eigen::Matrix4d作为消息类型



我想在CAF中使用Eigen::Matrix4d类作为消息。但我似乎写不出一个好的检查员。

错误如下:

usr/local/include/caf/write_inspector.hpp:133:7: error: static assertion failed: 
T is neither inspectable nor default-applicable

我尝试过将Matrix4d元素的内容传递给每个元素,并尝试过使用Boost(Boostrongerialization_eigen.h(的一些更精细的方法,但我总是收到同样的错误。

#include <iostream> 
#include <caf/all.hpp>
#include <Eigen/Core>
#include <Eigen/Geometry>
using namespace caf;
using namespace std;
using namespace Eigen;

CAF_BEGIN_TYPE_ID_BLOCK(custom_types, first_custom_type_id)
CAF_ADD_TYPE_ID(custom_types, (Matrix4d))
CAF_END_TYPE_ID_BLOCK(custom_types)
#include <iostream>
template <class Inspector> 
typename Inspector::result_type inspect(Inspector& f, Matrix4d& m) {
return f(m.data());
}

void caf_main(actor_system& system) {
Eigen::Matrix4d Trans; // Your Transformation Matrix
Trans.setIdentity();   // Set to Identity to make bottom row of Matrix 0,0,0,1
Trans(0, 0) = 42;
std::cout << Trans << endl;
// Spawn the actor
}
// creates a main function for us that calls our caf_main
CAF_MAIN(id_block::custom_types)

我意识到这可能是一个宽泛的问题,但任何指向正确方向的建议都值得赞赏。

(假设CAF 0.17(

检查DSL似乎并没有很好地涵盖这种特殊情况。目前CAF 0.17的最佳解决方案可能是专门处理data_processor并调用consume_range:

template <class Derived>
auto inspect(data_processor<Derived>& f, Matrix4d& x) {
auto range = make_span(x.data(), x.size());
return f.consume_range(range);
}

这不适用于CAF的自动字符串转换,但您可以根据需要提供to_string重载。

最新更新