A little more clean code

This commit is contained in:
Markus Gans 2020-05-14 01:22:45 +02:00
parent 923822ca25
commit 379c45efb5
7 changed files with 40 additions and 46 deletions

View File

@ -225,20 +225,6 @@ int main (int argc, char* argv[])
Background dialog(&app); Background dialog(&app);
finalcut::FWidget::setMainWidget(&dialog); finalcut::FWidget::setMainWidget(&dialog);
dialog.show(); dialog.show();
//-------------------------------------------------
std::cout << "\r\n" << std::flush;
finalcut::FLog& log = *finalcut::FApplication::getLog();
//std::ofstream file_stream("test.log", std::ofstream::out | std::ofstream::app);
//log.setLineEnding (finalcut::FLog::LF);
//log.setOutputStream(file_stream);
log.info("test1");
log.warn("test2");
log << finalcut::FLog::Error << "streaming " << "test 1" << std::flush;
log.enableTimestamp();
log << finalcut::FLog::Debug << "streaming test 2";
//-------------------------------------------------
return app.exec(); return app.exec();
} }

View File

@ -59,7 +59,8 @@ class EventDialog final : public finalcut::FDialog
private: private:
// Methods // Methods
finalcut::FString getMouseButtonName (int); finalcut::FString getMouseButtonName (int);
void logMouseEvent (finalcut::FString, finalcut::FMouseEvent&); void logMouseEvent ( const finalcut::FString&
, const finalcut::FMouseEvent& );
// Event handlers // Event handlers
void onClose (finalcut::FCloseEvent*) override; void onClose (finalcut::FCloseEvent*) override;
@ -75,7 +76,6 @@ class EventDialog final : public finalcut::FDialog
void onWindowRaised (finalcut::FEvent*) override; void onWindowRaised (finalcut::FEvent*) override;
void onWindowLowered (finalcut::FEvent*) override; void onWindowLowered (finalcut::FEvent*) override;
private:
// Data members // Data members
finalcut::FLog& log{*finalcut::FApplication::getLog()}; finalcut::FLog& log{*finalcut::FApplication::getLog()};
finalcut::FLabel label{this}; finalcut::FLabel label{this};
@ -124,8 +124,8 @@ finalcut::FString EventDialog::getMouseButtonName (int btn_state)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void EventDialog::logMouseEvent ( finalcut::FString state void EventDialog::logMouseEvent ( const finalcut::FString& state
, finalcut::FMouseEvent& ev ) , const finalcut::FMouseEvent& ev )
{ {
const int mouse_x = ev.getX(); const int mouse_x = ev.getX();
const int mouse_y = ev.getY(); const int mouse_y = ev.getY();
@ -273,8 +273,8 @@ EventLog::EventLog (finalcut::FWidget* parent)
// (CERT, OOP50-CPP) // (CERT, OOP50-CPP)
FDialog::setText ("Event log"); FDialog::setText ("Event log");
FDialog::setGeometry (FPoint{4, 16}, FSize{75, 8}); FDialog::setGeometry (FPoint{4, 16}, FSize{75, 8});
FDialog::setResizeable();
setMinimumSize (FSize{75, 5}); setMinimumSize (FSize{75, 5});
setResizeable();
setShadow(); setShadow();
scrollText.ignorePadding(); scrollText.ignorePadding();
scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});

View File

@ -224,15 +224,15 @@ void streamToInterger()
finalcut::FString("-321") >> stream_int; finalcut::FString("-321") >> stream_int;
std::cout << "stream out: " << stream_int << std::endl; std::cout << "stream out: " << stream_int << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -248,15 +248,15 @@ void streamToUnsignedInterger()
finalcut::FString("123") >> stream_uint; finalcut::FString("123") >> stream_uint;
std::cout << "stream out: " << stream_uint << std::endl; std::cout << "stream out: " << stream_uint << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -272,15 +272,15 @@ void streamToDouble()
finalcut::FString("0.123456e+2") >> stream_double; finalcut::FString("0.123456e+2") >> stream_double;
std::cout << "stream out: " << stream_double << std::endl; std::cout << "stream out: " << stream_double << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -296,15 +296,15 @@ void streamToFloat()
finalcut::FString("0.123e-3") >> stream_float; finalcut::FString("0.123e-3") >> stream_float;
std::cout << "stream out: " << stream_float << std::endl; std::cout << "stream out: " << stream_float << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -496,15 +496,15 @@ void convertToNumberExample()
const uLong ulong_num = finalcut::FString("123456789").toULong(); const uLong ulong_num = finalcut::FString("123456789").toULong();
std::cout << " toULong: " << ulong_num << std::endl; std::cout << " toULong: " << ulong_num << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -515,15 +515,15 @@ void convertToNumberExample()
const long long_num = finalcut::FString("-9876543210").toLong(); const long long_num = finalcut::FString("-9876543210").toLong();
std::cout << " toLong: " << long_num << std::endl; std::cout << " toLong: " << long_num << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -540,15 +540,15 @@ void convertToNumberExample()
<< double_num << std::endl; << double_num << std::endl;
std::cout.flags(save_flags); std::cout.flags(save_flags);
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
finalcut::FApplication::getLog()->error("Underflow"); finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
finalcut::FApplication::getLog()->error("Overflow"); finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
finalcut::FApplication::getLog()->error("Arithmetic error"); finalcut::FApplication::getLog()->error("Arithmetic error");
} }
@ -660,7 +660,7 @@ void indexExample()
, char(index[0]) , char(index[0])
, char(index[4]) ); , char(index[4]) );
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range&)
{ {
finalcut::FApplication::getLog()->error("Out of Range"); finalcut::FApplication::getLog()->error("Out of Range");
} }

View File

@ -632,7 +632,6 @@ void FComboBox::cb_setInputField (const FWidget*, const FDataPtr)
input_field = list.getItem(index).getText(); input_field = list.getItem(index).getText();
input_field.redraw(); input_field.redraw();
processChanged(); processChanged();
std::cout << "\r\n";
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -37,7 +37,7 @@ FLog::FLog()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLog::~FLog() // destructor FLog::~FLog() // destructor
{ {
sync(); FLog::sync();
} }

View File

@ -63,8 +63,9 @@ const std::string FLogger::getTimeString()
const auto& t = std::chrono::system_clock::to_time_t(now); const auto& t = std::chrono::system_clock::to_time_t(now);
std::stringstream str_stream; std::stringstream str_stream;
// Print RFC 2822 date // Print RFC 2822 date
const auto& tm = std::localtime(&t); struct tm time{};
std::strftime(str, sizeof(str), "%a, %d %b %Y %T %z", tm); localtime_r (&t, &time);
std::strftime (str, sizeof(str), "%a, %d %b %Y %T %z", &time);
return std::string(str); return std::string(str);
} }

View File

@ -288,7 +288,15 @@ void FLoggerTest::fileTest()
if ( file_stream.is_open() ) if ( file_stream.is_open() )
file_stream.close(); file_stream.close();
remove("test.log"); // Delete file int ret = remove("test.log"); // Delete file
if ( ret == -1 )
{
finalcut::FLogger log{};
log.setOutputStream(std::cerr);
log.setLineEnding (finalcut::FLog::LF);
log.error("Cannot delete the test.log file");
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------