mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Extending FairMQParts by a constructor taking list of FairMQMessagePtr
This introduces a little helper to create a FairMQParts object in place from a variable list of arguments. As a side effect also AddParts is extended to support more than one FairMQMessagePtr.
This commit is contained in:
parent
cdc1ba084c
commit
696257fd4f
|
@ -32,15 +32,15 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-multipart.sh.in ${CMA
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-ex-multipart.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-ex-multipart.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh)
|
||||||
|
|
||||||
add_test(NAME Example.Multipart.zeromq COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh zeromq)
|
add_test(NAME Example.Multipart.zeromq COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh zeromq)
|
||||||
set_tests_properties(Example.Multipart.zeromq PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 2 parts")
|
set_tests_properties(Example.Multipart.zeromq PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 5 parts")
|
||||||
|
|
||||||
if(BUILD_NANOMSG_TRANSPORT)
|
if(BUILD_NANOMSG_TRANSPORT)
|
||||||
add_test(NAME Example.Multipart.nanomsg COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh nanomsg)
|
add_test(NAME Example.Multipart.nanomsg COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh nanomsg)
|
||||||
set_tests_properties(Example.Multipart.nanomsg PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 2 parts")
|
set_tests_properties(Example.Multipart.nanomsg PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 5 parts")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME Example.Multipart.shmem COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh shmem)
|
add_test(NAME Example.Multipart.shmem COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-multipart.sh shmem)
|
||||||
set_tests_properties(Example.Multipart.shmem PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 2 parts")
|
set_tests_properties(Example.Multipart.shmem PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Received message with 5 parts")
|
||||||
|
|
||||||
# install
|
# install
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,13 @@ bool Sampler::ConditionalRun()
|
||||||
parts.AddPart(NewSimpleMessage(header));
|
parts.AddPart(NewSimpleMessage(header));
|
||||||
parts.AddPart(NewMessage(1000));
|
parts.AddPart(NewMessage(1000));
|
||||||
|
|
||||||
|
// create more data parts, testing the FairMQParts in-place constructor
|
||||||
|
FairMQParts auxData{ NewMessage(500), NewMessage(600), NewMessage(700) };
|
||||||
|
assert(auxData.Size() == 3);
|
||||||
|
parts.AddPart(std::move(auxData));
|
||||||
|
assert(auxData.Size() == 0);
|
||||||
|
assert(parts.Size() == 5);
|
||||||
|
|
||||||
LOG(info) << "Sending body of size: " << parts.At(1)->GetSize();
|
LOG(info) << "Sending body of size: " << parts.At(1)->GetSize();
|
||||||
|
|
||||||
Send(parts, "data");
|
Send(parts, "data");
|
||||||
|
|
|
@ -31,6 +31,9 @@ class FairMQParts
|
||||||
FairMQParts(FairMQParts&& p) = default;
|
FairMQParts(FairMQParts&& p) = default;
|
||||||
/// Assignment operator
|
/// Assignment operator
|
||||||
FairMQParts& operator=(const FairMQParts&) = delete;
|
FairMQParts& operator=(const FairMQParts&) = delete;
|
||||||
|
/// Constructor from argument pack of std::unique_ptr<FairMQMessage> rvalues
|
||||||
|
template <typename... Ts>
|
||||||
|
FairMQParts(Ts&&... messages) : fParts() {AddPart(std::forward<Ts>(messages)...);}
|
||||||
/// Default destructor
|
/// Default destructor
|
||||||
~FairMQParts() {};
|
~FairMQParts() {};
|
||||||
|
|
||||||
|
@ -41,14 +44,6 @@ class FairMQParts
|
||||||
fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
|
fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds part (std::unique_ptr<FairMQMessage>&) to the container (move)
|
|
||||||
/// @param msg unique pointer to FairMQMessage
|
|
||||||
/// lvalue ref (move not required when passing argument)
|
|
||||||
// inline void AddPart(std::unique_ptr<FairMQMessage>& msg)
|
|
||||||
// {
|
|
||||||
// fParts.push_back(std::move(msg));
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// Adds part (std::unique_ptr<FairMQMessage>&) to the container (move)
|
/// Adds part (std::unique_ptr<FairMQMessage>&) to the container (move)
|
||||||
/// @param msg unique pointer to FairMQMessage
|
/// @param msg unique pointer to FairMQMessage
|
||||||
/// rvalue ref (move required when passing argument)
|
/// rvalue ref (move required when passing argument)
|
||||||
|
@ -57,6 +52,23 @@ class FairMQParts
|
||||||
fParts.push_back(std::move(msg));
|
fParts.push_back(std::move(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add variable list of parts to the container (move)
|
||||||
|
template <typename... Ts>
|
||||||
|
void AddPart(std::unique_ptr<FairMQMessage>&& first, Ts&&... remaining)
|
||||||
|
{
|
||||||
|
AddPart(std::move(first));
|
||||||
|
AddPart(std::forward<Ts>(remaining)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add content of another object by move
|
||||||
|
void AddPart(FairMQParts&& other)
|
||||||
|
{
|
||||||
|
container parts = std::move(other.fParts);
|
||||||
|
for (auto& part : parts) {
|
||||||
|
fParts.push_back(std::move(part));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get reference to part in the container at index (without bounds check)
|
/// Get reference to part in the container at index (without bounds check)
|
||||||
/// @param index container index
|
/// @param index container index
|
||||||
FairMQMessage& operator[](const int index) { return *(fParts[index]); }
|
FairMQMessage& operator[](const int index) { return *(fParts[index]); }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user