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

#include "bucketspace.h"
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/stllike/string.h>

namespace document {

VESPA_DEFINE_EXCEPTION(UnknownBucketSpaceException, vespalib::IllegalArgumentException);

/**
 * Minimal repository/factory of bucket spaces hard coded for default and global
 * distributions.
 */
struct FixedBucketSpaces {
    static constexpr BucketSpace default_space() { return BucketSpace(1); };
    static constexpr BucketSpace global_space() { return BucketSpace(2); }
    static vespalib::stringref default_space_name() { return to_string(default_space()); }
    static vespalib::stringref global_space_name() { return to_string(global_space()); }

    // Post-condition: returned space has valid() == true iff name
    // is either "default" or "global".
    // Throws UnknownBucketSpaceException if name does not map to a known bucket space.
    static BucketSpace from_string(vespalib::stringref name);
    // Post-condition: returned string can be losslessly passed to from_string()
    // iff space is equal to default_space() or global_space().
    // Throws UnknownBucketSpaceException if space does not map to a known name.
    static vespalib::stringref to_string(BucketSpace space);
};

}