C/C++ API Reference
Loading...
Searching...
No Matches
tokenized_args.h
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include "pw_enum/to_string.h"
17#include "pw_tokenizer/enum.h"
18
20
25#define PW_LOG_ENUM_FMT(enum) PW_LOG_TOKEN_FMT(#enum)
26
27// pw_log backends that use pw_tokenizer and want to support nested tokenization
28// define this file under their public_overrides/ directory to activate the
29// PW_LOG_TOKEN aliases. If this file does not exist in the log backend,
30// arguments behave as basic strings (const char*).
31#if __has_include("pw_log_backend/log_backend_uses_pw_tokenizer.h")
32
33#include "pw_tokenizer/nested_tokenization.h"
34#include "pw_tokenizer/tokenize.h"
35
36#define PW_LOG_TOKEN_TYPE pw_tokenizer_Token
37#define PW_LOG_TOKEN_DEFAULT_VALUE ((pw_tokenizer_Token)0)
38#define PW_LOG_TOKEN PW_TOKENIZE_STRING
39#define PW_LOG_TOKEN_EXPR PW_TOKENIZE_STRING_EXPR
40#define PW_LOG_TOKEN_FMT PW_TOKEN_FMT
41#define PW_LOG_ENUM(enumerator) ::pw::tokenizer::EnumToToken(enumerator)
42#define PW_LOG_NESTED_TOKEN_FMT PW_NESTED_TOKEN_FMT
43
44#else
45
50#define PW_LOG_TOKEN_TYPE const char*
51
56#ifdef __cplusplus
57#define PW_LOG_TOKEN_DEFAULT_VALUE nullptr
58#else
59#define PW_LOG_TOKEN_DEFAULT_VALUE NULL
60#endif // __cplusplus
61
64#define PW_LOG_TOKEN(...) \
65 PW_DELEGATE_BY_ARG_COUNT(_PW_STRING_OPTIONAL_DOMAIN_, __VA_ARGS__)
66#define _PW_STRING_OPTIONAL_DOMAIN_1(string_literal) string_literal
67#define _PW_STRING_OPTIONAL_DOMAIN_2(domain, string_literal) string_literal
68
71#define PW_LOG_TOKEN_EXPR(...) \
72 PW_DELEGATE_BY_ARG_COUNT(_PW_STRING_OPTIONAL_DOMAIN_, __VA_ARGS__)
73
78#define PW_LOG_TOKEN_FMT(...) "%s"
79
85#define PW_LOG_ENUM(enumerator) ::pw::EnumToString(enumerator)
86
91#define PW_LOG_NESTED_TOKEN_FMT(...) "%s::%s"
92
93#endif //__has_include("log_backend/log_backend_uses_pw_tokenizer.h")
94
95#ifdef __cplusplus
96
97namespace pw::log {
98
101using Token = PW_LOG_TOKEN_TYPE;
102
104inline constexpr Token kDefaultToken = PW_LOG_TOKEN_DEFAULT_VALUE;
105
106} // namespace pw::log
107
108#endif // __cplusplus
109
#define PW_LOG_TOKEN_DEFAULT_VALUE
Definition: tokenized_args.h:57
#define PW_LOG_TOKEN_TYPE
Definition: tokenized_args.h:50