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

#include "fakeposting.h"
#include <map>
#include <vector>
#include <string>

namespace search::index { class Schema; }

namespace search::fakedata {

class FakeWord;
class FakeWordSet;

class FPFactory
{
public:
    virtual
    ~FPFactory();

    virtual FakePosting::SP
    make(const FakeWord &fw) = 0;

    virtual void
    setup(const FakeWordSet &fws);

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

template<class P>
class FPFactoryT : public FPFactory
{
public:
    FPFactoryT(const index::Schema &schema)
        : FPFactory()
    {
        (void) schema;
    }

    FakePosting::SP make(const FakeWord &fw) override {
        return FakePosting::SP(new P(fw));
    }
};

typedef FPFactory *(FPFactoryMaker)(const index::Schema &schema);

using FPFactoryMapEntry = std::pair<const std::string, FPFactoryMaker *const>;

template <class F>
static FPFactory *
makeFPFactory(const index::Schema &schema)
{
    return new F(schema);
}

FPFactory *
getFPFactory(const std::string &name, const index::Schema &schema);

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

class FPFactoryInit
{
    std::string _key;
public:
    FPFactoryInit(const FPFactoryMapEntry &fpFactoryMapEntry);

    ~FPFactoryInit();

    static void
    forceLink();
};

}