17 if(processed_results%2 == 0){
23int Similarity_Explorer::find_number_pairs_show(
int number_pair_found){
25 return number_pair_found;
27 return min(limit_on_results,number_pair_found);
30string Similarity_Explorer::format_initial_message(
int number_pair_found){
32 ret += INITIAL_TEXT_PRINT_1;
34 ret += INITIAL_TEXT_PRINT_2;
35 ret +=
to_string(find_number_pairs_show(number_pair_found));
36 ret += INITIAL_TEXT_PRINT_3;
40bool Similarity_Explorer::match_pattern(
Path path1,
Path path2){
44 if(both_path_need_to_match_pattern){
45 return match1 && match2;
47 return match1 || match2;
50string Similarity_Explorer::format_path_message_in_pair(
Path path){
55int Similarity_Explorer::find_number_lines(
Path path1){
57 return function.number_of_lines();
60void Similarity_Explorer::print_similar_path_pair(
Path path1,
Path path2){
62 line += START_LINE_COMPARATION_PRINT;
63 line += format_path_message_in_pair(path1);
64 line += BETWEEN_TWO_FUNCTION;
65 line += format_path_message_in_pair(path2);
66 line += NUMBER_LINES_MESSAGE;
67 line +=
to_string(find_number_lines(path1));
73void Similarity_Explorer::process_similar_path_pair(
Path path1,
Path path2){
74 if(!match_pattern(path1,path2)){
77 if(limit_on_results !=
UNLIMITED_RESULTS && processed_results >= limit_on_results){
81 print_similar_path_pair(path1,path2);
84int Similarity_Explorer::find_number_pair_found(vector<pair<Path,Path>> similar_path_pairs){
86 for(
auto [path1, path2] : similar_path_pairs){
87 if(match_pattern(path1,path2)){
94vector<pair<Path,Path>> Similarity_Explorer::build_similar_path_pairs(
bool sorted_by_number_of_duplicated_code){
95 vector<pair<Path,Path>> similar_path_pairs;
96 if(sorted_by_number_of_duplicated_code){
101 return similar_path_pairs;
104void Similarity_Explorer::explorer(
bool sorted_by_number_of_duplicated_code){
105 vector<pair<Path,Path>> similar_path_pairs = build_similar_path_pairs(sorted_by_number_of_duplicated_code);
106 string initial_line = format_initial_message(find_number_pair_found(similar_path_pairs));
108 cout << initial_line <<
'\n';
111 for(
auto [path1, path2] : similar_path_pairs){
112 process_similar_path_pair(path1,path2);
117 int _limit_on_results,
118 string _pattern_to_match,
119 bool _both_path_need_to_match,
120 bool sorted_by_number_of_duplicated_code){
121 similarity_table = _similarity_table;
122 limit_on_results = _limit_on_results;
123 pattern_to_match = _pattern_to_match;
124 both_path_need_to_match_pattern = _both_path_need_to_match;
125 explorer(sorted_by_number_of_duplicated_code);
Represents a code function with its content and metadata.
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.
vector< pair< Path, Path > > get_all_similar_path_pairs_sorted_by_line_number()
Gets all similar path pairs, sorted by line count.
vector< pair< Path, Path > > get_all_similar_path_pairs_sorted_by_similarity()
Gets all similar path pairs, sorted by similarity.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
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.