From 7d3d1b923b7793f1cf5e29c78bfda2582522cf25 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 12 Oct 2017 17:34:20 +0100 Subject: COMPMID-619: Logging interface Change-Id: I73d1433ee7a682aeabb7540aa2ea1f6564f90aae Reviewed-on: http://mpd-gerrit.cambridge.arm.com/91775 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- support/ToolchainSupport.h | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'support') diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h index b9d9103652..ab2a9fe80f 100644 --- a/support/ToolchainSupport.h +++ b/support/ToolchainSupport.h @@ -144,8 +144,8 @@ inline T trunc(T value) * @note This function implements the same behaviour as std::copysign except that it doesn't * support Integral type. The latter is not in the namespace std in some Android toolchains. * - * @param[in] x value that contains the magnitued to be used in constructing the result. - * @param[in] y value that contains the sign to be used in constructin the result. + * @param[in] x value that contains the magnitude to be used in constructing the result. + * @param[in] y value that contains the sign to be used in construct in the result. * * @return Floating-point value with magnitude of @p x and sign of @p y. */ @@ -154,6 +154,23 @@ inline T copysign(T x, T y) { return ::copysign(x, y); } + +/** Loads the data from the given location, converts them to character string equivalents + * and writes the result to a character string buffer. + * + * @param[in] s Pointer to a character string to write to + * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator + * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data. + * @param[in] args Arguments forwarded to snprintf. + * + * @return Number of characters that would have been written for a sufficiently large buffer + * if successful (not including the terminating null character), or a negative value if an error occurred. + */ +template +inline int snprintf(char *s, size_t n, const char *fmt, Ts &&... args) +{ + return ::snprintf(s, n, fmt, std::forward(args)...); +} #else /* (__ANDROID__ || BARE_METAL) */ /** Convert integer and float values to string. * @@ -250,8 +267,8 @@ inline T trunc(T value) * @note This function implements the same behaviour as std::copysign except that it doesn't * support Integral type. The latter is not in the namespace std in some Android toolchains. * - * @param[in] x value that contains the magnitued to be used in constructing the result. - * @param[in] y value that contains the sign to be used in constructin the result. + * @param[in] x value that contains the magnitude to be used in constructing the result. + * @param[in] y value that contains the sign to be used in construct in the result. * * @return Floating-point value with magnitude of @p x and sign of @p y. */ @@ -260,6 +277,23 @@ inline T copysign(T x, T y) { return std::copysign(x, y); } + +/** Loads the data from the given location, converts them to character string equivalents + * and writes the result to a character string buffer. + * + * @param[in] s Pointer to a character string to write to + * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator + * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data. + * @param[in] args Arguments forwarded to std::snprintf. + * + * @return Number of characters that would have been written for a sufficiently large buffer + * if successful (not including the terminating null character), or a negative value if an error occurred. + */ +template +inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args) +{ + return std::snprintf(s, n, fmt, std::forward(args)...); +} #endif /* (__ANDROID__ || BARE_METAL) */ inline std::string to_string(bool value) -- cgit v1.2.1