aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/bucket/fixed_bucket_spaces.cpp
blob: 34f61a76200b4ec2f0c05b708edc293e9701faa8 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "fixed_bucket_spaces.h"

namespace document {

VESPA_IMPLEMENT_EXCEPTION(UnknownBucketSpaceException, vespalib::IllegalArgumentException)

// Some sanity checks to ensure we don't mess up any legacy mappings.
static_assert(BucketSpace::placeHolder() != BucketSpace::invalid());
static_assert(FixedBucketSpaces::default_space() == BucketSpace::placeHolder());
static_assert(FixedBucketSpaces::global_space() != FixedBucketSpaces::default_space());

BucketSpace FixedBucketSpaces::from_string(vespalib::stringref name) {
    if (name == "default") {
        return default_space();
    } else if (name == "global") {
        return global_space();
    } else {
        throw UnknownBucketSpaceException("Unknown bucket space name: " + vespalib::string(name), VESPA_STRLOC);
    }
}

vespalib::stringref FixedBucketSpaces::to_string(BucketSpace space) {
    if (space == default_space()) {
        return "default";
    } else if (space == global_space()) {
        return "global";
    } else {
        throw UnknownBucketSpaceException("Unknown bucket space: " + space.toString(), VESPA_STRLOC);
    }
}

}