This file is indexed.

/usr/include/x86_64-linux-gnu/qt5/UbuntuGestures/pool.h is in libubuntugestures5-gles-dev 1.3.1918+16.04.20160404-0ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright 2015 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program 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
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UBUNTUGESTURES_POOL_H
#define UBUNTUGESTURES_POOL_H

#include <QVector>

#include "ubuntugesturesglobal.h"

/*
  An object pool.
  Avoids unnecessary creations/initializations and deletions/destructions of items. Useful
  in a scenario where items are created and destroyed very frequently but the total number
  of items at any given time remains small. They're stored in a unordered fashion.

  To be used in Pool, ItemType needs to have the following methods:

  - ItemType();

  A constructor that takes no parameters. An object contructed with it must return false if
  isValid() is called.

  - bool isValid() const;

  Returns wheter the object holds a valid , "filled" state or is empty.
  Used by Pool to check if the slot occupied by this object is actually available.

  - void reset();

  Resets the object to its initial, empty, state. After calling this method, isValid() must
  return false.
 */
template <class ItemType> class Pool
{
public:
    Pool() : m_lastUsedIndex(-1) {
    }

    class Iterator {
    public:
        Iterator() : index(-1), item(nullptr) {}
        Iterator(int index, ItemType *item)
            : index(index), item(item) {}

        ItemType *operator->() const { return item; }
        ItemType &operator*() const { return *item; }
        ItemType &value() const { return *item; }

        Iterator &operator= (const Iterator& other) {
            index = other.index;
            item = other.item;

            // by convention, always return *this
            return *this;
        }

        operator bool() const { return item != nullptr; }

        int index;
        ItemType *item;
    };

    ItemType &getEmptySlot() {
        Q_ASSERT(m_lastUsedIndex < m_slots.size());

        // Look for an in-between vacancy first
        for (int i = 0; i < m_lastUsedIndex; ++i) {
            ItemType &item = m_slots[i];
            if (!item.isValid()) {
                return item;
            }
        }

        ++m_lastUsedIndex;
        if (m_lastUsedIndex >= m_slots.size()) {
            m_slots.resize(m_lastUsedIndex + 1);
        }

        return m_slots[m_lastUsedIndex];
    }

    void freeSlot(Iterator &iterator) {
        m_slots[iterator.index].reset();
        if (iterator.index == m_lastUsedIndex) {
            do {
                --m_lastUsedIndex;
            } while (m_lastUsedIndex >= 0 && !m_slots.at(m_lastUsedIndex).isValid());
        }
    }

    // Iterates through all valid items (i.e. the occupied slots)
    // calling the given function, with the option of ending the loop early.
    //
    // bool Func(Iterator& item)
    //
    // Returning true means it wants to continue the "for" loop, false
    // terminates the loop.
    template<typename Func> void forEach(Func func) {
        Iterator it;
        for (it.index = 0; it.index <= m_lastUsedIndex; ++it.index) {
            it.item = &m_slots[it.index];
            if (!it.item->isValid())
                continue;

            if (!func(it))
                break;
        }
    }

    bool isEmpty() const { return m_lastUsedIndex == -1; }


private:
    QVector<ItemType> m_slots;
    int m_lastUsedIndex;
};

#endif // UBUNTUGESTURES_POOL_H