• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MemorySupport.h"
29 #include "support/ToolchainSupport.h"
30 
31 #include <cstddef>
32 #include <cstdio>
33 #include <memory>
34 #include <sstream>
35 #include <string>
36 
37 namespace arm_compute
38 {
39 namespace logging
40 {
41 /** Create a string given a format
42  *
43  * @param[in] fmt  String format
44  * @param[in] args Arguments
45  *
46  * @return The formatted string
47  */
48 template <typename... Ts>
string_with_format(const std::string & fmt,Ts &&...args)49 inline std::string string_with_format(const std::string &fmt, Ts &&... args)
50 {
51     size_t size     = support::cpp11::snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
52     auto   char_str = support::cpp14::make_unique<char[]>(size);
53     support::cpp11::snprintf(char_str.get(), size, fmt.c_str(), args...);
54     return std::string(char_str.get(), char_str.get() + size - 1);
55 }
56 /** Wraps a value with angles and returns the string
57  *
58  * @param[in] val Value to wrap
59  *
60  * @return Wrapped string
61  */
62 template <typename T>
angle_wrap_value(const T & val)63 inline std::string angle_wrap_value(const T &val)
64 {
65     std::ostringstream ss;
66     ss << "[" << val << "]";
67     return ss.str();
68 }
69 /** Translates a given log level to a string.
70  *
71  * @param[in] log_level @ref LogLevel to be translated to string.
72  *
73  * @return The string describing the logging level.
74  */
75 const std::string &string_from_log_level(LogLevel log_level);
76 } // namespace logging
77 } // namespace arm_compute
78 #endif /* ARM_COMPUTE_LOGGING_HELPERS_H */
79