0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-31 01:43:02 +08:00

naming cleanup: yarray->array

This commit is contained in:
Martin Sustrik 2010-08-31 21:03:34 +02:00
parent f5acbb5095
commit 090e460d6f
9 changed files with 66 additions and 95 deletions

View File

@ -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 \

View File

@ -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
{
// 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.
// Base class for objects stored in the array. Note that each object can
// be stored in at most one array.
template <typename T> class yarray_t
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 <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&);
};
}

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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**);

View File

@ -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

View File

@ -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:

View File

@ -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