1 /*
2 * Copyright (c) 2017-2020 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 #ifndef ARM_COMPUTE_LOGGING_HELPERS_H
25 #define ARM_COMPUTE_LOGGING_HELPERS_H
26
27 #include "arm_compute/core/utils/logging/Types.h"
28 #include "support/ToolchainSupport.h"
29
30 #include <cstddef>
31 #include <cstdio>
32 #include <memory>
33 #include <sstream>
34 #include <string>
35
36 namespace arm_compute
37 {
38 namespace logging
39 {
40 /** Create a string given a format
41 *
42 * @param[in] fmt String format
43 * @param[in] args Arguments
44 *
45 * @return The formatted string
46 */
47 template <typename... Ts>
string_with_format(const std::string & fmt,Ts &&...args)48 inline std::string string_with_format(const std::string &fmt, Ts &&... args)
49 {
50 size_t size = support::cpp11::snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
51 auto char_str = std::make_unique<char[]>(size);
52 support::cpp11::snprintf(char_str.get(), size, fmt.c_str(), args...);
53 return std::string(char_str.get(), char_str.get() + size - 1);
54 }
55 /** Wraps a value with angles and returns the string
56 *
57 * @param[in] val Value to wrap
58 *
59 * @return Wrapped string
60 */
61 template <typename T>
angle_wrap_value(const T & val)62 inline std::string angle_wrap_value(const T &val)
63 {
64 std::ostringstream ss;
65 ss << "[" << val << "]";
66 return ss.str();
67 }
68 /** Translates a given log level to a string.
69 *
70 * @param[in] log_level @ref LogLevel to be translated to string.
71 *
72 * @return The string describing the logging level.
73 */
74 const std::string &string_from_log_level(LogLevel log_level);
75 } // namespace logging
76 } // namespace arm_compute
77 #endif /* ARM_COMPUTE_LOGGING_HELPERS_H */
78