From 090e460d6f09b5611d34a4867efb6cf46dd44a34 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Tue, 31 Aug 2010 21:03:34 +0200 Subject: naming cleanup: yarray->array --- src/Makefile.am | 3 +- src/array.hpp | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctx.hpp | 4 +- src/fq.hpp | 4 +- src/lb.hpp | 4 +- src/pipe.hpp | 6 +-- src/pub.hpp | 4 +- src/socket_base.hpp | 4 +- src/yarray.hpp | 110 --------------------------------------- src/yarray_item.hpp | 64 ----------------------- 10 files changed, 160 insertions(+), 189 deletions(-) create mode 100644 src/array.hpp delete mode 100644 src/yarray.hpp delete mode 100644 src/yarray_item.hpp (limited to 'src') 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/array.hpp b/src/array.hpp new file mode 100644 index 0000000..a144049 --- /dev/null +++ b/src/array.hpp @@ -0,0 +1,146 @@ +/* + 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 . +*/ + +#ifndef __ZMQ_ARRAY_INCLUDED__ +#define __ZMQ_ARRAY_INCLUDED__ + +#include +#include + +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. Array stores pointers rather than objects. The objects have + // to be derived from array_item_t class. + + template class array_t + { + public: + + typedef typename std::vector ::size_type size_type; + + inline array_t () + { + } + + inline ~array_t () + { + } + + inline size_type size () + { + return items.size (); + } + + inline bool empty () + { + return items.empty (); + } + + inline T *&operator [] (size_type index_) + { + return items [index_]; + } + + inline void push_back (T *item_) + { + if (item_) + item_->set_array_index (items.size ()); + items.push_back (item_); + } + + inline void erase (T *item_) { + erase (item_->get_array_index ()); + } + + inline void erase (size_type index_) { + if (items.back ()) + items.back ()->set_array_index (index_); + items [index_] = items.back (); + items.pop_back (); + } + + inline void swap (size_type index1_, size_type index2_) + { + if (items [index1_]) + items [index1_]->set_array_index (index2_); + if (items [index2_]) + items [index2_]->set_array_index (index1_); + std::swap (items [index1_], items [index2_]); + } + + inline void clear () + { + items.clear (); + } + + inline size_type index (T *item_) + { + return (size_type) item_->get_array_index (); + } + + private: + + typedef std::vector items_t; + items_t items; + + array_t (const array_t&); + void operator = (const array_t&); + }; + +} + +#endif 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 sockets_t; + typedef array_t sockets_t; sockets_t sockets; // List of sockets that were already closed but not yet deallocated. diff --git a/src/fq.hpp b/src/fq.hpp index 97e9469..fd853d8 100644 --- a/src/fq.hpp +++ b/src/fq.hpp @@ -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 pipes_t; + typedef array_t pipes_t; pipes_t pipes; // Number of active pipes. All the active pipes are located at the diff --git a/src/lb.hpp b/src/lb.hpp index cb2ce72..ea965f8 100644 --- a/src/lb.hpp +++ b/src/lb.hpp @@ -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 pipes_t; + typedef array_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 pipes_t; + typedef array_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.hpp b/src/yarray.hpp deleted file mode 100644 index 8c79b99..0000000 --- a/src/yarray.hpp +++ /dev/null @@ -1,110 +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 . -*/ - -#ifndef __ZMQ_YARRAY_INCLUDED__ -#define __ZMQ_YARRAY_INCLUDED__ - -#include -#include - -namespace zmq -{ - - // 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. - - template class yarray_t - { - public: - - typedef typename std::vector ::size_type size_type; - - inline yarray_t () - { - } - - inline ~yarray_t () - { - } - - inline size_type size () - { - return items.size (); - } - - inline bool empty () - { - return items.empty (); - } - - inline T *&operator [] (size_type index_) - { - return items [index_]; - } - - inline void push_back (T *item_) - { - if (item_) - item_->set_yarray_index (items.size ()); - items.push_back (item_); - } - - inline void erase (T *item_) { - erase (item_->get_yarray_index ()); - } - - inline void erase (size_type index_) { - if (items.back ()) - items.back ()->set_yarray_index (index_); - items [index_] = items.back (); - items.pop_back (); - } - - inline void swap (size_type index1_, size_type index2_) - { - if (items [index1_]) - items [index1_]->set_yarray_index (index2_); - if (items [index2_]) - items [index2_]->set_yarray_index (index1_); - std::swap (items [index1_], items [index2_]); - } - - inline void clear () - { - items.clear (); - } - - inline size_type index (T *item_) - { - return (size_type) item_->get_yarray_index (); - } - - private: - - typedef std::vector items_t; - items_t items; - - yarray_t (const yarray_t&); - void operator = (const yarray_t&); - }; - -} - -#endif 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 . -*/ - -#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 -- cgit v1.2.3