Flow 1.0.1
Flow project: Full implementation reference.
util.cpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
20#include "flow/util/util.hpp"
21
22namespace flow::util
23{
24
25// Implementations.
26
27std::string get_where_am_i_str(String_view file, String_view function, unsigned int line)
28{
29 /* @todo There's a to-do in the one invoker of this as of this writing, namely FLOW_UTIL_WHERE_AM_I_STR(), to
30 * make that thing into a compile-time expression; which really reduces to making the present function constexpr.
31 * For example, FLOW_UTIL_WHERE_AM_I_FROM_ARGS() it compile-time, and it basically only took
32 * making get_last_path_segment() constexpr (which wasn't trivial but doable). One problem here is that macro
33 * only needs to evaluate to an ostream <<fragment<<, while we must actually create a string, which involves an
34 * extra step. That may still be doable, if we can keep [concatenation of 3 string vars and a few "literals"; +
35 * conversion of a number (`line`) to string] to constexpr-supported syntax. With a methodical approach it may be
36 * possible to build such a thing from the bottom up. Is itoa() `constexpr`able? Is string concatenation in
37 * some form? Perhaps. */
38
39 using std::string;
40
41 string out; // Write directly into this string.
43
44 return out;
45}
46
47} // namespace flow::util
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
Definition: basic_blob.hpp:29
std::string get_where_am_i_str(String_view file, String_view function, unsigned int line)
Helper for FLOW_UTIL_WHERE_AM_I(), etc., that, given values for source code file name,...
Definition: util.cpp:27
void ostream_op_to_string(std::string *target_str, T const &... ostream_args)
Writes to the specified string, as if the given arguments were each passed, via << in sequence,...
Definition: util.hpp:342
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.
#define FLOW_UTIL_WHERE_AM_I_FROM_ARGS_TO_ARGS(ARG_file, ARG_function, ARG_line)
Helper macro, same as FLOW_UTIL_WHERE_AM_I_FROM_ARGS(), but results in a list of comma-separated,...
Definition: util.hpp:131