19 #ifndef GEOS_COMMON_FORMAT_LOGPART_HPP
20 #define GEOS_COMMON_FORMAT_LOGPART_HPP
23 #include "common/format/Format.hpp"
29 using namespace stringutilities;
50 template<
typename ... Args >
51 void addDescription(
string_view name, Args
const & ... args );
65 template<
typename ... Args >
66 void addEndDescription(
string_view name, Args
const & ... args );
90 void begin( std::ostream & os = std::cout );
96 void end( std::ostream & oss = std::cout );
103 { m_enableOutput = enabled; }
123 struct FormattedDescription
128 stdVector< string > m_lines;
130 size_t m_maxNameWidth;
132 size_t m_maxValueWidth;
135 Description m_startDescription = { {}, {} };
136 Description m_endDescription = { {}, {} };
138 FormattedDescription m_formattedStartDescription = {
"", {}, 0, 0 };
139 FormattedDescription m_formattedEndDescription = {
"", {}, 0, 0 };
142 size_t m_width = 100;
144 size_t m_minWidth = 100;
146 size_t m_maxWidth = 100;
148 static constexpr
size_t m_borderMargin = 2;
150 static constexpr
size_t m_nbBorderChar = 2;
152 char const m_borderCharacter =
'#';
154 static constexpr
string_view m_prefixEndTitle =
"End of ";
158 bool m_enableOutput =
true;
167 template<
typename ... Args >
168 void addDescriptionBySection( Description & description, FormattedDescription & formattedDescription,
176 void formatDescriptions( LogPart::Description & description,
177 FormattedDescription & formattedDescription );
183 string outputTitle( FormattedDescription & formattedDescription );
189 string outputDescription( FormattedDescription & formattedDescription );
192 template<
typename ... Args >
193 void LogPart::addDescriptionBySection( Description & description, FormattedDescription & formattedDescription,
196 stdVector< string > values;
197 size_t & formattedDescriptionMaxWidth = formattedDescription.m_maxValueWidth;
198 size_t & formattedDescriptionNameWidth = formattedDescription.m_maxNameWidth;
200 static_assert( has_formatter_v< decltype(args) >,
201 "Argument passed cannot be converted to string" );
202 string const value = GEOS_FMT(
"{}", args );
204 stdVector< string_view > dividedDescriptionValues =
205 divideLines< string_view >( formattedDescriptionMaxWidth, value );
206 values.insert( values.end(), dividedDescriptionValues.begin(), dividedDescriptionValues.end() );
209 description.m_values.push_back( values );
211 size_t nameWidth = 0;
212 stdVector< string > nameLines = divideLines< string >( nameWidth, name );
214 nameWidth = name.size();
215 formattedDescriptionNameWidth = std::max( formattedDescriptionNameWidth, nameWidth );
217 description.m_names.push_back( nameLines );
219 size_t const totalDecorationWidth = m_nbBorderChar * 2 + m_borderMargin * 2;
220 size_t const logPartTotalWidth = formattedDescriptionNameWidth +
221 formattedDescriptionMaxWidth +
222 totalDecorationWidth;
223 m_width = std::max( m_width, logPartTotalWidth );
224 m_width = std::max( m_width, formattedDescription.m_title.size());
227 template<
typename ... Args >
230 addDescriptionBySection( m_startDescription, m_formattedStartDescription, name, args ... );
233 template<
typename ... Args >
236 addDescriptionBySection( m_endDescription, m_formattedEndDescription, name, args ... );
Class for displaying section for different steps of simulation.
void addDescription(string_view description)
Add a description to the top logPart. No specific format will be apply the this description.
void setMinWidth(size_t const &minWidth)
Set the minimal width of the LogPart.
void addEndDescription(string_view name, Args const &... args)
Add a description to the bottom logPart by concatening a description name and descriptions values.
void addDescription(string_view name, Args const &... args)
Add a description to the top LogPart.
void enableOutput(bool enabled)
Toggles the CSV output feature.
void end(std::ostream &oss=std::cout)
Draw the last part of the logPart. It include the title and optionnaly the end description(s).
void begin(std::ostream &os=std::cout)
Draw the first part of the logPart. It include the title and optionnaly the description(s).
LogPart(string_view logPartTitle, bool enableOutput)
Initialize a LogPart given a title.
void setMaxWidth(size_t const &maxWidth)
Set the maximal width of the LogPart.
void addEndDescription(string_view description)
Add a description to the top logPart. No specific format will be apply the this description.
std::string_view string_view
String type.
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector