aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/termfieldmatchdataarray.h
blob: 46d370ee8fec61f3c8355b5f413e5f1f65994c4a (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vector>
#include <cstddef>

namespace search::fef {

class TermFieldMatchData;

/**
 * Array of pointers to TermFieldMatchData instances.
 * Use this class to pass an ordered set of references
 * into e.g. iterators searching in multiple fields at once.
 * The array must either be totally empty, or contain
 * the appropriate number of valid references.
 **/
class TermFieldMatchDataArray
{
private:
    std::vector<TermFieldMatchData *> _array;

public:
    TermFieldMatchDataArray() = default;
    TermFieldMatchDataArray(TermFieldMatchDataArray &&) noexcept = default;
    TermFieldMatchDataArray & operator = (TermFieldMatchDataArray &&) noexcept = default;
    TermFieldMatchDataArray(const TermFieldMatchDataArray&) = default;
    TermFieldMatchDataArray & operator = (const TermFieldMatchDataArray &) = delete;
    ~TermFieldMatchDataArray();
    /**
     * Reserve space for a number of elements in order to reduce number of allocations.
     * @param size Number of elements to reserve space for.
     */
    void reserve(size_t sz) {
        _array.reserve(sz);
    }
    /**
     * add a pointer to the array.
     *
     * @return this object for chaining
     * @param value the pointer to be added
     **/
    TermFieldMatchDataArray &add(TermFieldMatchData *value) {
        _array.push_back(value);
        return *this;
    }

    /**
     * check that the array contains valid references.
     *
     * @return true if array not empty
     **/
    bool valid() const { return !_array.empty(); }

    /**
     * size of the array.
     *
     * @return the size
     **/
    size_t size() const { return _array.size(); }

    /**
     * get a pointer from the array.
     *
     * @return the pointer
     * @param i index of the pointer
     **/
    TermFieldMatchData *operator[] (size_t i) const {
        return _array[i];
    }
};

}