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 <sstream>
19 #include <string>
20 #include <type_traits>
21 #include <vector>
22
23 #include <android-base/logging.h>
24
25 namespace cuttlefish {
26 template <typename T>
Enum2Base(T t)27 constexpr typename std::underlying_type_t<T> Enum2Base(T t) {
28 return static_cast<typename std::underlying_type_t<T>>(t);
29 }
30 } // end of namespace cuttlefish
31
32 namespace cuttlefish {
33 namespace confui {
34 template <typename Delim, typename... Args>
ArgsToStringWithDelim(Delim && delim,Args &&...args)35 std::string ArgsToStringWithDelim(Delim&& delim, Args&&... args) {
36 std::stringstream ss;
37 ([&ss, &delim](auto& arg) { ss << arg << delim; }(args), ...);
38 return ss.str();
39 }
40
41 // make t... to a single string with no blank in between
42 template <typename... Args>
ArgsToString(Args &&...args)43 std::string ArgsToString(Args&&... args) {
44 return ArgsToStringWithDelim("", std::forward<Args>(args)...);
45 }
46
47 // note that no () surrounding LOG(level) << "ConfUI:" is crucial
48 #define ConfUiLog(LOG_LEVEL) LOG(LOG_LEVEL) << "ConfUI: "
49
50 // TODO(kwstephenkim@google.com): make these look more like LOG(level)
51 #define ConfUiCheck(cond) CHECK(cond) << "ConfUI: "
52
53 } // end of namespace confui
54 } // end of namespace cuttlefish
55