0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
source_location.h
Go to the documentation of this file.
1/**
2 * @file src/common/model/source_location.h
3 *
4 * Copyright (c) 2021-2024 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#pragma once
19
20#include <string>
21#include <utility>
22
24
25/**
26 * @brief Base class of all diagram elements that have source location.
27 *
28 * @embed{source_location_hierarchy_class.svg}
29 */
31public:
32 source_location() = default;
33
34 source_location(std::string f, unsigned int l)
35 : file_{std::move(f)}
36 , line_{l}
37 {
38 }
39
40 /**
41 * Return absolute source file path.
42 *
43 * @return Absolute file path.
44 */
45 const std::string &file() const { return file_; }
46
47 /**
48 * Set absolute file path.
49 *
50 * @param file Absolute file path.
51 */
52 void set_file(const std::string &file) { file_ = file; }
53
54 /**
55 * Return source file path relative to `relative_to` config option.
56 *
57 * @return Relative file path.
58 */
59 const std::string &file_relative() const { return file_relative_; }
60
61 /**
62 * Set relative file path.
63 *
64 * @param file Relative file path.
65 */
66 void set_file_relative(const std::string &file) { file_relative_ = file; }
67
68 /**
69 * Get the translation unit, from which this source location was visited.
70 *
71 * @return Path to the translation unit.
72 */
73 const std::string &translation_unit() const { return translation_unit_; }
74
75 /**
76 * Set the path to translation unit, from which this source location was
77 * visited.
78 *
79 * @param translation_unit Path to the translation unit.
80 */
81 void set_translation_unit(const std::string &translation_unit)
82 {
84 }
85
86 /**
87 * Get the source location line number.
88 *
89 * @return Line number.
90 */
91 unsigned int line() const { return line_; }
92
93 /**
94 * Set the source location line number.
95 *
96 * @param line Line number.
97 */
98 void set_line(const unsigned line) { line_ = line; }
99
100 /**
101 * Get the source location column number.
102 *
103 * @return Column number.
104 */
105 unsigned int column() const { return column_; }
106
107 /**
108 * Set the source location column number.
109 *
110 * @param line Column number.
111 */
112 void set_column(const unsigned column) { column_ = column; }
113
114 /**
115 * Get the source location id.
116 *
117 * The location id is equivalent to Clang's SourceLocation::getHashValue()
118 *
119 * @return Location id.
120 */
121 unsigned int location_id() const { return hash_; }
122
123 /**
124 * Set the source location id.
125 *
126 * The location id is equivalent to Clang's SourceLocation::getHashValue()
127 *
128 * @param h Location id.
129 */
130 void set_location_id(unsigned int h) { hash_ = h; }
131
132private:
133 std::string file_;
134 std::string file_relative_;
135 std::string translation_unit_;
136 unsigned int line_{0};
137 unsigned int column_{0};
138 unsigned int hash_{0};
139};
140} // namespace clanguml::common::model