ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
function.cpp
Go to the documentation of this file.
2
4
5const Path& Function::path() const {
6 return path_;
7}
8
9const std::string& Function::name() const {
10 return name_;
11}
12
14 : path_(_path),
15 location_{} {}
16
18 return location_;
19}
20
21const std::vector<std::string>& Function::header() const {
22 return header_;
23}
24
25std::vector<std::string> Function::build_all_content() const {
26 std::vector<std::string> ret;
27 // the last line of header should merge with the first line of content
28 for (const auto& line : header_)
29 ret.push_back(line);
30 for (size_t i = 0; i < content_.size(); i++) {
31 auto line = content_[i];
32 if (i >= 1) {
33 ret.push_back(line);
34 } else {
35 ret.back() += line;
36 }
37 }
38 return ret;
39}
40
41bool Function::contains_given_pattern(const std::string& pattern) const {
42 fs::path relative_path_plus_function_name = path().relative_path() / name();
43
44 return relative_path_plus_function_name.string().find(pattern) != std::string::npos;
45}
bool contains_given_pattern(const std::string &pattern) const
Checks whether the function contains a pattern.
Definition: function.cpp:41
Function()=default
const std::vector< std::string > & header() const
Gets the function's header content.
Definition: function.cpp:21
const Path & path() const
Gets the function path information.
Definition: function.cpp:5
std::vector< std::string > build_all_content() const
Builds combined content of header and source.
Definition: function.cpp:25
const std::string & name() const
Gets the function name.
Definition: function.cpp:9
const FunctionLocation & scope_location() const
Gets the function location inside the source file.
Definition: function.cpp:17
Represents a logical path to a function in the codebase.
Definition: path.hpp:26
fs::path relative_path() const
Gets the directory portion of the path.
Definition: path.cpp:15
Function representation for a codebase.