/builds/MusicScience37Projects/numerical-analysis/numerical-collection-cpp/include/num_collect/util/source_info_view.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021 MusicScience37 (Kenta Kabashima) |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | /*! |
17 | | * \file |
18 | | * \brief Definition of source_info_view class. |
19 | | */ |
20 | | #pragma once |
21 | | |
22 | | #include <string_view> |
23 | | |
24 | | #include "num_collect/base/index_type.h" |
25 | | #include "num_collect/util/impl/compiler_builtins.h" |
26 | | |
27 | | namespace num_collect::util { |
28 | | |
29 | | /*! |
30 | | * \brief Class to hold information of source codes. |
31 | | * |
32 | | * \note This class won't manage memory for strings. |
33 | | * \note This class is a wrapper of `std::source_location`. |
34 | | */ |
35 | | class source_info_view { |
36 | | public: |
37 | | /*! |
38 | | * \brief Constructor. |
39 | | * |
40 | | * \param[in] file_path File path. |
41 | | * \param[in] line Line number. |
42 | | * \param[in] column Column number. |
43 | | * \param[in] function_name Function name. |
44 | | */ |
45 | | constexpr explicit source_info_view( |
46 | | std::string_view file_path = NUM_COLLECT_BUILTIN_FILE(), |
47 | | index_type line = NUM_COLLECT_BUILTIN_LINE(), |
48 | | index_type column = NUM_COLLECT_BUILTIN_COLUMN(), |
49 | | std::string_view function_name = NUM_COLLECT_BUILTIN_FUNCTION()) |
50 | 139k | : file_path_(file_path), |
51 | 139k | line_(line), |
52 | 139k | column_(column), |
53 | 139k | function_name_(function_name) {} |
54 | | |
55 | | /*! |
56 | | * \brief Get the file path. |
57 | | * |
58 | | * \return File path. |
59 | | */ |
60 | 39.2k | [[nodiscard]] constexpr auto file_path() const -> std::string_view { |
61 | 39.2k | return file_path_; |
62 | 39.2k | } |
63 | | |
64 | | /*! |
65 | | * \brief Get the line number. |
66 | | * |
67 | | * \return Line number. |
68 | | */ |
69 | 39.2k | [[nodiscard]] constexpr auto line() const -> index_type { return line_; } |
70 | | |
71 | | /*! |
72 | | * \brief Get the column number. |
73 | | * |
74 | | * \return Column number. |
75 | | */ |
76 | 39.1k | [[nodiscard]] constexpr auto column() const -> index_type { |
77 | 39.1k | return column_; |
78 | 39.1k | } |
79 | | |
80 | | /*! |
81 | | * \brief Get the function name. |
82 | | * |
83 | | * \return Function name. |
84 | | */ |
85 | 39.0k | [[nodiscard]] constexpr auto function_name() const -> std::string_view { |
86 | 39.0k | return function_name_; |
87 | 39.0k | } |
88 | | |
89 | | private: |
90 | | //! File path. |
91 | | std::string_view file_path_; |
92 | | |
93 | | //! Line number. |
94 | | index_type line_; |
95 | | |
96 | | //! Column number. |
97 | | index_type column_; |
98 | | |
99 | | //! Function name. |
100 | | std::string_view function_name_; |
101 | | }; |
102 | | |
103 | | } // namespace num_collect::util |