mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-01-31 14:39:56 +01:00
Problem: non consistent whitespace formatting
* Converted tabs to to 4 spaces to be consistend with the rest of the code * Stripped white spaces from the end of lines
This commit is contained in:
parent
25196e5bb8
commit
8353e8460f
@ -8,7 +8,7 @@
|
||||
TEST(poller, create_destroy)
|
||||
{
|
||||
zmq::poller_t poller;
|
||||
ASSERT_EQ(0u, poller.size ());
|
||||
ASSERT_EQ(0u, poller.size ());
|
||||
}
|
||||
|
||||
static_assert(!std::is_copy_constructible<zmq::poller_t>::value, "poller_t should not be copy-constructible");
|
||||
@ -16,24 +16,24 @@ static_assert(!std::is_copy_assignable<zmq::poller_t>::value, "poller_t should n
|
||||
|
||||
TEST(poller, move_construct_empty)
|
||||
{
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
zmq::poller_t b = std::move(*a);
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
zmq::poller_t b = std::move(*a);
|
||||
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(0u, b.size ());
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(0u, b.size ());
|
||||
}
|
||||
|
||||
TEST(poller, move_assign_empty)
|
||||
{
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
zmq::poller_t b;
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
zmq::poller_t b;
|
||||
|
||||
b = std::move(*a);
|
||||
b = std::move(*a);
|
||||
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(0u, b.size ());
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(0u, b.size ());
|
||||
}
|
||||
|
||||
TEST(poller, move_construct_non_empty)
|
||||
@ -41,13 +41,13 @@ TEST(poller, move_construct_non_empty)
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket{context, zmq::socket_type::router};
|
||||
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
a->add(socket, ZMQ_POLLIN, [](short) {});
|
||||
zmq::poller_t b = std::move(*a);
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
a->add(socket, ZMQ_POLLIN, [](short) {});
|
||||
zmq::poller_t b = std::move(*a);
|
||||
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(1u, b.size ());
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(1u, b.size ());
|
||||
}
|
||||
|
||||
TEST(poller, move_assign_non_empty)
|
||||
@ -55,15 +55,15 @@ TEST(poller, move_assign_non_empty)
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket{context, zmq::socket_type::router};
|
||||
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
a->add(socket, ZMQ_POLLIN, [](short) {});
|
||||
zmq::poller_t b;
|
||||
std::unique_ptr<zmq::poller_t> a{new zmq::poller_t};
|
||||
a->add(socket, ZMQ_POLLIN, [](short) {});
|
||||
zmq::poller_t b;
|
||||
|
||||
b = std::move(*a);
|
||||
b = std::move(*a);
|
||||
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(1u, b.size ());
|
||||
ASSERT_EQ(0u, a->size ());
|
||||
a.reset ();
|
||||
ASSERT_EQ(1u, b.size ());
|
||||
}
|
||||
|
||||
TEST(poller, add_handler)
|
||||
@ -92,14 +92,14 @@ TEST(poller, add_handler_twice_throws)
|
||||
zmq::poller_t poller;
|
||||
zmq::poller_t::handler_t handler;
|
||||
poller.add(socket, ZMQ_POLLIN, handler);
|
||||
/// \todo the actual error code should be checked
|
||||
/// \todo the actual error code should be checked
|
||||
ASSERT_THROW(poller.add(socket, ZMQ_POLLIN, handler), zmq::error_t);
|
||||
}
|
||||
|
||||
TEST(poller, wait_with_no_handlers_throws)
|
||||
{
|
||||
zmq::poller_t poller;
|
||||
/// \todo the actual error code should be checked
|
||||
/// \todo the actual error code should be checked
|
||||
ASSERT_THROW(poller.wait(std::chrono::milliseconds{10}), zmq::error_t);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ TEST(poller, remove_unregistered_throws)
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket{context, zmq::socket_type::router};
|
||||
zmq::poller_t poller;
|
||||
/// \todo the actual error code should be checked
|
||||
/// \todo the actual error code should be checked
|
||||
ASSERT_THROW(poller.remove(socket), zmq::error_t);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ TEST(poller, remove_registered_non_empty)
|
||||
{
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket{context, zmq::socket_type::router};
|
||||
zmq::poller_t poller;
|
||||
zmq::poller_t poller;
|
||||
poller.add(socket, ZMQ_POLLIN, [](short) {});
|
||||
ASSERT_NO_THROW(poller.remove(socket));
|
||||
}
|
||||
|
42
zmq.hpp
42
zmq.hpp
@ -32,7 +32,7 @@
|
||||
#define ZMQ_DEPRECATED(msg) __declspec(deprecated(msg))
|
||||
#elif defined(__GNUC__)
|
||||
#define ZMQ_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201103L)
|
||||
#define ZMQ_CPP11
|
||||
@ -1030,20 +1030,20 @@ namespace zmq
|
||||
|
||||
using handler_t = std::function<void(short)>;
|
||||
|
||||
ZMQ_DEPRECATED("from 4.3.0, use overload accepting handler_t instead")
|
||||
ZMQ_DEPRECATED("from 4.3.0, use overload accepting handler_t instead")
|
||||
void add (zmq::socket_t &socket, short events, std::function<void(void)> &handler)
|
||||
{
|
||||
add (socket, events, [&handler](short) { handler(); });
|
||||
}
|
||||
add (socket, events, [&handler](short) { handler(); });
|
||||
}
|
||||
|
||||
void add (zmq::socket_t &socket, short events, handler_t handler)
|
||||
{
|
||||
handler_t *handler_ptr = nullptr;
|
||||
/// \todo is it sensible to allow handler to be empty? doesn't this lead to an error when the event is signalled? (perhaps it should already lead to an error in zmq_poller_add then)
|
||||
if (handler) {
|
||||
auto emplace_res = handlers.emplace(&socket, std::move(handler));
|
||||
handler_ptr = &emplace_res.first->second;
|
||||
}
|
||||
handler_t *handler_ptr = nullptr;
|
||||
/// \todo is it sensible to allow handler to be empty? doesn't this lead to an error when the event is signalled? (perhaps it should already lead to an error in zmq_poller_add then)
|
||||
if (handler) {
|
||||
auto emplace_res = handlers.emplace(&socket, std::move(handler));
|
||||
handler_ptr = &emplace_res.first->second;
|
||||
}
|
||||
if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler_ptr, events)) {
|
||||
poller_events.emplace_back (zmq_poller_event_t ());
|
||||
return;
|
||||
@ -1054,11 +1054,11 @@ namespace zmq
|
||||
void remove (zmq::socket_t &socket)
|
||||
{
|
||||
if (0 == zmq_poller_remove (poller_ptr, socket.ptr)) {
|
||||
auto it = handlers.find (&socket);
|
||||
if (it != handlers.end ()) { /// \todo this may only be false if handler was empty on add
|
||||
handlers.erase (it);
|
||||
}
|
||||
poller_events.pop_back ();
|
||||
auto it = handlers.find (&socket);
|
||||
if (it != handlers.end ()) { /// \todo this may only be false if handler was empty on add
|
||||
handlers.erase (it);
|
||||
}
|
||||
poller_events.pop_back ();
|
||||
return;
|
||||
}
|
||||
throw error_t ();
|
||||
@ -1084,16 +1084,16 @@ namespace zmq
|
||||
|
||||
throw error_t ();
|
||||
}
|
||||
|
||||
size_t size ()
|
||||
{
|
||||
return poller_events.size();
|
||||
}
|
||||
|
||||
size_t size ()
|
||||
{
|
||||
return poller_events.size();
|
||||
}
|
||||
|
||||
private:
|
||||
void *poller_ptr;
|
||||
std::vector<zmq_poller_event_t> poller_events;
|
||||
std::map<socket_t*, handler_t> handlers;
|
||||
std::map<socket_t*, handler_t> handlers;
|
||||
}; // class poller_t
|
||||
#endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user