Android-cuttlefish cvd tool
utils.h
Go to the documentation of this file.
1//
2// Copyright (C) 2021 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#pragma once
17
18#include <algorithm>
19#include <sstream>
20#include <string>
21#include <string_view>
22#include <type_traits>
23
24#include "absl/log/check.h"
25#include "absl/log/log.h"
26
27namespace cuttlefish::confui {
28
29template <typename T>
30constexpr typename std::underlying_type_t<T> Enum2Base(T t) {
31 return static_cast<typename std::underlying_type_t<T>>(t);
32}
33
34template <typename Delim, typename... Args>
35std::string ArgsToStringWithDelim(Delim&& delim, Args&&... args) {
36 std::stringstream ss;
37 ([&ss, &delim](auto& arg) { ss << arg << delim; }(args), ...);
38 auto result = ss.str();
39 std::string delim_str(delim);
40 if (!result.empty() && !delim_str.empty()) {
41 for (int i = 0; i < delim_str.size(); i++) {
42 result.pop_back();
43 }
44 }
45 return result;
46}
47
48// make t... to a single string with no blank in between
49template <typename... Args>
50std::string ArgsToString(Args&&... args) {
51 return ArgsToStringWithDelim("", std::forward<Args>(args)...);
52}
53
54inline bool IsOnlyDigits(std::string_view src) {
55 return std::all_of(src.begin(), src.end(),
56 [](int c) -> bool { return std::isdigit(c); });
57}
58
59// note that no () surrounding LOG(level) << "ConfUI:" is crucial
60#define ConfUiLog(LOG_LEVEL) LOG(LOG_LEVEL) << "ConfUI: "
61#define ConfUiLogDebug VLOG(0) << "ConfUI: "
62#define ConfUiLogVerbose VLOG(1) << "ConfUI: "
63
64// TODO(kwstephenkim@google.com): make these look more like LOG(level)
65#define ConfUiCheck(cond) CHECK(cond) << "ConfUI: "
66
67} // namespace cuttlefish::confui
struct f2fs_configuration c
Definition: libf2fs_io.c:47
Definition: packet.cpp:33
std::string ArgsToStringWithDelim(Delim &&delim, Args &&... args)
Definition: utils.h:35
constexpr std::underlying_type_t< T > Enum2Base(T t)
Definition: utils.h:30
bool IsOnlyDigits(std::string_view src)
Definition: utils.h:54
std::string ArgsToString(Args &&... args)
Definition: utils.h:50
std::vector< std::string_view > Args
Definition: incremental.h:28