mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-12 18:40:28 +01:00
add front and back (#269)
* add front and back i'll get the last message in some situations,but have to do like this : ``` multimsg msgs; auto msg = msgs[msgs.size() - 1]; func(msg.size()); auto *msg = msgs.end() - 1; ``` but, std::queue have some method 'front' and 'back'. so maybe i can simply do this ? : ``` multimsg msgs; auto msg = msgs.back(); ``` * add test for front and back
This commit is contained in:
parent
1547b6ec22
commit
5af24314c3
@ -75,6 +75,14 @@ TEST(multipart, legacy_test)
|
||||
multipart.pushmem("Frame0", 6);
|
||||
assert(multipart.size() == 10);
|
||||
|
||||
const message_t& front_msg = multipart.front();
|
||||
assert(multipart.size() == 10);
|
||||
assert(std::string(front_msg.data<char>(), front_msg.size()) == "Frame0");
|
||||
|
||||
const message_t& back_msg = multipart.back();
|
||||
assert(multipart.size() == 10);
|
||||
assert(std::string(back_msg.data<char>(), back_msg.size()) == "Frame9");
|
||||
|
||||
msg = multipart.remove();
|
||||
assert(multipart.size() == 9);
|
||||
assert(std::string(msg.data<char>(), msg.size()) == "Frame9");
|
||||
|
@ -246,6 +246,18 @@ class multipart_t
|
||||
return message;
|
||||
}
|
||||
|
||||
// get message part from front
|
||||
const message_t &front()
|
||||
{
|
||||
return m_parts.front();
|
||||
}
|
||||
|
||||
// get message part from back
|
||||
const message_t &back()
|
||||
{
|
||||
return m_parts.back();
|
||||
}
|
||||
|
||||
// Get pointer to a specific message part
|
||||
const message_t *peek(size_t index) const { return &m_parts[index]; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user