diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/array.hpp (renamed from src/yarray.hpp) | 66 | ||||
-rw-r--r-- | src/ctx.hpp | 4 | ||||
-rw-r--r-- | src/fq.hpp | 4 | ||||
-rw-r--r-- | src/lb.hpp | 4 | ||||
-rw-r--r-- | src/pipe.hpp | 6 | ||||
-rw-r--r-- | src/pub.hpp | 4 | ||||
-rw-r--r-- | src/socket_base.hpp | 4 | ||||
-rw-r--r-- | src/yarray_item.hpp | 64 |
9 files changed, 65 insertions, 94 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ad05a4b..86a6fbd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,6 +50,7 @@ endif nodist_libzmq_la_SOURCES = $(pgm_sources) libzmq_la_SOURCES = \ + array.hpp \ atomic_counter.hpp \ atomic_ptr.hpp \ blob.hpp \ @@ -115,8 +116,6 @@ libzmq_la_SOURCES = \ wire.hpp \ xrep.hpp \ xreq.hpp \ - yarray.hpp \ - yarray_item.hpp \ ypipe.hpp \ yqueue.hpp \ zmq_connecter.hpp \ diff --git a/src/yarray.hpp b/src/array.hpp index 8c79b99..a144049 100644 --- a/src/yarray.hpp +++ b/src/array.hpp @@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __ZMQ_YARRAY_INCLUDED__ -#define __ZMQ_YARRAY_INCLUDED__ +#ifndef __ZMQ_ARRAY_INCLUDED__ +#define __ZMQ_ARRAY_INCLUDED__ #include <vector> #include <algorithm> @@ -26,21 +26,57 @@ namespace zmq { + // Base class for objects stored in the array. Note that each object can + // be stored in at most one array. + + class array_item_t + { + public: + + inline array_item_t () : + array_index (-1) + { + } + + // The destructor doesn't have to be virtual. It is mad virtual + // just to keep ICC and code checking tools from complaining. + inline virtual ~array_item_t () + { + } + + inline void set_array_index (int index_) + { + array_index = index_; + } + + inline int get_array_index () + { + return array_index; + } + + private: + + int array_index; + + array_item_t (const array_item_t&); + void operator = (const array_item_t&); + }; + // Fast array implementation with O(1) access to item, insertion and - // removal. Yarray stores pointers rather than objects. The objects have - // to be derived from yarray_item_t class. + // removal. Array stores pointers rather than objects. The objects have + // to be derived from array_item_t class. - template <typename T> class yarray_t + template <typename T> class array_t { public: typedef typename std::vector <T*>::size_type size_type; - inline yarray_t () + inline array_t () { } - inline ~yarray_t () + inline ~array_t () { } @@ -62,17 +98,17 @@ namespace zmq inline void push_back (T *item_) { if (item_) - item_->set_yarray_index (items.size ()); + item_->set_array_index (items.size ()); items.push_back (item_); } inline void erase (T *item_) { - erase (item_->get_yarray_index ()); + erase (item_->get_array_index ()); } inline void erase (size_type index_) { if (items.back ()) - items.back ()->set_yarray_index (index_); + items.back ()->set_array_index (index_); items [index_] = items.back (); items.pop_back (); } @@ -80,9 +116,9 @@ namespace zmq inline void swap (size_type index1_, size_type index2_) { if (items [index1_]) - items [index1_]->set_yarray_index (index2_); + items [index1_]->set_array_index (index2_); if (items [index2_]) - items [index2_]->set_yarray_index (index1_); + items [index2_]->set_array_index (index1_); std::swap (items [index1_], items [index2_]); } @@ -93,7 +129,7 @@ namespace zmq inline size_type index (T *item_) { - return (size_type) item_->get_yarray_index (); + return (size_type) item_->get_array_index (); } private: @@ -101,8 +137,8 @@ namespace zmq typedef std::vector <T*> items_t; items_t items; - yarray_t (const yarray_t&); - void operator = (const yarray_t&); + array_t (const array_t&); + void operator = (const array_t&); }; } diff --git a/src/ctx.hpp b/src/ctx.hpp index 2394c70..a31e1d8 100644 --- a/src/ctx.hpp +++ b/src/ctx.hpp @@ -27,7 +27,7 @@ #include "signaler.hpp" #include "semaphore.hpp" #include "ypipe.hpp" -#include "yarray.hpp" +#include "array.hpp" #include "config.hpp" #include "mutex.hpp" #include "stdint.hpp" @@ -79,7 +79,7 @@ namespace zmq ~ctx_t (); // Sockets belonging to this context. - typedef yarray_t <socket_base_t> sockets_t; + typedef array_t <socket_base_t> sockets_t; sockets_t sockets; // List of sockets that were already closed but not yet deallocated. @@ -20,7 +20,7 @@ #ifndef __ZMQ_FQ_HPP_INCLUDED__ #define __ZMQ_FQ_HPP_INCLUDED__ -#include "yarray.hpp" +#include "array.hpp" #include "pipe.hpp" namespace zmq @@ -49,7 +49,7 @@ namespace zmq private: // Inbound pipes. - typedef yarray_t <reader_t> pipes_t; + typedef array_t <reader_t> pipes_t; pipes_t pipes; // Number of active pipes. All the active pipes are located at the @@ -20,7 +20,7 @@ #ifndef __ZMQ_LB_HPP_INCLUDED__ #define __ZMQ_LB_HPP_INCLUDED__ -#include "yarray.hpp" +#include "array.hpp" #include "pipe.hpp" namespace zmq @@ -47,7 +47,7 @@ namespace zmq private: // List of outbound pipes. - typedef yarray_t <class writer_t> pipes_t; + typedef array_t <class writer_t> pipes_t; pipes_t pipes; // Number of active pipes. All the active pipes are located at the diff --git a/src/pipe.hpp b/src/pipe.hpp index d85f9dc..402efc1 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -23,7 +23,7 @@ #include "../include/zmq.h" #include "stdint.hpp" -#include "yarray_item.hpp" +#include "array.hpp" #include "ypipe.hpp" #include "swap.hpp" #include "config.hpp" @@ -52,7 +52,7 @@ namespace zmq virtual void activated (class reader_t *pipe_) = 0; }; - class reader_t : public object_t, public yarray_item_t + class reader_t : public object_t, public array_item_t { friend void zmq::create_pipe (object_t*, object_t*, uint64_t, int64_t, reader_t**, writer_t**); @@ -119,7 +119,7 @@ namespace zmq virtual void activated (class writer_t *pipe_) = 0; }; - class writer_t : public object_t, public yarray_item_t + class writer_t : public object_t, public array_item_t { friend void zmq::create_pipe (object_t*, object_t*, uint64_t, int64_t, reader_t**, writer_t**); diff --git a/src/pub.hpp b/src/pub.hpp index edc9b53..8ff192e 100644 --- a/src/pub.hpp +++ b/src/pub.hpp @@ -21,7 +21,7 @@ #define __ZMQ_PUB_HPP_INCLUDED__ #include "socket_base.hpp" -#include "yarray.hpp" +#include "array.hpp" #include "pipe.hpp" namespace zmq @@ -54,7 +54,7 @@ namespace zmq bool write (class writer_t *pipe_, zmq_msg_t *msg_); // Outbound pipes, i.e. those the socket is sending messages to. - typedef yarray_t <class writer_t> pipes_t; + typedef array_t <class writer_t> pipes_t; pipes_t pipes; // Number of active pipes. All the active pipes are located at the diff --git a/src/socket_base.hpp b/src/socket_base.hpp index ce40d3f..1a7f9f0 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -26,7 +26,7 @@ #include "../include/zmq.h" #include "own.hpp" -#include "yarray_item.hpp" +#include "array.hpp" #include "mutex.hpp" #include "options.hpp" #include "stdint.hpp" @@ -41,7 +41,7 @@ namespace zmq class socket_base_t : public own_t, - public yarray_item_t + public array_item_t { public: diff --git a/src/yarray_item.hpp b/src/yarray_item.hpp deleted file mode 100644 index db24dda..0000000 --- a/src/yarray_item.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright (c) 2007-2010 iMatix Corporation - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the Lesser GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - Lesser GNU General Public License for more details. - - You should have received a copy of the Lesser GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ZMQ_YARRAY_ITEM_INCLUDED__ -#define __ZMQ_YARRAY_ITEM_INCLUDED__ - -namespace zmq -{ - - // Base class for objects stored in yarray. Note that each object can - // be stored in at most one yarray. - - class yarray_item_t - { - public: - - inline yarray_item_t () : - yarray_index (-1) - { - } - - // The destructor doesn't have to be virtual. It is mad virtual - // just to keep ICC and code checking tools from complaining. - inline virtual ~yarray_item_t () - { - } - - inline void set_yarray_index (int index_) - { - yarray_index = index_; - } - - inline int get_yarray_index () - { - return yarray_index; - } - - private: - - int yarray_index; - - yarray_item_t (const yarray_item_t&); - void operator = (const yarray_item_t&); - }; - -} - -#endif |