9#include <unordered_map>
11void FunctionBreaker::write_output(
12 const fs::path type_path,
13 const fs::path& relative_path,
14 const std::string& function_name,
15 const std::string& content
18 fs::path path = storage.
build_output_path(type_path, relative_path, function_name);
22std::string FunctionBreaker::create_info_json(
23 int line_declaration,
int start_number_line,
24 int end_number_line,
const fs::path& relative_path,
25 const std::string& function_name
28 "\"file_name\":\"" + relative_path.string() +
"\","
29 "\"function_name\":\"" + function_name +
"\","
30 "\"line_declaration\":" + std::to_string(line_declaration) +
","
31 "\"start_number_line\":" + std::to_string(start_number_line) +
","
32 "\"end_number_line\":" + std::to_string(end_number_line) +
37void FunctionBreaker::file_breaker(
38 const fs::path& file_path,
const fs::path& folder_path,
44 if (!fs::exists(file_path))
return;
46 fs::path relative_path;
48 relative_path = fs::relative(file_path, folder_path);
59 if (metadata->end_number_line - metadata->start_number_line <= minimum_lines) {
64 on_function(function);
68 write_output(cfg.source_path, relative_path, function.function_name, source->code +
"\n");
69 write_output(cfg.header_path, relative_path, function.function_name, metadata->signature);
70 write_output(cfg.info_path, relative_path, function.function_name,
71 create_info_json(metadata->line_declaration, metadata->start_number_line, metadata->end_number_line, relative_path, function.function_name));
83 const fs::path& folder_path,
91 for (
const auto& dirEntry : fs::recursive_directory_iterator(folder_path)) {
92 if (!dirEntry.is_regular_file())
continue;
94 auto path = dirEntry.path();
95 file_breaker(path, folder_path, on_function, stats, granularity, minimum_lines);
static Config & config()
Gets the singleton configuration instance.
int process(const fs::path &folder_path, std::function< void(const FunctionData &)> on_function, SkipStats &stats, int minimum_lines=0, Granularity granularity=Granularity::Function)
Processes all files in directory.
fs::path build_output_path(const fs::path type_path, const fs::path &relative_path, const std::string &function_name) const
Builds file path for a function.
static void process_file_as_unit(const fs::path &file_path, const fs::path &relative_path, const std::string &source_code, std::function< void(const FunctionData &)> callback, SkipStats &stats)
static void process_file(const fs::path &file_path, const fs::path &relative_path, const std::string &source_code, std::function< void(const FunctionData &)> callback, SkipStats &stats)
Configuration management interface.
Main function extraction interface.
Granularity
Comparison granularity used when breaking the codebase.
Provides access to function storage locations.
void write_file(const fs::path &path, const std::string &content)
Writes content to a file at specified path.
std::string read_file(const fs::path &path)
Reads a file into string.
Defines utility functions used across all files.