diff --git a/ChangeLog b/ChangeLog index fc72c7cb..02f97c46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-09-25 Markus Gans + * std::clog now streams everything to the FLogger object + 2020-09-23 Markus Gans * Bugfix: empty FString() + wchar_t diff --git a/examples/7segment.cpp b/examples/7segment.cpp index 89991113..2a6876fd 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -68,8 +68,8 @@ class SegmentView final : public finalcut::FDialog // Data members std::map code{}; finalcut::FString line[3]{}; - finalcut::FLineEdit Input{"0123", this}; - finalcut::FButton Exit{"E&xit", this}; + finalcut::FLineEdit input{"0123", this}; + finalcut::FButton exit{"E&xit", this}; }; //---------------------------------------------------------------------- @@ -86,18 +86,18 @@ SegmentView::SegmentView (finalcut::FWidget* parent) hexEncoding(); // Input field - Input.setGeometry (FPoint(2, 2), FSize{12, 1}); - Input.setLabelText (L"&Hex value"); - Input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); - Input.setLabelOrientation(finalcut::FLineEdit::label_above); - Input.setMaxLength(9); - Input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); + input.setGeometry (FPoint(2, 2), FSize{12, 1}); + input.setLabelText (L"&Hex value"); + input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); + input.setLabelOrientation(finalcut::FLineEdit::label_above); + input.setMaxLength(9); + input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); // Exit button - Exit.setGeometry(FPoint{28, 11}, FSize{10, 1}); + exit.setGeometry(FPoint{28, 11}, FSize{10, 1}); // Add some function callbacks - Input.addCallback + input.addCallback ( "changed", [] (SegmentView& dialog) @@ -107,7 +107,7 @@ SegmentView::SegmentView (finalcut::FWidget* parent) std::ref(*this) ); - Exit.addCallback + exit.addCallback ( "clicked", finalcut::getFApplication(), @@ -206,7 +206,7 @@ void SegmentView::draw() setColor(fc::LightGray, fc::Black); finalcut::drawBorder(this, FRect(FPoint{3, 6}, FPoint{40, 11})); - for (auto&& ch : Input.getText().toUpper()) + for (auto&& ch : input.getText().toUpper()) { const FColorPair color{fc::LightRed, fc::Black}; get7Segment(ch); diff --git a/examples/busy.cpp b/examples/busy.cpp index 24e3bf22..281da6e7 100644 --- a/examples/busy.cpp +++ b/examples/busy.cpp @@ -89,13 +89,13 @@ Dialog::Dialog (FWidget* parent) void Dialog::adjustSize() { finalcut::FDialog::adjustSize(); - int X = int((getDesktopWidth() - getWidth()) / 2); - const int Y = 5; + int x = int((getDesktopWidth() - getWidth()) / 2); + const int y = 5; - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setPos (FPoint{X, Y}, false); + setPos (FPoint{x, y}, false); } //---------------------------------------------------------------------- diff --git a/examples/calculator.cpp b/examples/calculator.cpp index ae3f2b9f..156a5c96 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -36,7 +36,7 @@ using finalcut::FRect; using finalcut::FSize; using finalcut::FColorPair; -constexpr lDouble PI{3.141592653589793238L}; +constexpr lDouble pi_value{3.141592653589793238L}; //---------------------------------------------------------------------- @@ -233,13 +233,13 @@ class Calc final : public finalcut::FDialog finalcut::FString input{""}; button button_no[Calc::NUM_OF_BUTTONS]{}; - struct stack_data + struct StackData { lDouble term; char infix_operator; }; - std::stack bracket_stack{}; + std::stack bracket_stack{}; std::map > calculator_buttons{}; std::map key_map{}; }; @@ -703,14 +703,14 @@ void Calc::percent (lDouble& x) //---------------------------------------------------------------------- void Calc::pi (lDouble& x) { - x = PI; + x = pi_value; setDisplay(x); } //---------------------------------------------------------------------- void Calc::open_bracket (const lDouble&) { - const stack_data d{ a, infix_operator }; + const StackData d{ a, infix_operator }; bracket_stack.push(d); clearInfixOperator(); input = ""; @@ -726,7 +726,7 @@ void Calc::close_bracket (const lDouble&) calcInfixOperator(); setDisplay(a); - const stack_data d = bracket_stack.top(); + const StackData d = bracket_stack.top(); bracket_stack.pop(); b = d.term; infix_operator = d.infix_operator; @@ -835,11 +835,11 @@ void Calc::sine (lDouble& x) else { if ( arcus_mode ) - x = std::asin(x) * 180.0L / PI; + x = std::asin(x) * 180.0L / pi_value; else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 = 0 x = 0.0L; else - x = std::sin(x * PI / 180.0L); + x = std::sin(x * pi_value / 180.0L); } if ( errno == EDOM ) @@ -873,11 +873,11 @@ void Calc::cosine (lDouble& x) else { if ( arcus_mode ) - x = std::acos(x) * 180.0L / PI; + x = std::acos(x) * 180.0L / pi_value; else if ( std::fabs(std::fmod(x - 90.0L, 180.0L)) < LDBL_EPSILON ) // (x - 90) / 180 == 0 x = 0.0L; else - x = std::cos(x * PI / 180.0L); + x = std::cos(x * pi_value / 180.0L); } if ( errno == EDOM ) @@ -911,7 +911,7 @@ void Calc::tangent (lDouble& x) else { if ( arcus_mode ) - x = std::atan(x) * 180.0L / PI; + x = std::atan(x) * 180.0L / pi_value; else { // Test if (x / 180) != 0 and x / 90 == 0 @@ -921,7 +921,7 @@ void Calc::tangent (lDouble& x) else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 == 0 x = 0.0L; else - x = std::tan(x * PI / 180.0L); + x = std::tan(x * pi_value / 180.0L); } } diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 6304866a..07248adf 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -67,7 +67,7 @@ class CheckList final : public finalcut::FDialog void cb_showList(); // Data members - finalcut::FListView listView{this}; + finalcut::FListView listview{this}; finalcut::FStatusBar status_bar{this}; }; @@ -83,22 +83,22 @@ CheckList::CheckList (finalcut::FWidget* parent) FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5} , FSize{28 + nf_offset, 13} ); setShadow(); - listView.ignorePadding(); - listView.setGeometry ( FPoint{1 + int(nf_offset), 2} + listview.ignorePadding(); + listview.setGeometry ( FPoint{1 + int(nf_offset), 2} , FSize{getWidth() - nf_offset, getHeight() - 1} ); // Add columns to the view - listView.addColumn ("Item"); - listView.addColumn ("Priority", 9); + listview.addColumn ("Item"); + listview.addColumn ("Priority", 9); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::by_name); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::by_name); // Statusbar at the bottom finalcut::FString separator{}; separator << ' ' << fc::BoxDrawingsVertical << ' '; - listView.setStatusbarMessage ( finalcut::FString{} + listview.setStatusbarMessage ( finalcut::FString{} << " exit" << separator << " select an item" << separator << " see your pick list"); @@ -107,7 +107,7 @@ CheckList::CheckList (finalcut::FWidget* parent) populate(); // Add callback method - listView.addCallback + listview.addCallback ( "clicked", this, &CheckList::cb_showList @@ -138,7 +138,7 @@ void CheckList::populate() for (const auto& line : list) { const finalcut::FStringList string_line (&line[0], &line[0] + 2); - auto iter = listView.insert (string_line); + auto iter = listview.insert (string_line); auto item = static_cast(*iter); item->setCheckable(true); } @@ -170,10 +170,10 @@ void CheckList::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void CheckList::cb_showList() { - auto iter = listView.beginOfList(); + auto iter = listview.beginOfList(); finalcut::FString shopping_list{}; - while ( iter != listView.endOfList() ) + while ( iter != listview.endOfList() ) { const auto item = static_cast(*iter); diff --git a/examples/event-log.cpp b/examples/event-log.cpp index ee9284c8..a82db7fa 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -162,8 +162,10 @@ void EventDialog::onKeyPress (finalcut::FKeyEvent* ev) if ( key_name.isEmpty() ) key_name = wchar_t(key_id); - log << finalcut::FLog::Info - << "Key " << key_name << " (id " << key_id << ")" << std::flush; + // std::clog redirects all stream data to FLogger + std::clog << finalcut::FLog::Info + << "Key " << key_name + << " (id " << key_id << ")" << std::flush; finalcut::FDialog::onKeyPress(ev); } @@ -257,7 +259,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream void adjustSize() override; // Data members - finalcut::FTextView scrollText{this}; + finalcut::FTextView scrolltext{this}; EventDialog* event_dialog{new EventDialog(this)}; }; @@ -273,8 +275,8 @@ EventLog::EventLog (finalcut::FWidget* parent) FDialog::setResizeable(); setMinimumSize (FSize{75, 5}); setShadow(); - scrollText.ignorePadding(); - scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); + scrolltext.ignorePadding(); + scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); event_dialog->setFocus(); addTimer(250); // Starts the timer every 250 milliseconds } @@ -288,9 +290,9 @@ void EventLog::onTimer (finalcut::FTimerEvent*) { if ( ! str().empty() ) { - scrollText.append(str()); + scrolltext.append(str()); str(""); - scrollText.scrollToEnd(); + scrolltext.scrollToEnd(); redraw(); updateTerminal(); } @@ -306,7 +308,7 @@ void EventLog::onClose (finalcut::FCloseEvent* ev) void EventLog::adjustSize() { finalcut::FDialog::adjustSize(); - scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); + scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); } diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index e977d60d..c0912dc2 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -93,22 +93,22 @@ int main (int argc, char* argv[]) c_field.setGeometry (FPoint{11, 11}, FSize{4, 1}); // Create the button group - finalcut::FButtonGroup radioButtonGroup {"Sex", &dgl}; - radioButtonGroup.setGeometry(FPoint{2, 13}, FSize{13, 4}); + finalcut::FButtonGroup radiobutton_group {"Sex", &dgl}; + radiobutton_group.setGeometry(FPoint{2, 13}, FSize{13, 4}); // Create radio buttons - finalcut::FRadioButton male {"&Male", &radioButtonGroup}; - finalcut::FRadioButton female {"&Female", &radioButtonGroup}; + finalcut::FRadioButton male {"&Male", &radiobutton_group}; + finalcut::FRadioButton female {"&Female", &radiobutton_group}; male.setGeometry (FPoint{1, 1}, FSize{8, 1}); female.setGeometry (FPoint{1, 2}, FSize{10, 1}); // Create another button group - finalcut::FButtonGroup checkButtonGroup {"&Data options", &dgl}; - checkButtonGroup.setGeometry(FPoint{16, 13}, FSize{19, 4}); + finalcut::FButtonGroup checkbutton_group {"&Data options", &dgl}; + checkbutton_group.setGeometry(FPoint{16, 13}, FSize{19, 4}); // Create checkbox buttons - finalcut::FCheckBox check1 {"Save data", &checkButtonGroup}; - finalcut::FCheckBox check2 {"Encrypt data", &checkButtonGroup}; + finalcut::FCheckBox check1 {"Save data", &checkbutton_group}; + finalcut::FCheckBox check2 {"Encrypt data", &checkbutton_group}; check1.setGeometry (FPoint{1, 1}, FSize{13, 1}); check2.setGeometry (FPoint{1, 2}, FSize{16, 1}); check2.setDisable(); diff --git a/examples/listbox.cpp b/examples/listbox.cpp index 017b4f5a..3c5cef26 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -101,7 +101,7 @@ class Listbox final : public FDialog FListBox list1{this}; FListBox list2{this}; FListBox list3{this}; - FButton Quit{this}; + FButton quit{this}; }; //---------------------------------------------------------------------- @@ -151,11 +151,11 @@ Listbox::Listbox (FWidget* parent) list3.setText ("key: value"); // Quit button - Quit.setGeometry(FPoint{42, 12}, FSize{10, 1}); - Quit.setText (L"&Quit"); + quit.setGeometry(FPoint{42, 12}, FSize{10, 1}); + quit.setText (L"&Quit"); // Add quit button function callback - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), diff --git a/examples/listview.cpp b/examples/listview.cpp index 6f7c905a..c2587da4 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -62,8 +62,8 @@ class Listview final : public finalcut::FDialog void cb_showInMessagebox(); // Data members - finalcut::FListView listView{this}; - finalcut::FButton Quit{this}; + finalcut::FListView listview{this}; + finalcut::FButton quit{this}; }; //---------------------------------------------------------------------- @@ -71,44 +71,44 @@ Listview::Listview (finalcut::FWidget* parent) : finalcut::FDialog{parent} { // Set FListView geometry - listView.setGeometry(FPoint{2, 1}, FSize{33, 14}); + listview.setGeometry(FPoint{2, 1}, FSize{33, 14}); // Add columns to the view - listView.addColumn ("City"); - listView.addColumn ("Condition"); - listView.addColumn ("Temp."); - listView.addColumn ("Humidity"); - listView.addColumn ("Pressure", 10); + listview.addColumn ("City"); + listview.addColumn ("Condition"); + listview.addColumn ("Temp."); + listview.addColumn ("Humidity"); + listview.addColumn ("Pressure", 10); // Set right alignment for the third, fourth, and fifth column - listView.setColumnAlignment (3, fc::alignRight); - listView.setColumnAlignment (4, fc::alignRight); - listView.setColumnAlignment (5, fc::alignRight); + listview.setColumnAlignment (3, fc::alignRight); + listview.setColumnAlignment (4, fc::alignRight); + listview.setColumnAlignment (5, fc::alignRight); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::by_name); - listView.setColumnSortType (3, fc::by_number); - listView.setColumnSortType (4, fc::by_number); - listView.setColumnSortType (5, fc::by_number); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::by_name); + listview.setColumnSortType (3, fc::by_number); + listview.setColumnSortType (4, fc::by_number); + listview.setColumnSortType (5, fc::by_number); // Sort in ascending order by the 1st column - listView.setColumnSort (1, fc::ascending); + listview.setColumnSort (1, fc::ascending); // Sorting follows later automatically on insert(). // Otherwise you could start the sorting directly with sort() // Allways show the sort indicator (▼/▲) - listView.hideSortIndicator(false); + listview.hideSortIndicator(false); // Populate FListView with a list of items populate(); // Quit button - Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); - Quit.setText (L"&Quit"); + quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); + quit.setText (L"&Quit"); // Add some function callbacks - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), @@ -116,7 +116,7 @@ Listview::Listview (finalcut::FWidget* parent) this ); - listView.addCallback + listview.addCallback ( "clicked", this, &Listview::cb_showInMessagebox @@ -178,7 +178,7 @@ void Listview::populate() for (const auto& place : weather) { const finalcut::FStringList line (&place[0], &place[0] + 5); - listView.insert (line); + listview.insert (line); } } @@ -191,7 +191,7 @@ void Listview::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void Listview::cb_showInMessagebox() { - const auto& item = listView.getCurrentItem(); + const auto& item = listview.getCurrentItem(); finalcut::FMessageBox info ( "Weather in " + item->getText(1) , " Condition: " + item->getText(2) + "\n" "Temperature: " + item->getText(3) + "\n" diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index a9ef2794..faacd892 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -481,9 +481,9 @@ void stringSplittingExample() void fromatStringExample() { // Test: format a string with sprintf - finalcut::FString formatStr{""}; + finalcut::FString format_str{""}; std::cout << " formatted: " - << formatStr.sprintf("sqrt(%d) = %d", 16, 4) + << format_str.sprintf("sqrt(%d) = %d", 16, 4) << std::endl; } diff --git a/examples/termcap.cpp b/examples/termcap.cpp index bbe7f067..1c36835c 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -42,21 +42,21 @@ void string(); // struct data //---------------------------------------------------------------------- -struct data +struct Data { - struct alignas(alignof(std::string)) termcap_string + struct alignas(alignof(std::string)) TermcapString { const std::string name; const fc::termcaps cap; }; - static termcap_string strings[]; + static TermcapString strings[]; }; //---------------------------------------------------------------------- // struct data - string data array //---------------------------------------------------------------------- -data::termcap_string data::strings[] = +Data::TermcapString Data::strings[] = { { "t_bell", fc::t_bell }, { "t_erase_chars", fc::t_erase_chars }, @@ -285,7 +285,7 @@ void string() const finalcut::FTermcap::tcap_map (&tcap_strings)[] \ = finalcut::FTermcap::strings; - for (const auto& entry : data::strings) + for (const auto& entry : Data::strings) { const std::string name = entry.name; const fc::termcaps cap = entry.cap; diff --git a/examples/transparent.cpp b/examples/transparent.cpp index ac8d5644..38a9e988 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -256,12 +256,12 @@ void MainWindow::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void MainWindow::onTimer (finalcut::FTimerEvent*) { - wchar_t first_Char[2]; + wchar_t first_char[2]; std::size_t length = line1.getLength(); - first_Char[0] = line1[0]; - first_Char[1] = line2[0]; - line1 = line1.right(length - 1) + first_Char[0]; - line2 = line2.right(length - 1) + first_Char[1]; + first_char[0] = line1[0]; + first_char[1] = line2[0]; + line1 = line1.right(length - 1) + first_char[0]; + line2 = line2.right(length - 1) + first_char[1]; redraw(); flush(); } diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 438ab0f3..a0393b4a 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -33,7 +33,7 @@ using finalcut::FSize; // Function prototypes -sInt64 StringToNumber (const finalcut::FString&); +sInt64 stringToNumber (const finalcut::FString&); bool sortAscending (const finalcut::FObject*, const finalcut::FObject*); bool sortDescending (const finalcut::FObject*, const finalcut::FObject*); bool isLessThanInteger (const finalcut::FString&, const finalcut::FString&); @@ -44,13 +44,13 @@ bool isGreaterThanDouble (const finalcut::FString&, const finalcut::FString&); // non-member functions //---------------------------------------------------------------------- -sInt64 StringToNumber (const finalcut::FString& str) +sInt64 stringToNumber (const finalcut::FString& str) { // Cut off one character (because LONG_MAX = 2147483647) - auto NumString = str.left(str.getLength() - 1); - NumString = NumString.replace(",", ""); - NumString = NumString.replace('.', ""); - sInt64 number = sInt64(NumString.toLong()); + auto num_string = str.left(str.getLength() - 1); + num_string = num_string.replace(",", ""); + num_string = num_string.replace('.', ""); + sInt64 number = sInt64(num_string.toLong()); return number; } @@ -58,8 +58,8 @@ sInt64 StringToNumber (const finalcut::FString& str) inline bool isLessThanInteger ( const finalcut::FString& lhs , const finalcut::FString& rhs ) { - const sInt64 l_number = StringToNumber(lhs); - const sInt64 r_number = StringToNumber(rhs); + const sInt64 l_number = stringToNumber(lhs); + const sInt64 r_number = stringToNumber(rhs); return bool( l_number < r_number ); // lhs < rhs } @@ -77,8 +77,8 @@ inline bool isLessThanDouble ( const finalcut::FString& lhs inline bool isGreaterThanInteger ( const finalcut::FString& lhs , const finalcut::FString& rhs ) { - const sInt64 l_number = StringToNumber(lhs); - const sInt64 r_number = StringToNumber(rhs); + const sInt64 l_number = stringToNumber(lhs); + const sInt64 r_number = stringToNumber(rhs); return bool( l_number > r_number ); // lhs > rhs } @@ -168,8 +168,8 @@ class Treeview final : public finalcut::FDialog // Data members bool initialized{false}; - finalcut::FListView listView{this}; - finalcut::FButton Quit{this}; + finalcut::FListView listview{this}; + finalcut::FButton quit{this}; static TreeItem africa[]; static TreeItem asia[]; static TreeItem europe[]; @@ -329,26 +329,26 @@ Treeview::Treeview (finalcut::FWidget* parent) : finalcut::FDialog{parent} { // Set FListView geometry - listView.setGeometry(FPoint{2, 1}, FSize{53, 14}); + listview.setGeometry(FPoint{2, 1}, FSize{53, 14}); // Add columns to the view - listView.addColumn ("Name", 23); - listView.addColumn ("Population"); - listView.addColumn ("Density/km²"); + listview.addColumn ("Name", 23); + listview.addColumn ("Population"); + listview.addColumn ("Density/km²"); // Set right alignment for the second and third column - listView.setColumnAlignment (2, fc::alignRight); - listView.setColumnAlignment (3, fc::alignRight); + listview.setColumnAlignment (2, fc::alignRight); + listview.setColumnAlignment (3, fc::alignRight); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::user_defined); - listView.setColumnSortType (3, fc::user_defined); - listView.setUserAscendingCompare(sortAscending); - listView.setUserDescendingCompare(sortDescending); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::user_defined); + listview.setColumnSortType (3, fc::user_defined); + listview.setUserAscendingCompare(sortAscending); + listview.setUserDescendingCompare(sortDescending); // Activate tree view - listView.setTreeView(); + listview.setTreeView(); // Populate FListView with a list of items static TreeItem continent_list[] = @@ -367,23 +367,23 @@ Treeview::Treeview (finalcut::FWidget* parent) const TreeItem* country_list = continent.child_element; finalcut::FStringList continent_line ( continent.begin() , continent.end() ); - auto iter = listView.insert (continent_line); + auto iter = listview.insert (continent_line); while ( country_list && country_list->name ) { finalcut::FStringList country_line ( country_list->begin() , country_list->end() ); - listView.insert (country_line, iter); + listview.insert (country_line, iter); country_list++; } } - // Quit button - Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); - Quit.setText (L"&Quit"); + // quit button + quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); + quit.setText (L"&Quit"); // Callback function - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), @@ -403,17 +403,17 @@ void Treeview::adjustSize() { std::size_t h = getDesktopHeight() - 4; setHeight (h, false); - int X = int((getDesktopWidth() - getWidth()) / 2); + int x = int((getDesktopWidth() - getWidth()) / 2); - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setX (X, false); + setX (x, false); if ( initialized ) { - listView.setHeight (getHeight() - 6, false); - Quit.setY(int(getHeight()) - 4); + listview.setHeight (getHeight() - 6, false); + quit.setY(int(getHeight()) - 4); } finalcut::FDialog::adjustSize(); diff --git a/examples/ui.cpp b/examples/ui.cpp index a6638197..8f0b8a99 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -68,7 +68,7 @@ class ProgressDialog final : public finalcut::FDialog void cb_exit_bar(); // Data members - finalcut::FProgressbar progressBar{this}; + finalcut::FProgressbar progressbar{this}; finalcut::FButton reset{this}; finalcut::FButton more{this}; finalcut::FButton quit{this}; @@ -100,8 +100,8 @@ ProgressDialog::ProgressDialog (finalcut::FWidget* parent) quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false); quit.setDisable(); - progressBar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false); - //progressBar.setPercentage(78); + progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false); + //progressbar.setPercentage(78); reset.addCallback ( @@ -140,9 +140,9 @@ void ProgressDialog::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void ProgressDialog::onTimer (finalcut::FTimerEvent*) { - auto p = progressBar.getPercentage(); + auto p = progressbar.getPercentage(); p++; - progressBar.setPercentage(p); + progressbar.setPercentage(p); flush(); if ( p != 100 ) @@ -167,15 +167,15 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*) //---------------------------------------------------------------------- void ProgressDialog::cb_reset_bar() { - progressBar.reset(); + progressbar.reset(); } //---------------------------------------------------------------------- void ProgressDialog::cb_more_bar() { - auto p = progressBar.getPercentage(); + auto p = progressbar.getPercentage(); p++; - progressBar.setPercentage(p); + progressbar.setPercentage(p); } //---------------------------------------------------------------------- @@ -212,25 +212,25 @@ class TextWindow final : public finalcut::FDialog void adjustSize() override; // Data members - finalcut::FTextView scrollText{this}; + finalcut::FTextView scrolltext{this}; }; //---------------------------------------------------------------------- TextWindow::TextWindow (finalcut::FWidget* parent) : finalcut::FDialog{parent} { - scrollText.ignorePadding(); - scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); + scrolltext.ignorePadding(); + scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); setMinimumSize (FSize{51, 6}); - scrollText.setFocus(); - scrollText.insert(" -----------------------------------------------\n" + scrolltext.setFocus(); + scrolltext.insert(" -----------------------------------------------\n" " line 1\n" " -----------------------------------------------\n" " line 3\n" " line 4" , -1); - scrollText.replaceRange(" File viewer", 1, 1); - scrollText.deleteRange(3, 4); + scrolltext.replaceRange(" File viewer", 1, 1); + scrolltext.deleteRange(3, 4); } //---------------------------------------------------------------------- @@ -240,14 +240,14 @@ TextWindow::~TextWindow() // destructor //---------------------------------------------------------------------- void TextWindow::append (const finalcut::FString& str) { - scrollText.append(str); + scrolltext.append(str); } //---------------------------------------------------------------------- void TextWindow::adjustSize() { finalcut::FDialog::adjustSize(); - scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); + scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); } @@ -784,12 +784,12 @@ void MyDialog::adjustSize() { const auto h = getParentWidget()->getHeight() - 4; setHeight (h, false); - int X = int((getDesktopWidth() - getWidth()) / 2); + int x = int((getDesktopWidth() - getWidth()) / 2); - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setX (X, false); + setX (x, false); if ( initialized ) myList.setHeight (getHeight() - 3, false); diff --git a/examples/windows.cpp b/examples/windows.cpp index 1283e6f2..526a28f1 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -122,7 +122,7 @@ void SmallWindow::adjustSize() else { top_right_label = "zoom"; - bottom_label.setVisible(); + bottom_label.show(); } finalcut::FDialog::adjustSize(); diff --git a/src/Makefile.am b/src/Makefile.am index 6eb26cfc..b85607e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ libfinal_la_SOURCES = \ fbutton.cpp \ fbuttongroup.cpp \ fcallback.cpp \ + fdata.cpp \ ftogglebutton.cpp \ fradiobutton.cpp \ fcheckbox.cpp \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 00547773..fef6c695 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -13,6 +13,7 @@ INCLUDE_HEADERS = \ fbuttongroup.h \ fbutton.h \ fcallback.h \ + fdata.h \ fcolorpair.h \ fstyle.h \ ftogglebutton.h \ @@ -93,6 +94,7 @@ OBJS = \ fsize.o \ frect.o \ fcallback.o \ + fdata.o \ fscrollbar.o \ fprogressbar.o \ flineedit.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 6ab87c5b..885996af 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -13,6 +13,7 @@ INCLUDE_HEADERS = \ fbuttongroup.h \ fbutton.h \ fcallback.h \ + fdata.h \ fcolorpair.h \ fstyle.h \ ftogglebutton.h \ @@ -93,6 +94,7 @@ OBJS = \ fsize.o \ frect.o \ fcallback.o \ + fdata.o \ fscrollbar.o \ fprogressbar.o \ flineedit.o \ diff --git a/src/fapplication.cpp b/src/fapplication.cpp index ec644f0c..3d1bfd75 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -22,7 +22,9 @@ #include #include +#include #include +#include #include #include @@ -131,18 +133,28 @@ FWidget* FApplication::getKeyboardWidget() FApplication::FLogPtr& FApplication::getLog() { // Global logger object - static FLogPtr* logger = new FLogPtr(); + static FLogPtr* logger_ptr = new FLogPtr(); - if ( logger && logger->get() == nullptr ) - *logger = std::make_shared(); + if ( logger_ptr && logger_ptr->get() == nullptr ) + { + *logger_ptr = std::make_shared(); - return *logger; + // Set the logger as rdbuf of clog + std::clog.rdbuf(logger_ptr->get()); + } + + return *logger_ptr; } //---------------------------------------------------------------------- -void FApplication::setLog (const FLogPtr& logger) +void FApplication::setLog (const FLogPtr& log) { - getLog() = logger; + FLogPtr& logger = getLog(); + logger.reset(); + logger = log; + + // Set the logger as rdbuf of clog + std::clog.rdbuf(logger.get()); } //---------------------------------------------------------------------- @@ -586,6 +598,10 @@ void FApplication::showParameterUsage() //---------------------------------------------------------------------- inline void FApplication::destroyLog() { + // Reset the rdbuf of clog + std::clog.rdbuf(default_clog_rdbuf); + + // Delete the logger const FLogPtr* logger = &(getLog()); delete logger; } @@ -1354,4 +1370,13 @@ bool FApplication::isNextEventTimeout() return FObject::isTimeout (&time_last_event, next_event_wait); } + +// FLog non-member operators +//---------------------------------------------------------------------- +std::ostream& operator << (std::ostream& outstr, FLog::LogLevel l) +{ + *FApplication::getLog() << l; + return outstr; +} + } // namespace finalcut diff --git a/src/fcharmap.cpp b/src/fcharmap.cpp index ad782f45..06597bb1 100644 --- a/src/fcharmap.cpp +++ b/src/fcharmap.cpp @@ -159,7 +159,7 @@ uInt character[][fc::NUM_OF_ENCODINGS] = * (2) Only supported in use with newfont */ -const std::size_t lastCharItem = \ +constexpr std::size_t last_char_item = \ std::size_t((sizeof(character) / sizeof(character[0])) - 1); @@ -206,7 +206,7 @@ constexpr int vt100_key_to_utf8[][2] = {fc::vt100_key_diamond , fc::Bullet} // ◆ }; -const std::size_t lastKeyItem = \ +constexpr std::size_t last_key_item = \ std::size_t((sizeof(vt100_key_to_utf8) / sizeof(vt100_key_to_utf8[0])) - 1); @@ -470,11 +470,11 @@ constexpr wchar_t cp437_ucs[][2] = {0xff, 0x00a0} // no-break space }; -const std::size_t lastCP437Item = \ +constexpr std::size_t last_cp437_item = \ std::size_t((sizeof(cp437_ucs) / sizeof(cp437_ucs[0])) - 1); // Based on http://www.unicode.org/charts/PDF/UFF00.pdf -constexpr wchar_t halfWidth_fullWidth[][2] = +constexpr wchar_t halfwidth_fullwidth[][2] = { // Fullwidth ASCII variants {0x0020, 0x3000}, // ' ' -> ' ' @@ -712,8 +712,8 @@ constexpr wchar_t halfWidth_fullWidth[][2] = {0xffee, 0x25cb} // ○ -> ○ }; -const std::size_t lastHalfWidthItem = \ - std::size_t((sizeof(halfWidth_fullWidth) / sizeof(halfWidth_fullWidth[0])) - 1); +constexpr std::size_t last_halfwidth_item = \ + std::size_t((sizeof(halfwidth_fullwidth) / sizeof(halfwidth_fullwidth[0])) - 1); } // namespace fc diff --git a/src/fcombobox.cpp b/src/fcombobox.cpp index 3d16be66..8ee8ca44 100644 --- a/src/fcombobox.cpp +++ b/src/fcombobox.cpp @@ -29,7 +29,6 @@ #include "final/flabel.h" #include "final/flineedit.h" #include "final/flistbox.h" -#include "final/flog.h" #include "final/fmouse.h" #include "final/fpoint.h" #include "final/fsize.h" diff --git a/src/fdata.cpp b/src/fdata.cpp new file mode 100644 index 00000000..f39345d9 --- /dev/null +++ b/src/fdata.cpp @@ -0,0 +1,42 @@ +/*********************************************************************** +* fdata.cpp - A general-purpose data wrapper * +* * +* This file is part of the FINAL CUT widget toolkit * +* * +* Copyright 2020 Markus Gans * +* * +* FINAL CUT is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Lesser General Public License as * +* published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* FINAL CUT is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include "final/fdata.h" + +namespace finalcut +{ + +//---------------------------------------------------------------------- +// class FDataAccess +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +FDataAccess::FDataAccess() +{ } + +//---------------------------------------------------------------------- +FDataAccess::~FDataAccess() // destructor +{ } + +} // namespace finalcut + diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 317b784e..e5556ebd 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -25,8 +25,8 @@ #include "final/fapplication.h" #include "final/fevent.h" #include "final/flabel.h" -#include "final/flog.h" #include "final/flineedit.h" +#include "final/flog.h" #include "final/fpoint.h" #include "final/fsize.h" #include "final/fstatusbar.h" @@ -833,8 +833,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } if ( input_width >= char_width ) @@ -857,8 +857,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -893,8 +893,8 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } idx++; @@ -927,8 +927,8 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -940,8 +940,8 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } diff --git a/src/fmenu.cpp b/src/fmenu.cpp index bc05b82f..3464a8b7 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -136,11 +136,8 @@ void FMenu::onKeyPress (FKeyEvent* ev) // looking for menu bar hotkey auto menu_bar = getMenuBar(); - if ( menu_bar ) - { - if ( menu_bar->hotkeyMenu(ev) ) - return; - } + if ( menu_bar && menu_bar->hotkeyMenu(ev) ) + return; switch ( ev->key() ) { diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 6f815346..5d87b8fb 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -24,7 +24,6 @@ #include "final/fapplication.h" #include "final/fc.h" -#include "final/flog.h" #include "final/foptimove.h" #include "final/ftermcap.h" @@ -1107,43 +1106,42 @@ void FOptiMove::moveByMethod ( int method //---------------------------------------------------------------------- void printDurations (const FOptiMove& om) { - finalcut::FLog& log = *FApplication::getLog(); - log << " speed: " - << om.baudrate << " baud" << std::flush; - log << " char_duration: " - << om.char_duration << " ms" << std::flush; - log << " cursor_home: " - << om.F_cursor_home.duration << " ms" << std::flush; - log << " cursor_to_ll: " - << om.F_cursor_to_ll.duration << " ms" << std::flush; - log << " carriage_return: " - << om.F_carriage_return.duration << " ms" << std::flush; - log << " tab: " - << om.F_tab.duration << " ms" << std::flush; - log << " back_tab: " - << om.F_back_tab.duration << " ms" << std::flush; - log << " cursor_up: " - << om.F_cursor_up.duration << " ms" << std::flush; - log << " cursor_down: " - << om.F_cursor_down.duration << " ms" << std::flush; - log << " cursor_left: " - << om.F_cursor_left.duration << " ms" << std::flush; - log << " cursor_right: " - << om.F_cursor_right.duration << " ms" << std::flush; - log << " cursor_address: " - << om.F_cursor_address.duration << " ms" << std::flush; - log << " column_address: " - << om.F_column_address.duration << " ms" << std::flush; - log << " row_address: " - << om.F_row_address.duration << " ms" << std::flush; - log << " parm_up_cursor: " - << om.F_parm_up_cursor.duration << " ms" << std::flush; - log << " parm_down_cursor: " - << om.F_parm_down_cursor.duration << " ms" << std::flush; - log << " parm_left_cursor: " - << om.F_parm_left_cursor.duration << " ms" << std::flush; - log << "parm_right_cursor: " - << om.F_parm_right_cursor.duration << " ms" << std::flush; + std::clog << " speed: " + << om.baudrate << " baud" << std::flush; + std::clog << " char_duration: " + << om.char_duration << " ms" << std::flush; + std::clog << " cursor_home: " + << om.F_cursor_home.duration << " ms" << std::flush; + std::clog << " cursor_to_ll: " + << om.F_cursor_to_ll.duration << " ms" << std::flush; + std::clog << " carriage_return: " + << om.F_carriage_return.duration << " ms" << std::flush; + std::clog << " tab: " + << om.F_tab.duration << " ms" << std::flush; + std::clog << " back_tab: " + << om.F_back_tab.duration << " ms" << std::flush; + std::clog << " cursor_up: " + << om.F_cursor_up.duration << " ms" << std::flush; + std::clog << " cursor_down: " + << om.F_cursor_down.duration << " ms" << std::flush; + std::clog << " cursor_left: " + << om.F_cursor_left.duration << " ms" << std::flush; + std::clog << " cursor_right: " + << om.F_cursor_right.duration << " ms" << std::flush; + std::clog << " cursor_address: " + << om.F_cursor_address.duration << " ms" << std::flush; + std::clog << " column_address: " + << om.F_column_address.duration << " ms" << std::flush; + std::clog << " row_address: " + << om.F_row_address.duration << " ms" << std::flush; + std::clog << " parm_up_cursor: " + << om.F_parm_up_cursor.duration << " ms" << std::flush; + std::clog << " parm_down_cursor: " + << om.F_parm_down_cursor.duration << " ms" << std::flush; + std::clog << " parm_left_cursor: " + << om.F_parm_left_cursor.duration << " ms" << std::flush; + std::clog << "parm_right_cursor: " + << om.F_parm_right_cursor.duration << " ms" << std::flush; } } // namespace finalcut diff --git a/src/fterm.cpp b/src/fterm.cpp index f896f6f3..430f66bf 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1191,7 +1191,7 @@ wchar_t FTerm::charEncode (wchar_t c, fc::encoding enc) { wchar_t ch_enc = c; - for (std::size_t i{0}; i <= fc::lastCharItem; i++) + for (std::size_t i{0}; i <= fc::last_char_item; i++) { if ( fc::character[i][fc::UTF8] == uInt(c) ) { @@ -1421,7 +1421,7 @@ void FTerm::init_alt_charset() }; // Update array 'character' with discovered VT100 pairs - for (std::size_t n{0}; n <= fc::lastKeyItem; n++ ) + for (std::size_t n{0}; n <= fc::last_key_item; n++ ) { const uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]); const uChar altChar = uChar(vt100_alt_char[keyChar]); @@ -1429,9 +1429,9 @@ void FTerm::init_alt_charset() const fc::encoding num{fc::NUM_OF_ENCODINGS}; uInt* p = std::find ( fc::character[0] - , fc::character[fc::lastCharItem] + num + , fc::character[fc::last_char_item] + num , utf8char ); - if ( p != fc::character[fc::lastCharItem] + num ) // found in character + if ( p != fc::character[fc::last_char_item] + num ) // found in character { const int item = int(std::distance(fc::character[0], p) / num); @@ -1506,7 +1506,7 @@ void FTerm::init_cygwin_charmap() return; // PC encoding changes - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) + for (std::size_t i{0}; i <= fc::last_char_item; i++ ) { if ( fc::character[i][fc::UTF8] == fc::BlackUpPointingTriangle ) // ▲ fc::character[i][fc::PC] = 0x18; @@ -1560,7 +1560,7 @@ void FTerm::init_teraterm_charmap() if ( ! isTeraTerm() ) return; - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) + for (std::size_t i{0}; i <= fc::last_char_item; i++ ) if ( fc::character[i][fc::PC] < 0x20 ) fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; } diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index 6f838725..19699705 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -274,7 +274,7 @@ wchar_t cp437_to_unicode (uChar c) constexpr std::size_t UNICODE = 1; wchar_t ucs = c; - for (std::size_t i{0}; i <= fc::lastCP437Item; i++) + for (std::size_t i{0}; i <= fc::last_cp437_item; i++) { if ( fc::cp437_ucs[i][CP437] == c ) // found { @@ -293,7 +293,7 @@ uChar unicode_to_cp437 (wchar_t ucs) constexpr std::size_t UNICODE = 1; uChar c{'?'}; - for (std::size_t i{0}; i <= fc::lastCP437Item; i++) + for (std::size_t i{0}; i <= fc::last_cp437_item; i++) { if ( fc::cp437_ucs[i][UNICODE] == ucs ) // found { @@ -322,10 +322,10 @@ const FString getFullWidth (const FString& str) } else { - for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++) + for (std::size_t i{0}; i <= fc::last_halfwidth_item; i++) { - if ( fc::halfWidth_fullWidth[i][HALF] == c ) // found - c = fc::halfWidth_fullWidth[i][FULL]; + if ( fc::halfwidth_fullwidth[i][HALF] == c ) // found + c = fc::halfwidth_fullwidth[i][FULL]; } } } @@ -350,10 +350,10 @@ const FString getHalfWidth (const FString& str) } else { - for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++) + for (std::size_t i{0}; i <= fc::last_halfwidth_item; i++) { - if ( fc::halfWidth_fullWidth[i][FULL] == c ) // found - c = fc::halfWidth_fullWidth[i][HALF]; + if ( fc::halfwidth_fullwidth[i][FULL] == c ) // found + c = fc::halfwidth_fullwidth[i][HALF]; } } } @@ -457,8 +457,8 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 8c695bc1..37e014f0 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -27,6 +27,7 @@ #include "final/emptyfstring.h" #include "final/fc.h" #include "final/fkey_map.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermdata.h" @@ -127,23 +128,22 @@ void FTermcap::termcapError (int status) static constexpr int no_entry = 0; static constexpr int db_not_found = -1; static constexpr int uninitialized = -2; - finalcut::FLog& log = *FApplication::getLog(); if ( status == no_entry || status == uninitialized ) { const char* termtype = fterm_data->getTermType(); - log << FLog::Error - << "Unknown terminal: \"" << termtype << "\". " - << "Check the TERM environment variable. " - << "Also make sure that the terminal " - << "is defined in the termcap/terminfo database." - << std::endl; + std::clog << FLog::Error + << "Unknown terminal: \"" << termtype << "\". " + << "Check the TERM environment variable. " + << "Also make sure that the terminal " + << "is defined in the termcap/terminfo database." + << std::endl; std::abort(); } else if ( status == db_not_found ) { - log << "The termcap/terminfo database could not be found." - << std::endl; + std::clog << "The termcap/terminfo database could not be found." + << std::endl; std::abort(); } } diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index 69edb8a9..6c4eb50e 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -171,7 +171,7 @@ void FTermFreeBSD::initCharMap() if ( ! isFreeBSDConsole() ) return; - for (std::size_t i{0}; i <= fc::lastCharItem; i++) + for (std::size_t i{0}; i <= fc::last_char_item; i++) if ( fc::character[i][fc::PC] < 0x1c ) fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; } @@ -195,11 +195,11 @@ void FTermFreeBSD::finish() //---------------------------------------------------------------------- void FTermFreeBSD::warnNotInitialized() { - *FApplication::getLog() << FLog::Warn - << "The FTermFreeBSD object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermFreeBSD object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 046de52b..5a775168 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -202,7 +202,7 @@ void FTermLinux::init() } else { - FApplication::getLog()->error("Can not open the console."); + std::clog << FLog::Error << "Can not open the console." << std::endl; std::abort(); } } @@ -217,7 +217,7 @@ void FTermLinux::initCharMap() if ( screen_unicode_map.entry_ct > 0 && screen_unicode_map.entries ) { - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) + for (std::size_t i{0}; i <= fc::last_char_item; i++ ) { const auto ucs = wchar_t(fc::character[i][fc::UTF8]); const sInt16 fontpos = getFontPos(ucs); diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 8d12b856..6b789543 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -162,11 +162,11 @@ bool FTermOpenBSD::resetBeep() //---------------------------------------------------------------------- void FTermOpenBSD::warnNotInitialized() { - *FApplication::getLog() << FLog::Warn - << "The FTermOpenBSD object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermOpenBSD object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 9c19ee5d..fe41dc2e 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -311,11 +311,11 @@ void FTermXTerminal::captureFontAndTitle() //---------------------------------------------------------------------- void FTermXTerminal::warnNotInitialized() const { - *FApplication::getLog() << FLog::Warn - << "The FTermXTerminal object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermXTerminal object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index b11cf9f8..27123bf6 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -35,7 +35,8 @@ #error "Only can be included directly." #endif -#include "final/fapplication.h" +#include + #include "final/flog.h" #include "final/fstring.h" diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index db7efbdb..5f3117c2 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -207,6 +207,7 @@ class FApplication : public FWidget char** app_argv{}; uInt64 key_timeout{100000}; // 100 ms uInt64 dblclick_interval{500000}; // 500 ms + std::streambuf* default_clog_rdbuf{std::clog.rdbuf()}; FEventQueue event_queue{}; static uInt64 next_event_wait; static timeval time_last_event; diff --git a/src/include/final/fcharmap.h b/src/include/final/fcharmap.h index 02caf1c2..79571fcd 100644 --- a/src/include/final/fcharmap.h +++ b/src/include/final/fcharmap.h @@ -37,16 +37,16 @@ namespace fc { extern uInt character[][fc::NUM_OF_ENCODINGS]; -extern const std::size_t lastCharItem; +extern const std::size_t last_char_item; extern const int vt100_key_to_utf8[][2]; -extern const std::size_t lastKeyItem; +extern const std::size_t last_key_item; extern const wchar_t cp437_ucs[][2]; -extern const std::size_t lastCP437Item; +extern const std::size_t last_cp437_item; -extern const wchar_t halfWidth_fullWidth[][2]; -extern const std::size_t lastHalfWidthItem; +extern const wchar_t halfwidth_fullwidth[][2]; +extern const std::size_t last_halfwidth_item; } // namespace fc diff --git a/src/include/final/fdata.h b/src/include/final/fdata.h index 91ed9984..64b3cd7f 100644 --- a/src/include/final/fdata.h +++ b/src/include/final/fdata.h @@ -57,9 +57,11 @@ class FData; // Class forward declaration class FDataAccess { public: + // Constructor + FDataAccess(); + // Destructor - virtual ~FDataAccess() - { } + virtual ~FDataAccess(); // Accessors virtual const FString getClassName() const @@ -101,7 +103,31 @@ class FData : public FDataAccess , value_ref{value} { } + FData (const FData& d) // Copy constructor + : value{d.value} + , value_ref{value} + { } + + FData (FData&& d) noexcept // Move constructor + : value{std::move(d.value)} + , value_ref{value} + { } + // Overloaded operators + FData& operator = (const FData& d) // Copy assignment operator (=) + { + value = d.value; + value_ref = value; + return *this; + } + + FData& operator = (FData&& d) noexcept // Move assignment operator (=) + { + value = std::move(d.value); + value_ref = value; + return *this; + } + T operator () () const { return value_ref; diff --git a/src/include/final/flog.h b/src/include/final/flog.h index 20da08b3..5fafbc83 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -108,6 +108,9 @@ class FLog : public std::stringbuf LineEnding end_of_line{CRLF}; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; std::ostream stream{this}; + + // Friend Non-member operator functions + friend std::ostream& operator << (std::ostream&, LogLevel); }; // FLog inline functions diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index 6aa4028a..bf2947ab 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -38,13 +38,13 @@ #define null nullptr -#define badAllocOutput(object_name) \ - *FApplication::getLog() << FLog::Error \ - << __FILE__ << ":" << __LINE__ \ - << ": Not enough memory to alloc " \ - << (object_name) \ - << " in " \ - << __func__ << std::endl; +#define badAllocOutput(object_name) \ + std::clog << FLog::Error \ + << __FILE__ << ":" << __LINE__ \ + << ": Not enough memory to alloc " \ + << (object_name) \ + << " in " \ + << __func__ << std::endl; typedef unsigned char uChar; typedef unsigned short uShort; diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index c62004af..546463bb 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -579,9 +579,9 @@ inline FVTerm& FVTerm::operator << (const std::string& string) //---------------------------------------------------------------------- inline FVTerm& FVTerm::operator << \ - (const std::vector& termString) + (const std::vector& term_string) { - print (termString); + print (term_string); return *this; } diff --git a/test/fdata-test.cpp b/test/fdata-test.cpp index 206cdc14..555b2ab5 100644 --- a/test/fdata-test.cpp +++ b/test/fdata-test.cpp @@ -35,16 +35,17 @@ //---------------------------------------------------------------------- // functions //---------------------------------------------------------------------- -/*void cb_function_ptr (int* value) +float my_function() { - (*value)++; + return 13.45F; } //---------------------------------------------------------------------- -void cb_function_ref (int& value) +long int my_function2 (long int i) { - value += 2; -}*/ + return 2 * i; +} + //---------------------------------------------------------------------- // class FDataTest diff --git a/test/flogger-test.cpp b/test/flogger-test.cpp index 21d91247..c3aee10c 100644 --- a/test/flogger-test.cpp +++ b/test/flogger-test.cpp @@ -316,6 +316,9 @@ void FLoggerTest::fileTest() //---------------------------------------------------------------------- void FLoggerTest::applicationObjectTest() { + // Save the rdbuf of clog + std::streambuf* default_clog_rdbuf = std::clog.rdbuf(); + // 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 @@ -348,6 +351,15 @@ void FLoggerTest::applicationObjectTest() CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" ); buf.str(""); // Clear buffer + // Logging to std::clog + std::clog << finalcut::FLog::Info << "test7" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[INFO] test7\r\n" ); + buf.str(""); // Clear buffer + + std::clog << finalcut::FLog::Warn << "test8" << std::endl; + CPPUNIT_ASSERT ( buf.str() == "[WARNING] test8\n\r\n" ); + buf.str(""); // Clear buffer + // Replace the logger with another one finalcut::FApplication::setLog(std::make_shared()); log = finalcut::FApplication::getLog(); @@ -369,8 +381,23 @@ void FLoggerTest::applicationObjectTest() CPPUNIT_ASSERT ( buf.str() == "Debug: myLogger 4\n" ); buf.str(""); // Clear buffer - std::shared_ptr* logger = &(finalcut::FApplication::getLog()); - delete logger; + // Logging to std::clog with the replaced logger + std::clog << finalcut::FLog::Info << "myLogger 5" << std::flush; + CPPUNIT_ASSERT ( buf.str() == " Info: myLogger 5\n" ); + buf.str(""); // Clear buffer + + std::clog << finalcut::FLog::Error << "myLogger 6" << std::endl; + CPPUNIT_ASSERT ( buf.str() == "Error: myLogger 6\n\n" ); + buf.str(""); // Clear buffer + + // Reset to the default rdbuf of clog + std::clog.rdbuf(default_clog_rdbuf); + + // Delete the global FApplication logger object + auto logger = &(finalcut::FApplication::getLog()); + + if ( logger ) + delete logger; } diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index a14a4f00..c5b51406 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -819,7 +819,7 @@ wchar_t ftermfreebsdTest::charEncode (wchar_t c) { wchar_t ch_enc{L'\0'}; - for (std::size_t i{0}; i <= finalcut::fc::lastCharItem; i++) + for (std::size_t i{0}; i <= finalcut::fc::last_char_item; i++) { if ( finalcut::fc::character[i][finalcut::fc::UTF8] == uInt(c) ) {