| 3864 | }; |
| 3865 | |
| 3866 | class SnippetFactory { |
| 3867 | public: |
| 3868 | typedef SourceFile::lines_t lines_t; |
| 3869 | |
| 3870 | lines_t get_snippet(const std::string& filename, unsigned line_start, unsigned context_size) |
| 3871 | { |
| 3872 | |
| 3873 | SourceFile& src_file = get_src_file(filename); |
| 3874 | unsigned start = line_start - context_size / 2; |
| 3875 | return src_file.get_lines(start, context_size); |
| 3876 | } |
| 3877 | |
| 3878 | lines_t get_combined_snippet( |
| 3879 | const std::string& filename_a, |
| 3880 | unsigned line_a, |
| 3881 | const std::string& filename_b, |
| 3882 | unsigned line_b, |
| 3883 | unsigned context_size) |
| 3884 | { |
| 3885 | SourceFile& src_file_a = get_src_file(filename_a); |
| 3886 | SourceFile& src_file_b = get_src_file(filename_b); |
| 3887 | |
| 3888 | lines_t lines = src_file_a.get_lines(line_a - context_size / 4, context_size / 2); |
| 3889 | src_file_b.get_lines(line_b - context_size / 4, context_size / 2, lines); |
| 3890 | return lines; |
| 3891 | } |
| 3892 | |
| 3893 | lines_t get_coalesced_snippet(const std::string& filename, unsigned line_a, unsigned line_b, unsigned context_size) |
| 3894 | { |
| 3895 | SourceFile& src_file = get_src_file(filename); |
| 3896 | |
| 3897 | using std::max; |
| 3898 | using std::min; |
| 3899 | unsigned a = min(line_a, line_b); |
| 3900 | unsigned b = max(line_a, line_b); |
| 3901 | |
| 3902 | if ((b - a) < (context_size / 3)) { |
| 3903 | return src_file.get_lines((a + b - context_size + 1) / 2, context_size); |
| 3904 | } |
| 3905 | |
| 3906 | lines_t lines = src_file.get_lines(a - context_size / 4, context_size / 2); |
| 3907 | src_file.get_lines(b - context_size / 4, context_size / 2, lines); |
| 3908 | return lines; |
| 3909 | } |
| 3910 | |
| 3911 | private: |
| 3912 | typedef details::hashtable<std::string, SourceFile>::type src_files_t; |
| 3913 | src_files_t _src_files; |
| 3914 | |
| 3915 | SourceFile& get_src_file(const std::string& filename) |
| 3916 | { |
| 3917 | src_files_t::iterator it = _src_files.find(filename); |
| 3918 | if (it != _src_files.end()) { |
| 3919 | return it->second; |
| 3920 | } |
| 3921 | SourceFile& new_src_file = _src_files[filename]; |
| 3922 | new_src_file = SourceFile(filename); |
| 3923 | return new_src_file; |
nothing calls this directly
no test coverage detected