blob: 1b56b4881f9eee5fa5ceac2baeedd8aa60816597 (
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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
namespace document {
/**
* Class used to represent up to 4 flags used in a DocumentUpdate.
* These flags are stored as the 4 most significant bits in a 32 bit integer.
*
* Flags currently used:
* 0) create-if-non-existent.
*/
class DocumentUpdateFlags {
private:
uint8_t _flags;
DocumentUpdateFlags(uint8_t flags) : _flags(flags) {}
public:
DocumentUpdateFlags() : _flags(0) {}
bool getCreateIfNonExistent() {
return (_flags & 1) != 0;
}
void setCreateIfNonExistent(bool value) {
_flags &= ~1; // clear flag
_flags |= value ? 1 : 0; // set flag
}
int injectInto(int value) {
return extractValue(value) | (_flags << 28);
}
static DocumentUpdateFlags extractFlags(int combined) {
return DocumentUpdateFlags((uint8_t)(combined >> 28));
}
static int extractValue(int combined) {
int mask = ~(~0U << 28);
return combined & mask;
}
};
}
|