aboutsummaryrefslogtreecommitdiffstats
path: root/vdslib/src/vespa/vdslib/container/operationlist.h
blob: c43d9e009e463e0183c99dba1a0b70ff7982b012 (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
77
78
79
80
81
82
83
84
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/document/fieldvalue/document.h>

namespace document { class DocumentUpdate; }

namespace vdslib {

class OperationList{
public:

    struct Operation{
        enum OpType{
            PUT=0,
            UPDATE=1,
            REMOVE=2
        };

        Operation(document::DocumentId dId)
            : docId(dId),
              opt(REMOVE)
        {
        }

        Operation(std::shared_ptr<document::Document> doc)
            : document(doc),
              opt(PUT)
        {
        }

        Operation(std::shared_ptr<document::DocumentUpdate> doc)
            : documentUpdate(doc),
              opt(UPDATE)
        {
        }
        ~Operation();

        document::DocumentId docId;
        std::shared_ptr<document::Document> document;
        std::shared_ptr<document::DocumentUpdate> documentUpdate;
        OpType opt;
    };

    void addPut(std::shared_ptr<document::Document> doc) {
        _operations.push_back(Operation(doc));
    }

    void addUpdate(std::shared_ptr<document::DocumentUpdate> docUpdate) {
        _operations.push_back(Operation(docUpdate));
    }

    void addRemove(document::DocumentId docId) {
        _operations.push_back(Operation(docId));
    }

    int getRequiredBufferSize() const;

    const std::vector<Operation>& getOperationList() const{
        return _operations;
    }

    // Deprecated functions. This list used to const cast and ruin source
    // objects in copy constructor. Keeping deprecated functions to avoid
    // breaking factory now, as they still work fine. Just code bloat.

    void addPut(std::unique_ptr<document::Document> doc) {
        _operations.push_back(
                Operation(std::shared_ptr<document::Document>(std::move(doc))));
    }

    void addUpdate(std::unique_ptr<document::DocumentUpdate> docUpdate) {
        _operations.push_back(
                Operation(std::shared_ptr<document::DocumentUpdate>(std::move(docUpdate))));
    }

    OperationList();
    ~OperationList();
private:
    std::vector<Operation> _operations;

};
}