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

#include "query_term_simple.h"
#include <atomic>

namespace search {

/**
 * Query term that can be returned in UCS-4 encoded form.
 */
class QueryTermUCS4 : public QueryTermSimple {
public:
    using ucs4_t = uint32_t;
    QueryTermUCS4(const QueryTermUCS4 &) = delete;
    QueryTermUCS4 & operator = (const QueryTermUCS4 &) = delete;
    QueryTermUCS4(QueryTermUCS4 &&) = delete;
    QueryTermUCS4 & operator = (QueryTermUCS4 &&) = delete;
    QueryTermUCS4(const string & term_, Type type);
    ~QueryTermUCS4() override;
    uint32_t getTermLen() const { return _cachedTermLen; }
    uint32_t term(const char * & t)     const { t = getTerm(); return _cachedTermLen; }
    void visitMembers(vespalib::ObjectVisitor &visitor) const override;
    std::unique_ptr<ucs4_t[]> asUcs4() const;
    uint32_t term(const ucs4_t * & t) {
        t = _termUCS4.load(std::memory_order_relaxed);
        if (t == nullptr) {
            t = fillUCS4();
        }
        return _cachedTermLen;
    }
private:
    const ucs4_t * fillUCS4();
    std::atomic<ucs4_t *>  _termUCS4;
    uint32_t               _cachedTermLen;
};

}