7#include <bits/stdc++.h>
13 if(processed_results%2 == 0){
19int Similarity_Explorer::find_number_pairs_show(
int number_pair_found){
21 return number_pair_found;
23 return min(limit_on_results,number_pair_found);
26string Similarity_Explorer::format_initial_message(
int number_pair_found){
28 ret += INITIAL_TEXT_PRINT_1;
29 ret += to_string(number_pair_found);
30 ret += INITIAL_TEXT_PRINT_2;
31 ret += to_string(find_number_pairs_show(number_pair_found));
32 ret += INITIAL_TEXT_PRINT_3;
36bool Similarity_Explorer::match_pattern(
Path path1,
Path path2){
40 if(both_path_need_to_match_pattern){
41 return match1 && match2;
43 return match1 || match2;
46string Similarity_Explorer::format_path_message_in_pair(
Path path){
51int Similarity_Explorer::find_number_lines(
Path path1){
52 Function function(path1);
53 return function.number_of_lines();
56void Similarity_Explorer::print_similar_path_pair(
Path path1,
Path path2){
58 line += START_LINE_COMPARATION_PRINT;
59 line += format_path_message_in_pair(path1);
60 line += BETWEEN_TWO_FUNCTION;
61 line += format_path_message_in_pair(path2);
62 line += NUMBER_LINES_MESSAGE;
63 line += to_string(find_number_lines(path1));
69void Similarity_Explorer::process_similar_path_pair(
Path path1,
Path path2){
70 if(!match_pattern(path1,path2)){
73 if(limit_on_results !=
UNLIMITED_RESULTS && processed_results >= limit_on_results){
77 print_similar_path_pair(path1,path2);
80int Similarity_Explorer::find_number_pair_found(vector<pair<Path,Path>> similar_path_pairs){
82 for(
auto [path1, path2] : similar_path_pairs){
83 if(match_pattern(path1,path2)){
90vector<pair<Path,Path>> Similarity_Explorer::build_similar_path_pairs(
bool sorted_by_number_of_duplicated_code){
91 vector<pair<Path,Path>> similar_path_pairs;
92 if(sorted_by_number_of_duplicated_code){
93 similar_path_pairs = similarity_table->get_all_similar_path_pairs_sorted_by_line_number();
95 similar_path_pairs = similarity_table->get_all_similar_path_pairs_sorted_by_similarity();
97 return similar_path_pairs;
100void Similarity_Explorer::explorer(
bool sorted_by_number_of_duplicated_code){
101 vector<pair<Path,Path>> similar_path_pairs = build_similar_path_pairs(sorted_by_number_of_duplicated_code);
102 string initial_line = format_initial_message(find_number_pair_found(similar_path_pairs));
104 cout << initial_line <<
'\n';
107 for(
auto [path1, path2] : similar_path_pairs){
108 process_similar_path_pair(path1,path2);
113 int _limit_on_results,
114 string _pattern_to_match,
115 bool _both_path_need_to_match,
116 bool sorted_by_number_of_duplicated_code){
117 similarity_table = _similarity_table;
118 limit_on_results = _limit_on_results;
119 pattern_to_match = _pattern_to_match;
120 both_path_need_to_match_pattern = _both_path_need_to_match;
121 explorer(sorted_by_number_of_duplicated_code);
Path manipulation class for tool-specific directory structure.
bool contains_given_pattern(string pattern)
Checks for pattern in path.
string build_relative_path()
Builds relative path portion.
string build_function_name()
Extracts function name from path.
Similarity_Explorer(Similarity_Table *_similarity_table, int _limit_on_results, string _pattern_to_match, bool _both_path_need_to_match, bool sorted_by_number_of_duplicated_code=false)
Constructs explorer with configuration.
int UNLIMITED_RESULTS
Constant for unlimited results display.
Manages and analyzes function similarity relationships.
COLOR
Enumeration of available colors for formatted messages.
string format_colored_message(string message, COLOR color)
Formats a message with ANSI color codes.
const string LIMITER_PRINT
Constant string used as a visual delimiter/separator in prints.
Duplicate function exploration interface.