Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
source_location-compat.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18
19/*
20 * Copyright (C) 2021 ScyllaDB
21 */
22
23#pragma once
24
25namespace seastar::internal {
26
27class source_location {
28 const char* _file;
29 const char* _func;
30 int _line;
31 int _col;
32
33 constexpr source_location(const char* file, const char* func, int line, int col) noexcept
34 : _file(file)
35 , _func(func)
36 , _line(line)
37 , _col(col)
38 { }
39public:
40 constexpr source_location() noexcept
41 : _file("unknown")
42 , _func(_file)
43 , _line(0)
44 , _col(0)
45 { }
46 static
47#ifdef __cpp_consteval
48 consteval
49#endif
50 source_location current(const char* file = __builtin_FILE(), const char* func = __builtin_FUNCTION(), int line = __builtin_LINE(), int col = 0) noexcept {
51 return source_location(file, func, line, col);
52 }
53
54 constexpr const char* file_name() const noexcept { return _file; }
55 constexpr const char* function_name() const noexcept { return _func; }
56 constexpr int line() const noexcept { return _line; }
57 constexpr int column() const noexcept { return _col; }
58};
59
60} // namespace seastar::internal