aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/query/tree/templatetermvisitor.h
blob: cafb9a214e733cf2bec9de12204484534c309950 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "customtypetermvisitor.h"

namespace search::query {

/**
 * Use this class to visit all term nodes by deriving from this class
 * and implementing a single template member function:
 * template <class TermType> void visitTerm(TermType &n);
 *
 * This class uses the curiously recurring template pattern to know
 * its own derived class that has the visitTerm template member
 * function.
 */
template <class Self, class NodeTypes>
class TemplateTermVisitor : public CustomTypeTermVisitor<NodeTypes> {
    template <class TermNode>
    void myVisit(TermNode &n) {
        static_cast<Self &>(*this).template visitTerm(n);
    }

    void visit(typename NodeTypes::NumberTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::LocationTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::PrefixTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::RangeTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::StringTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::SubstringTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::SuffixTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::PredicateQuery &n) override { myVisit(n); }
    void visit(typename NodeTypes::RegExpTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::NearestNeighborTerm &n) override { myVisit(n); }
    void visit(typename NodeTypes::FuzzyTerm &n) override { myVisit(n); }

    // Phrases are terms with children. This visitor will not visit
    // the phrase's children, unless this member function is
    // overridden to do so.
    void visit(typename NodeTypes::Phrase &n) override { myVisit(n); }

    // WeightedSetTerms are terms with children. This visitor will not visit
    // the weighted set's children, unless this member function is
    // overridden to do so.
    void visit(typename NodeTypes::WeightedSetTerm &n) override { myVisit(n); }

    // DotProducts have children. This visitor will not visit the dot
    // product's children, unless this member function is overridden
    // to do so.
    void visit(typename NodeTypes::DotProduct &n) override { myVisit(n); }

    // WandTerms have children. This visitor will not visit the wand
    // term's children, unless this member function is overridden
    // to do so.
    void visit(typename NodeTypes::WandTerm &n) override { myVisit(n); }

    // SameElement have children. This visitor will not visit the
    // term's children, unless this member function is overridden
    // to do so.
    void visit(typename NodeTypes::SameElement &n) override { myVisit(n); }
};

}