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

#include <vespa/vespalib/util/arrayref.h>
#include <sstream>

namespace storage {

/**
 * Creates a vector of the given type with one entry in it.
 */
template<class A>
std::vector<A>
toVector(A entry) {
    std::vector<A> entries;
    entries.push_back(entry);
    return entries;
}

/**
 * Creates a vector of the given type with two entries in it.
 */
template<class A>
std::vector<A>
toVector(A entry, A entry2) {
    std::vector<A> entries;
    entries.push_back(entry);
    entries.push_back(entry2);
    return entries;
}

/**
 * Creates a vector of the given type with two entries in it.
 */
template<class A>
std::vector<A>
toVector(A entry, A entry2, A entry3) {
    std::vector<A> entries;
    entries.push_back(entry);
    entries.push_back(entry2);
    entries.push_back(entry3);
    return entries;
}

/**
 * Creates a vector of the given type with two entries in it.
 */
template<class A>
std::vector<A>
toVector(A entry, A entry2, A entry3, A entry4) {
    std::vector<A> entries;
    entries.push_back(entry);
    entries.push_back(entry2);
    entries.push_back(entry3);
    entries.push_back(entry4);
    return entries;
}

template<class A>
std::string
dumpVector(const std::vector<A>& vec) {
    std::ostringstream ost;
    for (uint32_t i = 0; i < vec.size(); ++i) {
        if (!ost.str().empty()) {
            ost << ",";
        }
        ost << vec[i];
    }

    return ost.str();
}

}