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; }
114 std::vector< std::vector< string > > m_names;
117 std::vector< std::vector< string > > m_values;
123 struct FormattedDescription
128 std::vector< 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 = SIZE_MAX;
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 std::vector< string > values;
197 size_t & maxValueSize = formattedDescription.m_maxValueWidth;
198 size_t & maxNameSize = 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 std::vector< string_view > splitValues = divideLines< string_view >( maxValueSize, value );
205 values.insert( values.end(), splitValues.begin(), splitValues.end() );
208 description.m_values.push_back( values );
210 size_t lineWidth = 0;
211 std::vector< string > nameDivided = divideLines< string >( lineWidth, name );
213 lineWidth = name.size();
214 maxNameSize = std::max( maxNameSize, lineWidth );
216 description.m_names.push_back( nameDivided );
218 size_t const formattingCharSize = m_nbBorderChar * 2 + m_borderMargin * 2;
219 size_t const currentTotalWidth = maxNameSize + maxValueSize + formattingCharSize;
220 m_width = std::max( m_width, currentTotalWidth );
221 m_width = std::max( m_width, formattedDescription.m_title.size());
224 template<
typename ... Args >
227 addDescriptionBySection( m_startDescription, m_formattedStartDescription, name, args ... );
230 template<
typename ... Args >
233 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.