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);
finalcut::FWidget::setMainWidget(&dialog);
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();
}

View File

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

View File

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

View File

@ -37,7 +37,7 @@ FLog::FLog()
//----------------------------------------------------------------------
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);
std::stringstream str_stream;
// Print RFC 2822 date
const auto& tm = std::localtime(&t);
std::strftime(str, sizeof(str), "%a, %d %b %Y %T %z", tm);
struct tm time{};
localtime_r (&t, &time);
std::strftime (str, sizeof(str), "%a, %d %b %Y %T %z", &time);
return std::string(str);
}

View File

@ -288,7 +288,15 @@ void FLoggerTest::fileTest()
if ( file_stream.is_open() )
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");
}
}
//----------------------------------------------------------------------