blob: 0e2a839f64d40705799e2cccd18ddcee32acfc02 [file] [log] [blame]
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_LOGGING_HELPERS_H
25#define ARM_COMPUTE_LOGGING_HELPERS_H
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010026
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
36namespace arm_compute
37{
38namespace 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 */
47template <typename... Ts>
48inline 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 = support::cpp14::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 */
61template <typename T>
62inline 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 */
74const std::string &string_from_log_level(LogLevel log_level);
75} // namespace logging
76} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000077#endif /* ARM_COMPUTE_LOGGING_HELPERS_H */