aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/attributesaver.h
blob: fd081f44c1cf7c25d842f88e6d02dcb40f07435a (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "attribute_header.h"
#include <vespa/vespalib/util/generationhandler.h>

namespace search {

class IAttributeSaveTarget;

/*
 * Abstract class used to hold data outside attribute vector needed
 * during a save operation, e.g. copy of data structure without
 * snapshot property, and guards to protect frozen views on structures
 * with snapshot properties.
 */
class AttributeSaver
{
private:
    vespalib::GenerationHandler::Guard _guard;
    attribute::AttributeHeader _header;

protected:
    AttributeSaver(vespalib::GenerationHandler::Guard &&guard,
                   const attribute::AttributeHeader &header);

    virtual bool onSave(IAttributeSaveTarget &saveTarget) = 0;

    uint32_t get_header_version() const { return _header.getVersion(); }
public:
    virtual ~AttributeSaver();

    bool save(IAttributeSaveTarget &saveTarget);

    bool hasGenerationGuard() const;

    const vespalib::string &get_file_name() const { return _header.getFileName(); }
};

} // namespace search