aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/test/fakedata/fpfactory.cpp
blob: 150d8a3af325a4fca245b1bf0b0602e849f144a8 (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
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "fpfactory.h"
#include "fakeegcompr64filterocc.h"
#include "fakefilterocc.h"
#include "fakezcbfilterocc.h"
#include "fakezcfilterocc.h"
#include "fakememtreeocc.h"
#include "fakewordset.h"

namespace search::fakedata {

using index::Schema;

FPFactory::~FPFactory() = default;

void
FPFactory::setup(const FakeWordSet &fws)
{
    std::vector<const FakeWord *> v;

    for (const auto& words : fws.words()) {
        for (const auto& word : words) {
            v.push_back(word.get());
        }
    }
    setup(v);
}


void
FPFactory::setup(const std::vector<const FakeWord *> &fws)
{
    (void) fws;
}


using FPFactoryMap = std::map<const std::string, FPFactoryMaker *const>;

static FPFactoryMap *fpFactoryMap = nullptr;

/*
 * Posting list factory glue.
 */

FPFactory *
getFPFactory(const std::string &name, const Schema &schema)
{
    if (fpFactoryMap == nullptr)
        return nullptr;

    auto i = fpFactoryMap->find(name);

    if (i != fpFactoryMap->end())
        return i->second(schema);
    else
        return nullptr;
}


std::vector<std::string>
getPostingTypes()
{
    std::vector<std::string> res;

    if (fpFactoryMap != nullptr)
        for (const auto& elem : *fpFactoryMap) {
            res.push_back(elem.first);
        }
    return res;
}


FPFactoryInit::FPFactoryInit(const FPFactoryMapEntry &fpFactoryMapEntry)
    : _key(fpFactoryMapEntry.first)
{
    if (fpFactoryMap == nullptr)
        fpFactoryMap = new FPFactoryMap;
    fpFactoryMap->insert(fpFactoryMapEntry);
}

FPFactoryInit::~FPFactoryInit()
{
    assert(fpFactoryMap != nullptr);
    size_t eraseRes = fpFactoryMap->erase(_key);
    assert(eraseRes == 1);
    (void) eraseRes;
    if (fpFactoryMap->empty()) {
        delete fpFactoryMap;
        fpFactoryMap = nullptr;
    }
}

void
FPFactoryInit::forceLink()
{
    FakeEGCompr64FilterOcc::forceLink();
    FakeFilterOcc::forceLink();
    FakeZcbFilterOcc::forceLink();
    FakeZcFilterOcc::forceLink();
    FakeMemTreeOcc::forceLink();
}

}