aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/update/tensor_add_update.h
blob: 20e231b42949d8d3a37eee65858ee7643a5870a9 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "tensor_update.h"
#include "valueupdate.h"

namespace vespalib::eval { struct Value; struct ValueBuilderFactory; }

namespace document {

class TensorFieldValue;

/**
 * An update used to add cells to a sparse or mixed tensor.
 *
 * The cells to add are contained in a tensor of the same type.
 */
class TensorAddUpdate final : public ValueUpdate, public TensorUpdate {
    std::unique_ptr<TensorFieldValue> _tensor;

    friend ValueUpdate;
    TensorAddUpdate();
    ACCEPT_UPDATE_VISITOR;
public:
    explicit TensorAddUpdate(std::unique_ptr<TensorFieldValue> tensor);
    TensorAddUpdate(const TensorAddUpdate &rhs) = delete;
    TensorAddUpdate &operator=(const TensorAddUpdate &rhs) = delete;
    ~TensorAddUpdate() override;
    bool operator==(const ValueUpdate &other) const override;
    const TensorFieldValue &getTensor() const { return *_tensor; }
    void checkCompatibility(const Field &field) const override;
    std::unique_ptr<vespalib::eval::Value> applyTo(const vespalib::eval::Value &tensor) const;
    std::unique_ptr<Value> apply_to(const Value &tensor,
                                    const ValueBuilderFactory &factory) const override;
    bool applyTo(FieldValue &value) const override;
    void printXml(XmlOutputStream &xos) const override;
    void print(std::ostream &out, bool verbose, const std::string &indent) const override;
    void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override;
};

}