blob: 6441fa57853e398e531b8bfeb62be6a546ec1bd0 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/document/fieldvalue/fieldvalue.h>
#include <vespa/vsm/common/document.h>
namespace vsm {
/**
* Interface for classes that want to modify a field value.
**/
class FieldModifier
{
public:
using UP = std::unique_ptr<FieldModifier>;
/**
* Modifies the given field value and returns a new one.
**/
virtual document::FieldValue::UP modify(const document::FieldValue & fv) = 0;
/**
* Modifies the given field value and returns a new one.
* Use the given field path to iterate the field value.
**/
virtual document::FieldValue::UP modify(const document::FieldValue & fv,
const document::FieldPath & path) = 0;
virtual ~FieldModifier() { }
};
using FieldModifierMapT = vespalib::hash_map<FieldIdT, FieldModifier::UP>;
/**
* This class wraps a map from field id to field modifier.
**/
class FieldModifierMap
{
private:
FieldModifierMapT _map;
public:
FieldModifierMap();
~FieldModifierMap();
FieldModifierMapT & map() { return _map; }
const FieldModifierMapT & map() const { return _map; }
/**
* Returns the modifier associated with the given field id or NULL if not found.
*
* @param fId the field id to look up.
* @return the field modifier or NULL if not found.
**/
FieldModifier * getModifier(FieldIdT fId) const;
};
}
|