blob: 508663115186268aa63a4744911a9f2f43349de4 (
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
85
86
87
88
89
90
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "valueupdate.h"
#include "addvalueupdate.h"
#include "assignvalueupdate.h"
#include "arithmeticvalueupdate.h"
#include "clearvalueupdate.h"
#include "removevalueupdate.h"
#include "mapvalueupdate.h"
#include "tensor_add_update.h"
#include "tensor_modify_update.h"
#include "tensor_remove_update.h"
#include <vespa/vespalib/util/stringfmt.h>
#include <stdexcept>
namespace document {
const char *
ValueUpdate::className() const noexcept {
switch (getType()) {
case Add:
return "AddValueUpdate";
case Assign:
return "AssignValueUpdate";
case Arithmetic:
return "ArithmeticValueUpdate";
case Clear:
return "ClearValueUpdate";
case Remove:
return "RemoveValueUpdate";
case Map:
return "MapValueUpdate";
case TensorAdd:
return "TensorAddUpdate";
case TensorModify:
return "TensorModifyUpdate";
case TensorRemove:
return "TensorRemoveUpdate";
default:
abort();
}
}
std::unique_ptr<ValueUpdate>
ValueUpdate::create(ValueUpdateType type) {
switch (type) {
case Add:
return std::unique_ptr<AddValueUpdate>(new AddValueUpdate());
case Assign:
return std::make_unique<AssignValueUpdate>();
case Arithmetic:
return std::unique_ptr<ArithmeticValueUpdate>(new ArithmeticValueUpdate());
case Clear:
return std::make_unique<ClearValueUpdate>();
case Remove:
return std::unique_ptr<RemoveValueUpdate>(new RemoveValueUpdate());
case Map:
return std::unique_ptr<MapValueUpdate>( new MapValueUpdate());
case TensorAdd:
return std::unique_ptr<TensorAddUpdate>( new TensorAddUpdate());
case TensorModify:
return std::unique_ptr<TensorModifyUpdate>( new TensorModifyUpdate());
case TensorRemove:
return std::unique_ptr<TensorRemoveUpdate>( new TensorRemoveUpdate());
default:
throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", type, type));
}
}
std::unique_ptr<ValueUpdate>
ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream)
{
int32_t classId = 0;
stream >> classId;
std::unique_ptr<ValueUpdate> update = create(static_cast<ValueUpdateType>(classId));
/// \todo TODO (was warning): Updates are not versioned in serialization format. Will not work without altering it.
/// Should also use the serializer, not this deserialize into self.
update->deserialize(repo, type, stream);
return update;
}
std::ostream&
operator<<(std::ostream& out, const ValueUpdate& p) {
p.print(out, false, "");
return out;
}
}
|