-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrp_base_reporter_impl.cpp
More file actions
202 lines (150 loc) · 4.78 KB
/
rp_base_reporter_impl.cpp
File metadata and controls
202 lines (150 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "reporter/impl/rp_base_reporter_impl.hpp"
#include "reporter/api/rp_settings.hpp"
#include "reporter/resources/rp_report_resources.hpp"
#include "exception/ih/exc_internal_error.hpp"
#include <fmt/format.h>
#include <std_fs>
#include <string>
//------------------------------------------------------------------------------
namespace reporter {
//------------------------------------------------------------------------------
BaseReporterImpl::BaseReporterImpl( SettingsPtr && _settingsPtr )
: m_settings{ std::move( _settingsPtr ) }
{
}
//------------------------------------------------------------------------------
BaseReporterImpl::~BaseReporterImpl() = default;
//------------------------------------------------------------------------------
const Settings & BaseReporterImpl::getSettings() const
{
INTERNAL_CHECK_ERROR( m_settings );
return *m_settings;
}
//------------------------------------------------------------------------------
void BaseReporterImpl::copySettings( const Settings & _settings )
{
INTERNAL_CHECK_ERROR( m_settings );
m_settings->copy( _settings );
}
//------------------------------------------------------------------------------
size_t BaseReporterImpl::getMaxFilesCount() const
{
return getSettings().getMaxFilesCount();
}
//------------------------------------------------------------------------------
size_t BaseReporterImpl::getMaxDetailsCount() const
{
return getSettings().getMaxDetailsCount();
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::getShowStdFiles() const
{
return getSettings().getShowStdFiles();
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::getShowOnlyStdHeaders() const
{
return getSettings().getShowOnlyStdHeaders();
}
//------------------------------------------------------------------------------
std::string BaseReporterImpl::getPathWithoutProject(
const Path & _filePath,
const Path & _dirPath
)
{
if( _dirPath.empty() )
{
return _filePath.string();
}
if( !isFromSameDirectory( _filePath, _dirPath ) )
{
return _filePath.string();
}
Path result = stdfs::lexically_relative( _filePath, _dirPath );
if( ( !result.empty() ) )
{
return result.string();
}
return _filePath.string();
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::isFromSameDirectory(
const Path & _path1,
const Path & _path2
)
{
const Path root = _path1.root_path();
if( root != _path2.root_path() )
{
return false;
}
Path commonPath = getCommonPath( _path1, _path2 );
const bool result = commonPath != root;
return result;
}
//------------------------------------------------------------------------------
BaseReporterImpl::Path BaseReporterImpl::getCommonPath(
const Path & _path1,
const Path & _path2
)
{
Path resutl;
auto itCurrentFirst = _path1.begin();
auto itEndFirst = _path1.end();
auto itCurrentSecond = _path2.begin();
auto itEndSecond = _path2.end();
while(
itCurrentFirst != itEndFirst &&
itCurrentSecond != itEndSecond &&
*itCurrentFirst == *itCurrentSecond
)
{
resutl /= *itCurrentFirst;
++itCurrentFirst;
++itCurrentSecond;
}
return resutl;
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::isLimitFiles( CountType _currentNumber ) const
{
return isLimit( _currentNumber, getMaxFilesCount() );
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::isLimitFilesWithOriginSize(
CountType _currentNumber,
CountType _originSize
) const
{
return isLimitFiles( _currentNumber ) && _currentNumber - 1 != _originSize;
}
//------------------------------------------------------------------------------
void BaseReporterImpl::printFileLimitLine(
CountType _filesCount,
std::ostream & _stream
) const
{
const CountType limit = getMaxFilesCount();
_stream << fmt::format( resources::LimitLineFmt, limit, _filesCount );
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::isLimitDetails( CountType _currentNumber ) const
{
return isLimit( _currentNumber, getMaxDetailsCount() );
}
//------------------------------------------------------------------------------
void BaseReporterImpl::printDetailsLimitLine(
CountType _detailsCount,
std::ostream & _stream
) const
{
const CountType limit = getMaxDetailsCount();
_stream << fmt::format( resources::LimitDetailLineFmt, limit, _detailsCount );
}
//------------------------------------------------------------------------------
bool BaseReporterImpl::isLimit( CountType _currentNumber, CountType _limit )
{
return ( _limit > 0 ) && ( _currentNumber > _limit );
}
//------------------------------------------------------------------------------
}