aboutsummaryrefslogtreecommitdiffstats
path: root/persistence/src/vespa/persistence/spi/types.h
blob: 33280df72f99760a16daf5ba8bbae9a1f23d9c95 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vector>
#include <memory>

namespace vespalib {
    class nbostream;
}

namespace document {
    class GlobalId;
    class Document;
    class DocumentId;
    class DocumentUpdate;
}

/**
 * We create small wrapper classes for number values for the following reasons:
 *   - Being able to create functions taking in several of them, without risking
 *     caller using numbers in wrong order.
 *   - We can identify type by typename instead of variable name.
 */
#define DEFINE_PRIMITIVE_WRAPPER(type, name) \
  class name { \
      type _value; \
  public: \
      using Type = type; \
      name() noexcept : _value() {} \
      explicit name(type v) noexcept : _value(v) {} \
      operator type() const noexcept { return _value; } \
      operator type&() noexcept { return _value; } \
      type getValue() const noexcept { return _value; } \
      name& operator=(type val) noexcept { _value = val; return *this; } \
      friend vespalib::nbostream & \
      operator<<(vespalib::nbostream &os, const name &wrapped); \
      friend vespalib::nbostream & \
      operator>>(vespalib::nbostream &is, name &wrapped); \
  }; \

#define DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(name) \
  vespalib::nbostream & \
  operator<<(vespalib::nbostream &os, const name &wrapped) \
  { \
      os << wrapped._value; \
      return os; \
  } \
  \
  vespalib::nbostream & \
  operator>>(vespalib::nbostream &is, name &wrapped) \
  { \
      is >> wrapped._value; \
      return is; \
  } \

namespace storage::spi {

/**
 * \class storage::spi::NodeIndex
 * \ingroup spi
 */
DEFINE_PRIMITIVE_WRAPPER(uint16_t, NodeIndex);

/**
 * \class storage::spi::IteratorId
 * \ingroup spi
 */
DEFINE_PRIMITIVE_WRAPPER(uint64_t, IteratorId);

/**
 * \class storage::spi::Timestamp
 * \ingroup spi
 */
DEFINE_PRIMITIVE_WRAPPER(uint64_t, Timestamp);

/**
 * \class storage::spi::BucketChecksum
 * \ingroup spi
 */
DEFINE_PRIMITIVE_WRAPPER(uint32_t, BucketChecksum);

// Import critical dependencies into SPI namespace. This makes interface look
// cleaner, and makes it easy to exchange actual implementation.
using Document = document::Document;
using DocumentUpdate = document::DocumentUpdate;
using DocumentId = document::DocumentId;
using GlobalId = document::GlobalId;
using TimestampList = std::vector<Timestamp>;
using string = vespalib::string;
using DocumentUP = std::unique_ptr<document::Document>;
using DocumentIdUP = std::unique_ptr<document::DocumentId>;
using DocumentSP = std::shared_ptr<document::Document>;
using DocumentUpdateSP = std::shared_ptr<document::DocumentUpdate>;

enum IncludedVersions {
    NEWEST_DOCUMENT_ONLY,
    NEWEST_DOCUMENT_OR_REMOVE,
    ALL_VERSIONS
};

enum MaintenanceLevel {
    LOW,
    HIGH
};

}