xref: /4.6.4/ep-engine/src/ep_types.h (revision 73d84472)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2016 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#pragma once
19#include <stdexcept>
20#include <string>
21#include <type_traits>
22
23enum class GenerateBySeqno {
24    No, Yes
25};
26
27typedef std::underlying_type<GenerateBySeqno>::type GenerateBySeqnoUType;
28
29static inline std::string to_string(const GenerateBySeqno generateBySeqno) {
30    switch (generateBySeqno) {
31        case GenerateBySeqno::Yes:
32            return "Yes";
33        case GenerateBySeqno::No:
34            return "No";
35        default:
36            throw std::invalid_argument("to_string(GenerateBySeqno) unknown " +
37                    std::to_string(static_cast<GenerateBySeqnoUType>(generateBySeqno)));
38            return "";
39    }
40}
41
42enum class GenerateCas {
43    No, Yes
44};
45
46typedef std::underlying_type<GenerateCas>::type GenerateByCasUType;
47
48static inline std::string to_string(GenerateCas generateCas) {
49    switch (generateCas) {
50        case GenerateCas::Yes:
51            return "Yes";
52        case GenerateCas::No:
53            return "No";
54        default:
55            throw std::invalid_argument("to_string(GenerateCas) unknown " +
56                    std::to_string(static_cast<GenerateByCasUType>(generateCas)));
57            return "";
58    }
59}
60
61enum class TaskStatus {
62    Reschedule, /* Reschedule for later */
63    Complete, /* Complete in this run */
64    Abort /* Abort task immediately */
65};
66