Android-cuttlefish cvd tool
flag_base.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <stddef.h>
20
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace cuttlefish {
26
27template <typename T>
28class FlagBase {
29 public:
30 T ForIndex(const size_t index) const {
31 if (index < values_.size()) {
32 return values_[index];
33 } else {
34 return values_[0];
35 }
36 }
37
38 bool IsDefault() const { return is_default_; }
39
40 size_t Size() const { return values_.size(); }
41 const std::vector<T>& AsVector() const { return values_; }
42
43 protected:
44 explicit FlagBase(std::vector<T> flag_values, bool is_default)
45 : values_(std::move(flag_values)), is_default_(is_default) {}
46 virtual ~FlagBase() = 0;
47
48 private:
49 std::vector<T> values_;
51};
52
53template <typename T>
55
56extern template class FlagBase<bool>;
57extern template class FlagBase<int>;
58extern template class FlagBase<std::string>;
59
60} // namespace cuttlefish
Definition: flag_base.h:28
virtual ~FlagBase()=0
Definition: flag_base.h:54
bool IsDefault() const
Definition: flag_base.h:38
const std::vector< T > & AsVector() const
Definition: flag_base.h:41
bool is_default_
Definition: flag_base.h:50
FlagBase(std::vector< T > flag_values, bool is_default)
Definition: flag_base.h:44
size_t Size() const
Definition: flag_base.h:40
T ForIndex(const size_t index) const
Definition: flag_base.h:30
std::vector< T > values_
Definition: flag_base.h:49
Definition: alloc_driver.h:20
Definition: logging.h:464