Skip to content

Commit

Permalink
Added pybind functions for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktrem committed Feb 5, 2024
1 parent 841138c commit e5d0cdb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace YarpUtilities

void CreateVectorsCollectionServer(pybind11::module& module);
void CreateVectorsCollectionClient(pybind11::module& module);
void CreateVectorsCollectionMetadata(pybind11::module& module);

} // namespace YarpUtilities
} // namespace bindings
Expand Down
1 change: 1 addition & 0 deletions bindings/python/YarpUtilities/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void CreateModule(pybind11::module& module)

CreateVectorsCollectionServer(module);
CreateVectorsCollectionClient(module);
CreateVectorsCollectionMetadata(module);
}
} // namespace IK
} // namespace bindings
Expand Down
40 changes: 36 additions & 4 deletions bindings/python/YarpUtilities/src/VectorsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,52 @@ void CreateVectorsCollectionClient(pybind11::module& module)
py::arg("handler"))
.def("connect", &VectorsCollectionClient::connect)
.def("disconnect", &VectorsCollectionClient::disconnect)
.def("getMetadata",
[](VectorsCollectionClient& impl) -> std::map<std::string, std::vector<std::string>>
.def("get_metadata",
[](VectorsCollectionClient& impl) -> BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata
{
BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata metadata;
impl.getMetadata(metadata);
return metadata.vectors;
return metadata;
})
.def("readData",
.def("read_data",
[](VectorsCollectionClient& impl, bool shouldWait) -> std::map<std::string, std::vector<double>>
{
BipedalLocomotion::YarpUtilities::VectorsCollection* collection = impl.readData(shouldWait);
return collection->vectors;
});
}

void CreateVectorsCollectionMetadata(pybind11::module& module)
{
namespace py = ::pybind11;

using namespace ::BipedalLocomotion::YarpUtilities;

py::class_<VectorsCollectionMetadata>(module, "VectorsCollectionMetadata")
.def(py::init())
.def(py::init<const std::map<std::string, std::vector<std::string>>&>())
.def("readWireReader",
[](VectorsCollectionMetadata& impl, yarp::os::idl::WireReader& reader) -> bool {
return impl.read(reader);
})
.def("readConnectionReader",
[](VectorsCollectionMetadata& impl, yarp::os::ConnectionReader& connection) -> bool {
return impl.read(connection);
})
.def("writeWireWriter",
[](const VectorsCollectionMetadata& impl, const yarp::os::idl::WireWriter& writer) -> bool {
return impl.write(writer);
})
.def("writeConnectionWriter",
[](const VectorsCollectionMetadata& impl, yarp::os::ConnectionWriter& connection) -> bool {
return impl.write(connection);
})
.def("toString", &VectorsCollectionMetadata::toString)
.def("getVectors",
[](const VectorsCollectionMetadata& impl) -> std::map<std::string, std::vector<std::string>> {
return impl.vectors;
});
}
} // namespace YarpUtilities
} // namespace bindings
} // namespace BipedalLocomotion

0 comments on commit e5d0cdb

Please sign in to comment.