Coverage Report

Created: 2026-01-10 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libzmq/src/array.hpp
Line
Count
Source
1
/* SPDX-License-Identifier: MPL-2.0 */
2
3
#ifndef __ZMQ_ARRAY_INCLUDED__
4
#define __ZMQ_ARRAY_INCLUDED__
5
6
#include <vector>
7
#include <algorithm>
8
9
#include "macros.hpp"
10
11
namespace zmq
12
{
13
//  Implementation of fast arrays with O(1) access, insertion and
14
//  removal. The array stores pointers rather than objects.
15
//  O(1) is achieved by making items inheriting from
16
//  array_item_t<ID> class which internally stores the position
17
//  in the array.
18
//  The ID template argument is used to differentiate among arrays
19
//  and thus let an object be stored in different arrays.
20
21
//  Base class for objects stored in the array. If you want to store
22
//  same object in multiple arrays, each of those arrays has to have
23
//  different ID. The item itself has to be derived from instantiations of
24
//  array_item_t template for all relevant IDs.
25
26
template <int ID = 0> class array_item_t
27
{
28
  public:
29
1.69k
    array_item_t () : _array_index (-1) {}
Unexecuted instantiation: zmq::array_item_t<1>::array_item_t()
Unexecuted instantiation: zmq::array_item_t<2>::array_item_t()
Unexecuted instantiation: zmq::array_item_t<3>::array_item_t()
zmq::array_item_t<0>::array_item_t()
Line
Count
Source
29
1.69k
    array_item_t () : _array_index (-1) {}
30
31
    //  The destructor doesn't have to be virtual. It is made virtual
32
    //  just to keep ICC and code checking tools from complaining.
33
    virtual ~array_item_t () ZMQ_DEFAULT;
34
35
3.39k
    void set_array_index (int index_) { _array_index = index_; }
zmq::array_item_t<0>::set_array_index(int)
Line
Count
Source
35
3.39k
    void set_array_index (int index_) { _array_index = index_; }
Unexecuted instantiation: zmq::array_item_t<3>::set_array_index(int)
Unexecuted instantiation: zmq::array_item_t<2>::set_array_index(int)
Unexecuted instantiation: zmq::array_item_t<1>::set_array_index(int)
36
37
1.69k
    int get_array_index () const { return _array_index; }
zmq::array_item_t<0>::get_array_index() const
Line
Count
Source
37
1.69k
    int get_array_index () const { return _array_index; }
Unexecuted instantiation: zmq::array_item_t<3>::get_array_index() const
Unexecuted instantiation: zmq::array_item_t<2>::get_array_index() const
Unexecuted instantiation: zmq::array_item_t<1>::get_array_index() const
38
39
  private:
40
    int _array_index;
41
42
    ZMQ_NON_COPYABLE_NOR_MOVABLE (array_item_t)
43
};
44
45
46
template <typename T, int ID = 0> class array_t
47
{
48
  private:
49
    typedef array_item_t<ID> item_t;
50
51
  public:
52
    typedef typename std::vector<T *>::size_type size_type;
53
54
    array_t () ZMQ_DEFAULT;
55
56
5.09k
    size_type size () { return _items.size (); }
zmq::array_t<zmq::socket_base_t, 0>::size()
Line
Count
Source
56
1.69k
    size_type size () { return _items.size (); }
zmq::array_t<zmq::pipe_t, 3>::size()
Line
Count
Source
56
3.39k
    size_type size () { return _items.size (); }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::size()
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::size()
57
58
8.48k
    bool empty () { return _items.empty (); }
zmq::array_t<zmq::socket_base_t, 0>::empty()
Line
Count
Source
58
6.79k
    bool empty () { return _items.empty (); }
zmq::array_t<zmq::pipe_t, 2>::empty()
Line
Count
Source
58
1.69k
    bool empty () { return _items.empty (); }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::empty()
59
60
1.69k
    T *&operator[] (size_type index_) { return _items[index_]; }
zmq::array_t<zmq::socket_base_t, 0>::operator[](unsigned long)
Line
Count
Source
60
1.69k
    T *&operator[] (size_type index_) { return _items[index_]; }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 3>::operator[](unsigned long)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::operator[](unsigned long)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::operator[](unsigned long)
61
62
    void push_back (T *item_)
63
1.69k
    {
64
1.69k
        if (item_)
65
1.69k
            static_cast<item_t *> (item_)->set_array_index (
66
1.69k
              static_cast<int> (_items.size ()));
67
1.69k
        _items.push_back (item_);
68
1.69k
    }
zmq::array_t<zmq::socket_base_t, 0>::push_back(zmq::socket_base_t*)
Line
Count
Source
63
1.69k
    {
64
1.69k
        if (item_)
65
1.69k
            static_cast<item_t *> (item_)->set_array_index (
66
1.69k
              static_cast<int> (_items.size ()));
67
1.69k
        _items.push_back (item_);
68
1.69k
    }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 3>::push_back(zmq::pipe_t*)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::push_back(zmq::pipe_t*)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::push_back(zmq::pipe_t*)
69
70
    void erase (T *item_)
71
1.69k
    {
72
1.69k
        erase (static_cast<item_t *> (item_)->get_array_index ());
73
1.69k
    }
zmq::array_t<zmq::socket_base_t, 0>::erase(zmq::socket_base_t*)
Line
Count
Source
71
1.69k
    {
72
1.69k
        erase (static_cast<item_t *> (item_)->get_array_index ());
73
1.69k
    }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 3>::erase(zmq::pipe_t*)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::erase(zmq::pipe_t*)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::erase(zmq::pipe_t*)
74
75
    void erase (size_type index_)
76
1.69k
    {
77
1.69k
        if (_items.empty ())
78
0
            return;
79
1.69k
        static_cast<item_t *> (_items.back ())
80
1.69k
          ->set_array_index (static_cast<int> (index_));
81
82
1.69k
        _items[index_] = _items.back ();
83
1.69k
        _items.pop_back ();
84
1.69k
    }
zmq::array_t<zmq::socket_base_t, 0>::erase(unsigned long)
Line
Count
Source
76
1.69k
    {
77
1.69k
        if (_items.empty ())
78
0
            return;
79
1.69k
        static_cast<item_t *> (_items.back ())
80
1.69k
          ->set_array_index (static_cast<int> (index_));
81
82
1.69k
        _items[index_] = _items.back ();
83
1.69k
        _items.pop_back ();
84
1.69k
    }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 3>::erase(unsigned long)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::erase(unsigned long)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::erase(unsigned long)
85
86
    void swap (size_type index1_, size_type index2_)
87
0
    {
88
0
        if (_items[index1_])
89
0
            static_cast<item_t *> (_items[index1_])
90
0
              ->set_array_index (static_cast<int> (index2_));
91
0
        if (_items[index2_])
92
0
            static_cast<item_t *> (_items[index2_])
93
0
              ->set_array_index (static_cast<int> (index1_));
94
0
        std::swap (_items[index1_], _items[index2_]);
95
0
    }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::swap(unsigned long, unsigned long)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::swap(unsigned long, unsigned long)
96
97
    void clear () { _items.clear (); }
98
99
    static size_type index (T *item_)
100
0
    {
101
0
        return static_cast<size_type> (
102
0
          static_cast<item_t *> (item_)->get_array_index ());
103
0
    }
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 2>::index(zmq::pipe_t*)
Unexecuted instantiation: zmq::array_t<zmq::pipe_t, 1>::index(zmq::pipe_t*)
104
105
  private:
106
    typedef std::vector<T *> items_t;
107
    items_t _items;
108
109
    ZMQ_NON_COPYABLE_NOR_MOVABLE (array_t)
110
};
111
}
112
113
#endif