From c1b2699e5379a8e8a26069b3499a96f6cf61e1dd Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 6 Jun 2020 22:22:01 +0200 Subject: [PATCH] Simplification of FMouse::createMouseObject() --- ChangeLog | 1 + examples/opti-move.cpp | 6 ++--- src/fmouse.cpp | 42 +++----------------------------- src/fterm.cpp | 7 +++++- src/include/final/fapplication.h | 2 +- src/include/final/fmouse.h | 10 +++++++- src/include/final/fvterm.h | 2 +- src/include/final/fwidget.h | 2 +- 8 files changed, 25 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43fb315a..a63619fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2020-06-06 Markus Gans * Now, the terminal is not initialized before the method show() is called. Or you force it explicitly via the FApplication object. + * Simplification of FMouse::createMouseObject() 2020-05-30 Markus Gans * With the two new methods FApplication::setDarkTheme() and diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index f6d4d56e..5e931ace 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -216,7 +216,7 @@ int main (int argc, char* argv[]) // Pointer to the global virtual terminal object app = &term_app; - if ( app->isQuit() ) + if ( finalcut::FApplication::isQuit() ) return 0; // Get screen dimension @@ -267,14 +267,12 @@ int main (int argc, char* argv[]) std::cout << "\r" << line << std::flush; // Generation of a logger in a shared_ptr via a pointer finalcut::FApplication::setLog(std::make_shared()); - // Get the shared_ptr with the base class - std::shared_ptr log = finalcut::FApplication::getLog(); const finalcut::FOptiMove& opti_move = *finalcut::FTerm::getFOptiMove(); finalcut::printDurations(opti_move); - delete &log; // Waiting for keypress keyPressed(); app = nullptr; // End of term_app object scope + return 0; } diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 3cd8f6f2..996c2268 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -177,40 +177,6 @@ inline bool FMouse::isInputDataPending() return input_data_pending; } -//---------------------------------------------------------------------- -inline FMouse* FMouse::createMouseObject (const mouse_type mt) -{ - assert ( mt == FMouse::none - || mt == FMouse::gpm - || mt == FMouse::x11 - || mt == FMouse::sgr - || mt == FMouse::urxvt ); - - switch ( mt ) - { - case none: - return nullptr; - - case gpm: -#ifdef F_HAVE_LIBGPM - return new FMouseGPM; -#else - return nullptr; -#endif - - case x11: - return new FMouseX11; - - case sgr: - return new FMouseSGR; - - case urxvt: - return new FMouseUrxvt; - } - - return nullptr; -} - //---------------------------------------------------------------------- void FMouse::clearButtonState() { @@ -1216,12 +1182,12 @@ void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time) FMouseControl::FMouseControl() { #ifdef F_HAVE_LIBGPM - mouse_protocol[FMouse::gpm] = FMouse::createMouseObject(FMouse::gpm); + mouse_protocol[FMouse::gpm] = FMouse::createMouseObject(); #endif - mouse_protocol[FMouse::x11] = FMouse::createMouseObject(FMouse::x11); - mouse_protocol[FMouse::sgr] = FMouse::createMouseObject(FMouse::sgr); - mouse_protocol[FMouse::urxvt] = FMouse::createMouseObject(FMouse::urxvt); + mouse_protocol[FMouse::x11] = FMouse::createMouseObject(); + mouse_protocol[FMouse::sgr] = FMouse::createMouseObject(); + mouse_protocol[FMouse::urxvt] = FMouse::createMouseObject(); } //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index 4fd68cce..931d2463 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -2549,7 +2549,9 @@ void FTerm::terminalSizeChange() //---------------------------------------------------------------------- void FTerm::processTermination (int signum) { - init_term_object->finish(); + if ( init_term_object ) + init_term_object->finish(); + std::fflush (stderr); std::fflush (stdout); @@ -2562,6 +2564,9 @@ void FTerm::processTermination (int signum) printExitMessage(); } + if ( init_term_object ) + init_term_object->deallocationValues(); + std::terminate(); } diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 875a17eb..521ad2fa 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -129,7 +129,7 @@ class FApplication : public FWidget void sendQueuedEvents(); bool eventInQueue(); bool removeQueuedEvent (const FObject*); - void initTerminal(); + void initTerminal() override; static void setDefaultTheme(); static void setDarkTheme(); static void closeConfirmationDialog (FWidget*, FCloseEvent*); diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index e51cac00..8a747be0 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -130,7 +130,8 @@ class FMouse bool isInputDataPending(); // Methods - static FMouse* createMouseObject (const mouse_type); + template + static FMouse* createMouseObject (); void clearButtonState(); virtual void setRawData (FKeyboard::keybuffer&) = 0; virtual void processEvent (struct timeval*) = 0; @@ -191,6 +192,13 @@ class FMouse FPoint new_mouse_position{}; }; +//---------------------------------------------------------------------- +template +inline FMouse* FMouse::createMouseObject() +{ + return new ClassT; +} + #ifdef F_HAVE_LIBGPM //---------------------------------------------------------------------- diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index a6082c29..3d73c7eb 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -317,7 +317,7 @@ class FVTerm void processTerminalUpdate(); static void startTerminalUpdate(); static void finishTerminalUpdate(); - void initTerminal(); + virtual void initTerminal(); private: // Enumerations diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index d89f331b..f167405a 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -374,7 +374,7 @@ class FWidget : public FVTerm, public FObject void setTermOffsetWithPadding(); // Methods - void initTerminal(); + void initTerminal() override; void initDesktop(); virtual void adjustSize(); void adjustSizeGlobal();