Problem: read-only arguments of mtrie are not declared as const

Solution: add const, introduce typedef
This commit is contained in:
Simon Giesecke 2018-02-15 12:32:10 +01:00
parent 31387f84e4
commit 9fc3692e3f
4 changed files with 31 additions and 34 deletions

View File

@ -57,14 +57,12 @@ zmq::mtrie_t::~mtrie_t ()
}
}
bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_)
bool zmq::mtrie_t::add (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{
return add_helper (prefix_, size_, pipe_);
}
bool zmq::mtrie_t::add_helper (unsigned char *prefix_,
size_t size_,
pipe_t *pipe_)
bool zmq::mtrie_t::add_helper (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{
// We are at the node corresponding to the prefix. We are done.
if (!size_) {
@ -139,9 +137,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_,
void zmq::mtrie_t::rm (pipe_t *pipe_,
void (*func_) (unsigned char *data_,
size_t size_,
void *arg_),
void (*func_) (prefix_t data_, size_t size_, void *arg_),
void *arg_,
bool call_on_uniq_)
{
@ -154,7 +150,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_,
unsigned char **buff_,
size_t buffsize_,
size_t maxbuffsize_,
void (*func_) (unsigned char *data_,
void (*func_) (prefix_t data_,
size_t size_,
void *arg_),
void *arg_,
@ -275,14 +271,12 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_,
}
}
bool zmq::mtrie_t::rm (unsigned char *prefix_, size_t size_, pipe_t *pipe_)
bool zmq::mtrie_t::rm (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{
return rm_helper (prefix_, size_, pipe_);
}
bool zmq::mtrie_t::rm_helper (unsigned char *prefix_,
size_t size_,
pipe_t *pipe_)
bool zmq::mtrie_t::rm_helper (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{
if (!size_) {
if (pipes) {
@ -372,7 +366,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_,
return ret;
}
void zmq::mtrie_t::match (unsigned char *data_,
void zmq::mtrie_t::match (prefix_t data_,
size_t size_,
void (*func_) (pipe_t *pipe_, void *arg_),
void *arg_)

View File

@ -44,43 +44,45 @@ class pipe_t;
class mtrie_t
{
public:
typedef const unsigned char *prefix_t;
mtrie_t ();
~mtrie_t ();
// Add key to the trie. Returns true if it's a new subscription
// rather than a duplicate.
bool add (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
bool add (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
// Remove all subscriptions for a specific peer from the trie.
// The call_on_uniq_ flag controls if the callback is invoked
// when there are no subscriptions left on some topics or on
// every removal.
void rm (zmq::pipe_t *pipe_,
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
void *arg_,
bool call_on_uniq_);
void
rm (zmq::pipe_t *pipe_,
void (*func_) (const unsigned char *data_, size_t size_, void *arg_),
void *arg_,
bool call_on_uniq_);
// Remove specific subscription from the trie. Return true is it was
// actually removed rather than de-duplicated.
bool rm (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
bool rm (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
// Signal all the matching pipes.
void match (unsigned char *data_,
void match (prefix_t data_,
size_t size_,
void (*func_) (zmq::pipe_t *pipe_, void *arg_),
void *arg_);
private:
bool add_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
void
rm_helper (zmq::pipe_t *pipe_,
unsigned char **buff_,
size_t buffsize_,
size_t maxbuffsize_,
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
void *arg_,
bool call_on_uniq_);
bool rm_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
bool add_helper (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
void rm_helper (zmq::pipe_t *pipe_,
unsigned char **buff_,
size_t buffsize_,
size_t maxbuffsize_,
void (*func_) (prefix_t data_, size_t size_, void *arg_),
void *arg_,
bool call_on_uniq_);
bool rm_helper (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
bool is_redundant () const;
typedef std::set<zmq::pipe_t *> pipes_t;

View File

@ -188,7 +188,7 @@ int zmq::xpub_t::xsetsockopt (int option_,
return 0;
}
static void stub (unsigned char *data_, size_t size_, void *arg_)
static void stub (zmq::mtrie_t::prefix_t data_, size_t size_, void *arg_)
{
LIBZMQ_UNUSED (data_);
LIBZMQ_UNUSED (size_);
@ -295,7 +295,7 @@ bool zmq::xpub_t::xhas_in ()
return !pending_data.empty ();
}
void zmq::xpub_t::send_unsubscription (unsigned char *data_,
void zmq::xpub_t::send_unsubscription (zmq::mtrie_t::prefix_t data_,
size_t size_,
void *arg_)
{

View File

@ -66,8 +66,9 @@ class xpub_t : public socket_base_t
private:
// Function to be applied to the trie to send all the subscriptions
// upstream.
static void
send_unsubscription (unsigned char *data_, size_t size_, void *arg_);
static void send_unsubscription (zmq::mtrie_t::prefix_t data_,
size_t size_,
void *arg_);
// Function to be applied to each matching pipes.
static void mark_as_matching (zmq::pipe_t *pipe_, void *arg_);