std::clog now streams everything to the FLogger object

This commit is contained in:
Markus Gans 2020-09-25 00:48:58 +02:00
parent a69d38fb1e
commit 3d9f621258
42 changed files with 420 additions and 290 deletions

View File

@ -1,3 +1,6 @@
2020-09-25 Markus Gans <guru.mail@muenster.de>
* std::clog now streams everything to the FLogger object
2020-09-23 Markus Gans <guru.mail@muenster.de> 2020-09-23 Markus Gans <guru.mail@muenster.de>
* Bugfix: empty FString() + wchar_t * Bugfix: empty FString() + wchar_t

View File

@ -68,8 +68,8 @@ class SegmentView final : public finalcut::FDialog
// Data members // Data members
std::map<wchar_t, sevenSegment> code{}; std::map<wchar_t, sevenSegment> code{};
finalcut::FString line[3]{}; finalcut::FString line[3]{};
finalcut::FLineEdit Input{"0123", this}; finalcut::FLineEdit input{"0123", this};
finalcut::FButton Exit{"E&xit", this}; finalcut::FButton exit{"E&xit", this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -86,18 +86,18 @@ SegmentView::SegmentView (finalcut::FWidget* parent)
hexEncoding(); hexEncoding();
// Input field // Input field
Input.setGeometry (FPoint(2, 2), FSize{12, 1}); input.setGeometry (FPoint(2, 2), FSize{12, 1});
Input.setLabelText (L"&Hex value"); input.setLabelText (L"&Hex value");
Input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)");
Input.setLabelOrientation(finalcut::FLineEdit::label_above); input.setLabelOrientation(finalcut::FLineEdit::label_above);
Input.setMaxLength(9); input.setMaxLength(9);
Input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); input.setInputFilter("[:.hHlLpPuU[:xdigit:]]");
// Exit button // Exit button
Exit.setGeometry(FPoint{28, 11}, FSize{10, 1}); exit.setGeometry(FPoint{28, 11}, FSize{10, 1});
// Add some function callbacks // Add some function callbacks
Input.addCallback input.addCallback
( (
"changed", "changed",
[] (SegmentView& dialog) [] (SegmentView& dialog)
@ -107,7 +107,7 @@ SegmentView::SegmentView (finalcut::FWidget* parent)
std::ref(*this) std::ref(*this)
); );
Exit.addCallback exit.addCallback
( (
"clicked", "clicked",
finalcut::getFApplication(), finalcut::getFApplication(),
@ -206,7 +206,7 @@ void SegmentView::draw()
setColor(fc::LightGray, fc::Black); setColor(fc::LightGray, fc::Black);
finalcut::drawBorder(this, FRect(FPoint{3, 6}, FPoint{40, 11})); 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}; const FColorPair color{fc::LightRed, fc::Black};
get7Segment(ch); get7Segment(ch);

View File

@ -89,13 +89,13 @@ Dialog::Dialog (FWidget* parent)
void Dialog::adjustSize() void Dialog::adjustSize()
{ {
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
int X = int((getDesktopWidth() - getWidth()) / 2); int x = int((getDesktopWidth() - getWidth()) / 2);
const int Y = 5; const int y = 5;
if ( X < 1 ) if ( x < 1 )
X = 1; x = 1;
setPos (FPoint{X, Y}, false); setPos (FPoint{x, y}, false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -36,7 +36,7 @@ using finalcut::FRect;
using finalcut::FSize; using finalcut::FSize;
using finalcut::FColorPair; 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{""}; finalcut::FString input{""};
button button_no[Calc::NUM_OF_BUTTONS]{}; button button_no[Calc::NUM_OF_BUTTONS]{};
struct stack_data struct StackData
{ {
lDouble term; lDouble term;
char infix_operator; char infix_operator;
}; };
std::stack<stack_data> bracket_stack{}; std::stack<StackData> bracket_stack{};
std::map<Calc::button, std::shared_ptr<Button> > calculator_buttons{}; std::map<Calc::button, std::shared_ptr<Button> > calculator_buttons{};
std::map<Calc::button, keyFunction> key_map{}; std::map<Calc::button, keyFunction> key_map{};
}; };
@ -703,14 +703,14 @@ void Calc::percent (lDouble& x)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::pi (lDouble& x) void Calc::pi (lDouble& x)
{ {
x = PI; x = pi_value;
setDisplay(x); setDisplay(x);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::open_bracket (const lDouble&) void Calc::open_bracket (const lDouble&)
{ {
const stack_data d{ a, infix_operator }; const StackData d{ a, infix_operator };
bracket_stack.push(d); bracket_stack.push(d);
clearInfixOperator(); clearInfixOperator();
input = ""; input = "";
@ -726,7 +726,7 @@ void Calc::close_bracket (const lDouble&)
calcInfixOperator(); calcInfixOperator();
setDisplay(a); setDisplay(a);
const stack_data d = bracket_stack.top(); const StackData d = bracket_stack.top();
bracket_stack.pop(); bracket_stack.pop();
b = d.term; b = d.term;
infix_operator = d.infix_operator; infix_operator = d.infix_operator;
@ -835,11 +835,11 @@ void Calc::sine (lDouble& x)
else else
{ {
if ( arcus_mode ) 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 else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 = 0
x = 0.0L; x = 0.0L;
else else
x = std::sin(x * PI / 180.0L); x = std::sin(x * pi_value / 180.0L);
} }
if ( errno == EDOM ) if ( errno == EDOM )
@ -873,11 +873,11 @@ void Calc::cosine (lDouble& x)
else else
{ {
if ( arcus_mode ) 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 else if ( std::fabs(std::fmod(x - 90.0L, 180.0L)) < LDBL_EPSILON ) // (x - 90) / 180 == 0
x = 0.0L; x = 0.0L;
else else
x = std::cos(x * PI / 180.0L); x = std::cos(x * pi_value / 180.0L);
} }
if ( errno == EDOM ) if ( errno == EDOM )
@ -911,7 +911,7 @@ void Calc::tangent (lDouble& x)
else else
{ {
if ( arcus_mode ) if ( arcus_mode )
x = std::atan(x) * 180.0L / PI; x = std::atan(x) * 180.0L / pi_value;
else else
{ {
// Test if (x / 180) != 0 and x / 90 == 0 // 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 else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 == 0
x = 0.0L; x = 0.0L;
else else
x = std::tan(x * PI / 180.0L); x = std::tan(x * pi_value / 180.0L);
} }
} }

View File

@ -67,7 +67,7 @@ class CheckList final : public finalcut::FDialog
void cb_showList(); void cb_showList();
// Data members // Data members
finalcut::FListView listView{this}; finalcut::FListView listview{this};
finalcut::FStatusBar status_bar{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} FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5}
, FSize{28 + nf_offset, 13} ); , FSize{28 + nf_offset, 13} );
setShadow(); setShadow();
listView.ignorePadding(); listview.ignorePadding();
listView.setGeometry ( FPoint{1 + int(nf_offset), 2} listview.setGeometry ( FPoint{1 + int(nf_offset), 2}
, FSize{getWidth() - nf_offset, getHeight() - 1} ); , FSize{getWidth() - nf_offset, getHeight() - 1} );
// Add columns to the view // Add columns to the view
listView.addColumn ("Item"); listview.addColumn ("Item");
listView.addColumn ("Priority", 9); listview.addColumn ("Priority", 9);
// Set the type of sorting // Set the type of sorting
listView.setColumnSortType (1, fc::by_name); listview.setColumnSortType (1, fc::by_name);
listView.setColumnSortType (2, fc::by_name); listview.setColumnSortType (2, fc::by_name);
// Statusbar at the bottom // Statusbar at the bottom
finalcut::FString separator{}; finalcut::FString separator{};
separator << ' ' << fc::BoxDrawingsVertical << ' '; separator << ' ' << fc::BoxDrawingsVertical << ' ';
listView.setStatusbarMessage ( finalcut::FString{} listview.setStatusbarMessage ( finalcut::FString{}
<< "<Q> exit" << separator << "<Q> exit" << separator
<< "<Space> select an item" << separator << "<Space> select an item" << separator
<< "<Enter> see your pick list"); << "<Enter> see your pick list");
@ -107,7 +107,7 @@ CheckList::CheckList (finalcut::FWidget* parent)
populate(); populate();
// Add callback method // Add callback method
listView.addCallback listview.addCallback
( (
"clicked", "clicked",
this, &CheckList::cb_showList this, &CheckList::cb_showList
@ -138,7 +138,7 @@ void CheckList::populate()
for (const auto& line : list) for (const auto& line : list)
{ {
const finalcut::FStringList string_line (&line[0], &line[0] + 2); 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<finalcut::FListViewItem*>(*iter); auto item = static_cast<finalcut::FListViewItem*>(*iter);
item->setCheckable(true); item->setCheckable(true);
} }
@ -170,10 +170,10 @@ void CheckList::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void CheckList::cb_showList() void CheckList::cb_showList()
{ {
auto iter = listView.beginOfList(); auto iter = listview.beginOfList();
finalcut::FString shopping_list{}; finalcut::FString shopping_list{};
while ( iter != listView.endOfList() ) while ( iter != listview.endOfList() )
{ {
const auto item = static_cast<finalcut::FListViewItem*>(*iter); const auto item = static_cast<finalcut::FListViewItem*>(*iter);

View File

@ -162,8 +162,10 @@ void EventDialog::onKeyPress (finalcut::FKeyEvent* ev)
if ( key_name.isEmpty() ) if ( key_name.isEmpty() )
key_name = wchar_t(key_id); key_name = wchar_t(key_id);
log << finalcut::FLog::Info // std::clog redirects all stream data to FLogger
<< "Key " << key_name << " (id " << key_id << ")" << std::flush; std::clog << finalcut::FLog::Info
<< "Key " << key_name
<< " (id " << key_id << ")" << std::flush;
finalcut::FDialog::onKeyPress(ev); finalcut::FDialog::onKeyPress(ev);
} }
@ -257,7 +259,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream
void adjustSize() override; void adjustSize() override;
// Data members // Data members
finalcut::FTextView scrollText{this}; finalcut::FTextView scrolltext{this};
EventDialog* event_dialog{new EventDialog(this)}; EventDialog* event_dialog{new EventDialog(this)};
}; };
@ -273,8 +275,8 @@ EventLog::EventLog (finalcut::FWidget* parent)
FDialog::setResizeable(); FDialog::setResizeable();
setMinimumSize (FSize{75, 5}); setMinimumSize (FSize{75, 5});
setShadow(); setShadow();
scrollText.ignorePadding(); scrolltext.ignorePadding();
scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
event_dialog->setFocus(); event_dialog->setFocus();
addTimer(250); // Starts the timer every 250 milliseconds addTimer(250); // Starts the timer every 250 milliseconds
} }
@ -288,9 +290,9 @@ void EventLog::onTimer (finalcut::FTimerEvent*)
{ {
if ( ! str().empty() ) if ( ! str().empty() )
{ {
scrollText.append(str()); scrolltext.append(str());
str(""); str("");
scrollText.scrollToEnd(); scrolltext.scrollToEnd();
redraw(); redraw();
updateTerminal(); updateTerminal();
} }
@ -306,7 +308,7 @@ void EventLog::onClose (finalcut::FCloseEvent* ev)
void EventLog::adjustSize() void EventLog::adjustSize()
{ {
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();
scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1));
} }

View File

@ -93,22 +93,22 @@ int main (int argc, char* argv[])
c_field.setGeometry (FPoint{11, 11}, FSize{4, 1}); c_field.setGeometry (FPoint{11, 11}, FSize{4, 1});
// Create the button group // Create the button group
finalcut::FButtonGroup radioButtonGroup {"Sex", &dgl}; finalcut::FButtonGroup radiobutton_group {"Sex", &dgl};
radioButtonGroup.setGeometry(FPoint{2, 13}, FSize{13, 4}); radiobutton_group.setGeometry(FPoint{2, 13}, FSize{13, 4});
// Create radio buttons // Create radio buttons
finalcut::FRadioButton male {"&Male", &radioButtonGroup}; finalcut::FRadioButton male {"&Male", &radiobutton_group};
finalcut::FRadioButton female {"&Female", &radioButtonGroup}; finalcut::FRadioButton female {"&Female", &radiobutton_group};
male.setGeometry (FPoint{1, 1}, FSize{8, 1}); male.setGeometry (FPoint{1, 1}, FSize{8, 1});
female.setGeometry (FPoint{1, 2}, FSize{10, 1}); female.setGeometry (FPoint{1, 2}, FSize{10, 1});
// Create another button group // Create another button group
finalcut::FButtonGroup checkButtonGroup {"&Data options", &dgl}; finalcut::FButtonGroup checkbutton_group {"&Data options", &dgl};
checkButtonGroup.setGeometry(FPoint{16, 13}, FSize{19, 4}); checkbutton_group.setGeometry(FPoint{16, 13}, FSize{19, 4});
// Create checkbox buttons // Create checkbox buttons
finalcut::FCheckBox check1 {"Save data", &checkButtonGroup}; finalcut::FCheckBox check1 {"Save data", &checkbutton_group};
finalcut::FCheckBox check2 {"Encrypt data", &checkButtonGroup}; finalcut::FCheckBox check2 {"Encrypt data", &checkbutton_group};
check1.setGeometry (FPoint{1, 1}, FSize{13, 1}); check1.setGeometry (FPoint{1, 1}, FSize{13, 1});
check2.setGeometry (FPoint{1, 2}, FSize{16, 1}); check2.setGeometry (FPoint{1, 2}, FSize{16, 1});
check2.setDisable(); check2.setDisable();

View File

@ -101,7 +101,7 @@ class Listbox final : public FDialog
FListBox list1{this}; FListBox list1{this};
FListBox list2{this}; FListBox list2{this};
FListBox list3{this}; FListBox list3{this};
FButton Quit{this}; FButton quit{this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -151,11 +151,11 @@ Listbox::Listbox (FWidget* parent)
list3.setText ("key: value"); list3.setText ("key: value");
// Quit button // Quit button
Quit.setGeometry(FPoint{42, 12}, FSize{10, 1}); quit.setGeometry(FPoint{42, 12}, FSize{10, 1});
Quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Add quit button function callback // Add quit button function callback
Quit.addCallback quit.addCallback
( (
"clicked", "clicked",
finalcut::getFApplication(), finalcut::getFApplication(),

View File

@ -62,8 +62,8 @@ class Listview final : public finalcut::FDialog
void cb_showInMessagebox(); void cb_showInMessagebox();
// Data members // Data members
finalcut::FListView listView{this}; finalcut::FListView listview{this};
finalcut::FButton Quit{this}; finalcut::FButton quit{this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -71,44 +71,44 @@ Listview::Listview (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Set FListView geometry // Set FListView geometry
listView.setGeometry(FPoint{2, 1}, FSize{33, 14}); listview.setGeometry(FPoint{2, 1}, FSize{33, 14});
// Add columns to the view // Add columns to the view
listView.addColumn ("City"); listview.addColumn ("City");
listView.addColumn ("Condition"); listview.addColumn ("Condition");
listView.addColumn ("Temp."); listview.addColumn ("Temp.");
listView.addColumn ("Humidity"); listview.addColumn ("Humidity");
listView.addColumn ("Pressure", 10); listview.addColumn ("Pressure", 10);
// Set right alignment for the third, fourth, and fifth column // Set right alignment for the third, fourth, and fifth column
listView.setColumnAlignment (3, fc::alignRight); listview.setColumnAlignment (3, fc::alignRight);
listView.setColumnAlignment (4, fc::alignRight); listview.setColumnAlignment (4, fc::alignRight);
listView.setColumnAlignment (5, fc::alignRight); listview.setColumnAlignment (5, fc::alignRight);
// Set the type of sorting // Set the type of sorting
listView.setColumnSortType (1, fc::by_name); listview.setColumnSortType (1, fc::by_name);
listView.setColumnSortType (2, fc::by_name); listview.setColumnSortType (2, fc::by_name);
listView.setColumnSortType (3, fc::by_number); listview.setColumnSortType (3, fc::by_number);
listView.setColumnSortType (4, fc::by_number); listview.setColumnSortType (4, fc::by_number);
listView.setColumnSortType (5, fc::by_number); listview.setColumnSortType (5, fc::by_number);
// Sort in ascending order by the 1st column // Sort in ascending order by the 1st column
listView.setColumnSort (1, fc::ascending); listview.setColumnSort (1, fc::ascending);
// Sorting follows later automatically on insert(). // Sorting follows later automatically on insert().
// Otherwise you could start the sorting directly with sort() // Otherwise you could start the sorting directly with sort()
// Allways show the sort indicator (▼/▲) // Allways show the sort indicator (▼/▲)
listView.hideSortIndicator(false); listview.hideSortIndicator(false);
// Populate FListView with a list of items // Populate FListView with a list of items
populate(); populate();
// Quit button // Quit button
Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
Quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Add some function callbacks // Add some function callbacks
Quit.addCallback quit.addCallback
( (
"clicked", "clicked",
finalcut::getFApplication(), finalcut::getFApplication(),
@ -116,7 +116,7 @@ Listview::Listview (finalcut::FWidget* parent)
this this
); );
listView.addCallback listview.addCallback
( (
"clicked", "clicked",
this, &Listview::cb_showInMessagebox this, &Listview::cb_showInMessagebox
@ -178,7 +178,7 @@ void Listview::populate()
for (const auto& place : weather) for (const auto& place : weather)
{ {
const finalcut::FStringList line (&place[0], &place[0] + 5); 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() void Listview::cb_showInMessagebox()
{ {
const auto& item = listView.getCurrentItem(); const auto& item = listview.getCurrentItem();
finalcut::FMessageBox info ( "Weather in " + item->getText(1) finalcut::FMessageBox info ( "Weather in " + item->getText(1)
, " Condition: " + item->getText(2) + "\n" , " Condition: " + item->getText(2) + "\n"
"Temperature: " + item->getText(3) + "\n" "Temperature: " + item->getText(3) + "\n"

View File

@ -481,9 +481,9 @@ void stringSplittingExample()
void fromatStringExample() void fromatStringExample()
{ {
// Test: format a string with sprintf // Test: format a string with sprintf
finalcut::FString formatStr{""}; finalcut::FString format_str{""};
std::cout << " formatted: " std::cout << " formatted: "
<< formatStr.sprintf("sqrt(%d) = %d", 16, 4) << format_str.sprintf("sqrt(%d) = %d", 16, 4)
<< std::endl; << std::endl;
} }

View File

@ -42,21 +42,21 @@ void string();
// struct data // struct data
//---------------------------------------------------------------------- //----------------------------------------------------------------------
struct data struct Data
{ {
struct alignas(alignof(std::string)) termcap_string struct alignas(alignof(std::string)) TermcapString
{ {
const std::string name; const std::string name;
const fc::termcaps cap; const fc::termcaps cap;
}; };
static termcap_string strings[]; static TermcapString strings[];
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// struct data - string data array // struct data - string data array
//---------------------------------------------------------------------- //----------------------------------------------------------------------
data::termcap_string data::strings[] = Data::TermcapString Data::strings[] =
{ {
{ "t_bell", fc::t_bell }, { "t_bell", fc::t_bell },
{ "t_erase_chars", fc::t_erase_chars }, { "t_erase_chars", fc::t_erase_chars },
@ -285,7 +285,7 @@ void string()
const finalcut::FTermcap::tcap_map (&tcap_strings)[] \ const finalcut::FTermcap::tcap_map (&tcap_strings)[] \
= finalcut::FTermcap::strings; = finalcut::FTermcap::strings;
for (const auto& entry : data::strings) for (const auto& entry : Data::strings)
{ {
const std::string name = entry.name; const std::string name = entry.name;
const fc::termcaps cap = entry.cap; const fc::termcaps cap = entry.cap;

View File

@ -256,12 +256,12 @@ void MainWindow::onShow (finalcut::FShowEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MainWindow::onTimer (finalcut::FTimerEvent*) void MainWindow::onTimer (finalcut::FTimerEvent*)
{ {
wchar_t first_Char[2]; wchar_t first_char[2];
std::size_t length = line1.getLength(); std::size_t length = line1.getLength();
first_Char[0] = line1[0]; first_char[0] = line1[0];
first_Char[1] = line2[0]; first_char[1] = line2[0];
line1 = line1.right(length - 1) + first_Char[0]; line1 = line1.right(length - 1) + first_char[0];
line2 = line2.right(length - 1) + first_Char[1]; line2 = line2.right(length - 1) + first_char[1];
redraw(); redraw();
flush(); flush();
} }

View File

@ -33,7 +33,7 @@ using finalcut::FSize;
// Function prototypes // Function prototypes
sInt64 StringToNumber (const finalcut::FString&); sInt64 stringToNumber (const finalcut::FString&);
bool sortAscending (const finalcut::FObject*, const finalcut::FObject*); bool sortAscending (const finalcut::FObject*, const finalcut::FObject*);
bool sortDescending (const finalcut::FObject*, const finalcut::FObject*); bool sortDescending (const finalcut::FObject*, const finalcut::FObject*);
bool isLessThanInteger (const finalcut::FString&, const finalcut::FString&); bool isLessThanInteger (const finalcut::FString&, const finalcut::FString&);
@ -44,13 +44,13 @@ bool isGreaterThanDouble (const finalcut::FString&, const finalcut::FString&);
// non-member functions // non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
sInt64 StringToNumber (const finalcut::FString& str) sInt64 stringToNumber (const finalcut::FString& str)
{ {
// Cut off one character (because LONG_MAX = 2147483647) // Cut off one character (because LONG_MAX = 2147483647)
auto NumString = str.left(str.getLength() - 1); auto num_string = str.left(str.getLength() - 1);
NumString = NumString.replace(",", ""); num_string = num_string.replace(",", "");
NumString = NumString.replace('.', ""); num_string = num_string.replace('.', "");
sInt64 number = sInt64(NumString.toLong()); sInt64 number = sInt64(num_string.toLong());
return number; return number;
} }
@ -58,8 +58,8 @@ sInt64 StringToNumber (const finalcut::FString& str)
inline bool isLessThanInteger ( const finalcut::FString& lhs inline bool isLessThanInteger ( const finalcut::FString& lhs
, const finalcut::FString& rhs ) , const finalcut::FString& rhs )
{ {
const sInt64 l_number = StringToNumber(lhs); const sInt64 l_number = stringToNumber(lhs);
const sInt64 r_number = StringToNumber(rhs); const sInt64 r_number = stringToNumber(rhs);
return bool( l_number < r_number ); // lhs < 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 inline bool isGreaterThanInteger ( const finalcut::FString& lhs
, const finalcut::FString& rhs ) , const finalcut::FString& rhs )
{ {
const sInt64 l_number = StringToNumber(lhs); const sInt64 l_number = stringToNumber(lhs);
const sInt64 r_number = StringToNumber(rhs); const sInt64 r_number = stringToNumber(rhs);
return bool( l_number > r_number ); // lhs > rhs return bool( l_number > r_number ); // lhs > rhs
} }
@ -168,8 +168,8 @@ class Treeview final : public finalcut::FDialog
// Data members // Data members
bool initialized{false}; bool initialized{false};
finalcut::FListView listView{this}; finalcut::FListView listview{this};
finalcut::FButton Quit{this}; finalcut::FButton quit{this};
static TreeItem africa[]; static TreeItem africa[];
static TreeItem asia[]; static TreeItem asia[];
static TreeItem europe[]; static TreeItem europe[];
@ -329,26 +329,26 @@ Treeview::Treeview (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Set FListView geometry // Set FListView geometry
listView.setGeometry(FPoint{2, 1}, FSize{53, 14}); listview.setGeometry(FPoint{2, 1}, FSize{53, 14});
// Add columns to the view // Add columns to the view
listView.addColumn ("Name", 23); listview.addColumn ("Name", 23);
listView.addColumn ("Population"); listview.addColumn ("Population");
listView.addColumn ("Density/km²"); listview.addColumn ("Density/km²");
// Set right alignment for the second and third column // Set right alignment for the second and third column
listView.setColumnAlignment (2, fc::alignRight); listview.setColumnAlignment (2, fc::alignRight);
listView.setColumnAlignment (3, fc::alignRight); listview.setColumnAlignment (3, fc::alignRight);
// Set the type of sorting // Set the type of sorting
listView.setColumnSortType (1, fc::by_name); listview.setColumnSortType (1, fc::by_name);
listView.setColumnSortType (2, fc::user_defined); listview.setColumnSortType (2, fc::user_defined);
listView.setColumnSortType (3, fc::user_defined); listview.setColumnSortType (3, fc::user_defined);
listView.setUserAscendingCompare(sortAscending); listview.setUserAscendingCompare(sortAscending);
listView.setUserDescendingCompare(sortDescending); listview.setUserDescendingCompare(sortDescending);
// Activate tree view // Activate tree view
listView.setTreeView(); listview.setTreeView();
// Populate FListView with a list of items // Populate FListView with a list of items
static TreeItem continent_list[] = static TreeItem continent_list[] =
@ -367,23 +367,23 @@ Treeview::Treeview (finalcut::FWidget* parent)
const TreeItem* country_list = continent.child_element; const TreeItem* country_list = continent.child_element;
finalcut::FStringList continent_line ( continent.begin() finalcut::FStringList continent_line ( continent.begin()
, continent.end() ); , continent.end() );
auto iter = listView.insert (continent_line); auto iter = listview.insert (continent_line);
while ( country_list && country_list->name ) while ( country_list && country_list->name )
{ {
finalcut::FStringList country_line ( country_list->begin() finalcut::FStringList country_line ( country_list->begin()
, country_list->end() ); , country_list->end() );
listView.insert (country_line, iter); listview.insert (country_line, iter);
country_list++; country_list++;
} }
} }
// Quit button // quit button
Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
Quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Callback function // Callback function
Quit.addCallback quit.addCallback
( (
"clicked", "clicked",
finalcut::getFApplication(), finalcut::getFApplication(),
@ -403,17 +403,17 @@ void Treeview::adjustSize()
{ {
std::size_t h = getDesktopHeight() - 4; std::size_t h = getDesktopHeight() - 4;
setHeight (h, false); setHeight (h, false);
int X = int((getDesktopWidth() - getWidth()) / 2); int x = int((getDesktopWidth() - getWidth()) / 2);
if ( X < 1 ) if ( x < 1 )
X = 1; x = 1;
setX (X, false); setX (x, false);
if ( initialized ) if ( initialized )
{ {
listView.setHeight (getHeight() - 6, false); listview.setHeight (getHeight() - 6, false);
Quit.setY(int(getHeight()) - 4); quit.setY(int(getHeight()) - 4);
} }
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();

View File

@ -68,7 +68,7 @@ class ProgressDialog final : public finalcut::FDialog
void cb_exit_bar(); void cb_exit_bar();
// Data members // Data members
finalcut::FProgressbar progressBar{this}; finalcut::FProgressbar progressbar{this};
finalcut::FButton reset{this}; finalcut::FButton reset{this};
finalcut::FButton more{this}; finalcut::FButton more{this};
finalcut::FButton quit{this}; finalcut::FButton quit{this};
@ -100,8 +100,8 @@ ProgressDialog::ProgressDialog (finalcut::FWidget* parent)
quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false); quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false);
quit.setDisable(); quit.setDisable();
progressBar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false); progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false);
//progressBar.setPercentage(78); //progressbar.setPercentage(78);
reset.addCallback reset.addCallback
( (
@ -140,9 +140,9 @@ void ProgressDialog::onShow (finalcut::FShowEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::onTimer (finalcut::FTimerEvent*) void ProgressDialog::onTimer (finalcut::FTimerEvent*)
{ {
auto p = progressBar.getPercentage(); auto p = progressbar.getPercentage();
p++; p++;
progressBar.setPercentage(p); progressbar.setPercentage(p);
flush(); flush();
if ( p != 100 ) if ( p != 100 )
@ -167,15 +167,15 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::cb_reset_bar() void ProgressDialog::cb_reset_bar()
{ {
progressBar.reset(); progressbar.reset();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::cb_more_bar() void ProgressDialog::cb_more_bar()
{ {
auto p = progressBar.getPercentage(); auto p = progressbar.getPercentage();
p++; p++;
progressBar.setPercentage(p); progressbar.setPercentage(p);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -212,25 +212,25 @@ class TextWindow final : public finalcut::FDialog
void adjustSize() override; void adjustSize() override;
// Data members // Data members
finalcut::FTextView scrollText{this}; finalcut::FTextView scrolltext{this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
TextWindow::TextWindow (finalcut::FWidget* parent) TextWindow::TextWindow (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
scrollText.ignorePadding(); scrolltext.ignorePadding();
scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
setMinimumSize (FSize{51, 6}); setMinimumSize (FSize{51, 6});
scrollText.setFocus(); scrolltext.setFocus();
scrollText.insert(" -----------------------------------------------\n" scrolltext.insert(" -----------------------------------------------\n"
" line 1\n" " line 1\n"
" -----------------------------------------------\n" " -----------------------------------------------\n"
" line 3\n" " line 3\n"
" line 4" " line 4"
, -1); , -1);
scrollText.replaceRange(" File viewer", 1, 1); scrolltext.replaceRange(" File viewer", 1, 1);
scrollText.deleteRange(3, 4); scrolltext.deleteRange(3, 4);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -240,14 +240,14 @@ TextWindow::~TextWindow() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void TextWindow::append (const finalcut::FString& str) void TextWindow::append (const finalcut::FString& str)
{ {
scrollText.append(str); scrolltext.append(str);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void TextWindow::adjustSize() void TextWindow::adjustSize()
{ {
finalcut::FDialog::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; const auto h = getParentWidget()->getHeight() - 4;
setHeight (h, false); setHeight (h, false);
int X = int((getDesktopWidth() - getWidth()) / 2); int x = int((getDesktopWidth() - getWidth()) / 2);
if ( X < 1 ) if ( x < 1 )
X = 1; x = 1;
setX (X, false); setX (x, false);
if ( initialized ) if ( initialized )
myList.setHeight (getHeight() - 3, false); myList.setHeight (getHeight() - 3, false);

View File

@ -122,7 +122,7 @@ void SmallWindow::adjustSize()
else else
{ {
top_right_label = "zoom"; top_right_label = "zoom";
bottom_label.setVisible(); bottom_label.show();
} }
finalcut::FDialog::adjustSize(); finalcut::FDialog::adjustSize();

View File

@ -20,6 +20,7 @@ libfinal_la_SOURCES = \
fbutton.cpp \ fbutton.cpp \
fbuttongroup.cpp \ fbuttongroup.cpp \
fcallback.cpp \ fcallback.cpp \
fdata.cpp \
ftogglebutton.cpp \ ftogglebutton.cpp \
fradiobutton.cpp \ fradiobutton.cpp \
fcheckbox.cpp \ fcheckbox.cpp \

View File

@ -13,6 +13,7 @@ INCLUDE_HEADERS = \
fbuttongroup.h \ fbuttongroup.h \
fbutton.h \ fbutton.h \
fcallback.h \ fcallback.h \
fdata.h \
fcolorpair.h \ fcolorpair.h \
fstyle.h \ fstyle.h \
ftogglebutton.h \ ftogglebutton.h \
@ -93,6 +94,7 @@ OBJS = \
fsize.o \ fsize.o \
frect.o \ frect.o \
fcallback.o \ fcallback.o \
fdata.o \
fscrollbar.o \ fscrollbar.o \
fprogressbar.o \ fprogressbar.o \
flineedit.o \ flineedit.o \

View File

@ -13,6 +13,7 @@ INCLUDE_HEADERS = \
fbuttongroup.h \ fbuttongroup.h \
fbutton.h \ fbutton.h \
fcallback.h \ fcallback.h \
fdata.h \
fcolorpair.h \ fcolorpair.h \
fstyle.h \ fstyle.h \
ftogglebutton.h \ ftogglebutton.h \
@ -93,6 +94,7 @@ OBJS = \
fsize.o \ fsize.o \
frect.o \ frect.o \
fcallback.o \ fcallback.o \
fdata.o \
fscrollbar.o \ fscrollbar.o \
fprogressbar.o \ fprogressbar.o \
flineedit.o \ flineedit.o \

View File

@ -22,7 +22,9 @@
#include <chrono> #include <chrono>
#include <fstream> #include <fstream>
#include <iostream>
#include <memory> #include <memory>
#include <ostream>
#include <string> #include <string>
#include <thread> #include <thread>
@ -131,18 +133,28 @@ FWidget* FApplication::getKeyboardWidget()
FApplication::FLogPtr& FApplication::getLog() FApplication::FLogPtr& FApplication::getLog()
{ {
// Global logger object // Global logger object
static FLogPtr* logger = new FLogPtr(); static FLogPtr* logger_ptr = new FLogPtr();
if ( logger && logger->get() == nullptr ) if ( logger_ptr && logger_ptr->get() == nullptr )
*logger = std::make_shared<FLogger>(); {
*logger_ptr = std::make_shared<FLogger>();
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() inline void FApplication::destroyLog()
{ {
// Reset the rdbuf of clog
std::clog.rdbuf(default_clog_rdbuf);
// Delete the logger
const FLogPtr* logger = &(getLog()); const FLogPtr* logger = &(getLog());
delete logger; delete logger;
} }
@ -1354,4 +1370,13 @@ bool FApplication::isNextEventTimeout()
return FObject::isTimeout (&time_last_event, next_event_wait); 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 } // namespace finalcut

View File

@ -159,7 +159,7 @@ uInt character[][fc::NUM_OF_ENCODINGS] =
* (2) Only supported in use with newfont * (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); 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} // ◆ {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); 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 {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); std::size_t((sizeof(cp437_ucs) / sizeof(cp437_ucs[0])) - 1);
// Based on http://www.unicode.org/charts/PDF/UFF00.pdf // 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 // Fullwidth ASCII variants
{0x0020, 0x3000}, // ' ' -> ' ' {0x0020, 0x3000}, // ' ' -> ' '
@ -712,8 +712,8 @@ constexpr wchar_t halfWidth_fullWidth[][2] =
{0xffee, 0x25cb} // ○ -> ○ {0xffee, 0x25cb} // ○ -> ○
}; };
const std::size_t lastHalfWidthItem = \ constexpr std::size_t last_halfwidth_item = \
std::size_t((sizeof(halfWidth_fullWidth) / sizeof(halfWidth_fullWidth[0])) - 1); std::size_t((sizeof(halfwidth_fullwidth) / sizeof(halfwidth_fullwidth[0])) - 1);
} // namespace fc } // namespace fc

View File

@ -29,7 +29,6 @@
#include "final/flabel.h" #include "final/flabel.h"
#include "final/flineedit.h" #include "final/flineedit.h"
#include "final/flistbox.h" #include "final/flistbox.h"
#include "final/flog.h"
#include "final/fmouse.h" #include "final/fmouse.h"
#include "final/fpoint.h" #include "final/fpoint.h"
#include "final/fsize.h" #include "final/fsize.h"

42
src/fdata.cpp Normal file
View File

@ -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 *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include "final/fdata.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FDataAccess
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FDataAccess::FDataAccess()
{ }
//----------------------------------------------------------------------
FDataAccess::~FDataAccess() // destructor
{ }
} // namespace finalcut

View File

@ -25,8 +25,8 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flabel.h" #include "final/flabel.h"
#include "final/flog.h"
#include "final/flineedit.h" #include "final/flineedit.h"
#include "final/flog.h"
#include "final/fpoint.h" #include "final/fpoint.h"
#include "final/fsize.h" #include "final/fsize.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
@ -833,7 +833,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
@ -857,7 +857,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -893,7 +893,7 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
@ -927,7 +927,7 @@ void FLineEdit::adjustTextOffset()
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -940,7 +940,7 @@ void FLineEdit::adjustTextOffset()
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
} }

View File

@ -136,11 +136,8 @@ void FMenu::onKeyPress (FKeyEvent* ev)
// looking for menu bar hotkey // looking for menu bar hotkey
auto menu_bar = getMenuBar(); auto menu_bar = getMenuBar();
if ( menu_bar ) if ( menu_bar && menu_bar->hotkeyMenu(ev) )
{
if ( menu_bar->hotkeyMenu(ev) )
return; return;
}
switch ( ev->key() ) switch ( ev->key() )
{ {

View File

@ -24,7 +24,6 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/flog.h"
#include "final/foptimove.h" #include "final/foptimove.h"
#include "final/ftermcap.h" #include "final/ftermcap.h"
@ -1107,42 +1106,41 @@ void FOptiMove::moveByMethod ( int method
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void printDurations (const FOptiMove& om) void printDurations (const FOptiMove& om)
{ {
finalcut::FLog& log = *FApplication::getLog(); std::clog << " speed: "
log << " speed: "
<< om.baudrate << " baud" << std::flush; << om.baudrate << " baud" << std::flush;
log << " char_duration: " std::clog << " char_duration: "
<< om.char_duration << " ms" << std::flush; << om.char_duration << " ms" << std::flush;
log << " cursor_home: " std::clog << " cursor_home: "
<< om.F_cursor_home.duration << " ms" << std::flush; << om.F_cursor_home.duration << " ms" << std::flush;
log << " cursor_to_ll: " std::clog << " cursor_to_ll: "
<< om.F_cursor_to_ll.duration << " ms" << std::flush; << om.F_cursor_to_ll.duration << " ms" << std::flush;
log << " carriage_return: " std::clog << " carriage_return: "
<< om.F_carriage_return.duration << " ms" << std::flush; << om.F_carriage_return.duration << " ms" << std::flush;
log << " tab: " std::clog << " tab: "
<< om.F_tab.duration << " ms" << std::flush; << om.F_tab.duration << " ms" << std::flush;
log << " back_tab: " std::clog << " back_tab: "
<< om.F_back_tab.duration << " ms" << std::flush; << om.F_back_tab.duration << " ms" << std::flush;
log << " cursor_up: " std::clog << " cursor_up: "
<< om.F_cursor_up.duration << " ms" << std::flush; << om.F_cursor_up.duration << " ms" << std::flush;
log << " cursor_down: " std::clog << " cursor_down: "
<< om.F_cursor_down.duration << " ms" << std::flush; << om.F_cursor_down.duration << " ms" << std::flush;
log << " cursor_left: " std::clog << " cursor_left: "
<< om.F_cursor_left.duration << " ms" << std::flush; << om.F_cursor_left.duration << " ms" << std::flush;
log << " cursor_right: " std::clog << " cursor_right: "
<< om.F_cursor_right.duration << " ms" << std::flush; << om.F_cursor_right.duration << " ms" << std::flush;
log << " cursor_address: " std::clog << " cursor_address: "
<< om.F_cursor_address.duration << " ms" << std::flush; << om.F_cursor_address.duration << " ms" << std::flush;
log << " column_address: " std::clog << " column_address: "
<< om.F_column_address.duration << " ms" << std::flush; << om.F_column_address.duration << " ms" << std::flush;
log << " row_address: " std::clog << " row_address: "
<< om.F_row_address.duration << " ms" << std::flush; << om.F_row_address.duration << " ms" << std::flush;
log << " parm_up_cursor: " std::clog << " parm_up_cursor: "
<< om.F_parm_up_cursor.duration << " ms" << std::flush; << om.F_parm_up_cursor.duration << " ms" << std::flush;
log << " parm_down_cursor: " std::clog << " parm_down_cursor: "
<< om.F_parm_down_cursor.duration << " ms" << std::flush; << om.F_parm_down_cursor.duration << " ms" << std::flush;
log << " parm_left_cursor: " std::clog << " parm_left_cursor: "
<< om.F_parm_left_cursor.duration << " ms" << std::flush; << om.F_parm_left_cursor.duration << " ms" << std::flush;
log << "parm_right_cursor: " std::clog << "parm_right_cursor: "
<< om.F_parm_right_cursor.duration << " ms" << std::flush; << om.F_parm_right_cursor.duration << " ms" << std::flush;
} }

View File

@ -1191,7 +1191,7 @@ wchar_t FTerm::charEncode (wchar_t c, fc::encoding enc)
{ {
wchar_t ch_enc = c; 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) ) if ( fc::character[i][fc::UTF8] == uInt(c) )
{ {
@ -1421,7 +1421,7 @@ void FTerm::init_alt_charset()
}; };
// Update array 'character' with discovered VT100 pairs // 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 keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]);
const uChar altChar = uChar(vt100_alt_char[keyChar]); 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}; const fc::encoding num{fc::NUM_OF_ENCODINGS};
uInt* p = std::find ( fc::character[0] uInt* p = std::find ( fc::character[0]
, fc::character[fc::lastCharItem] + num , fc::character[fc::last_char_item] + num
, utf8char ); , 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); const int item = int(std::distance(fc::character[0], p) / num);
@ -1506,7 +1506,7 @@ void FTerm::init_cygwin_charmap()
return; return;
// PC encoding changes // 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 ) // ▲ if ( fc::character[i][fc::UTF8] == fc::BlackUpPointingTriangle ) // ▲
fc::character[i][fc::PC] = 0x18; fc::character[i][fc::PC] = 0x18;
@ -1560,7 +1560,7 @@ void FTerm::init_teraterm_charmap()
if ( ! isTeraTerm() ) if ( ! isTeraTerm() )
return; 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 ) if ( fc::character[i][fc::PC] < 0x20 )
fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; fc::character[i][fc::PC] = fc::character[i][fc::ASCII];
} }

View File

@ -274,7 +274,7 @@ wchar_t cp437_to_unicode (uChar c)
constexpr std::size_t UNICODE = 1; constexpr std::size_t UNICODE = 1;
wchar_t ucs = c; 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 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; constexpr std::size_t UNICODE = 1;
uChar c{'?'}; 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 if ( fc::cp437_ucs[i][UNICODE] == ucs ) // found
{ {
@ -322,10 +322,10 @@ const FString getFullWidth (const FString& str)
} }
else 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 if ( fc::halfwidth_fullwidth[i][HALF] == c ) // found
c = fc::halfWidth_fullWidth[i][FULL]; c = fc::halfwidth_fullwidth[i][FULL];
} }
} }
} }
@ -350,10 +350,10 @@ const FString getHalfWidth (const FString& str)
} }
else 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 if ( fc::halfwidth_fullwidth[i][FULL] == c ) // found
c = fc::halfWidth_fullWidth[i][HALF]; c = fc::halfwidth_fullwidth[i][HALF];
} }
} }
} }
@ -457,7 +457,7 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
*FApplication::getLog() << FLog::Error std::clog << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl; << "Out of Range error: " << ex.what() << std::endl;
} }
} }

View File

@ -27,6 +27,7 @@
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/fkey_map.h" #include "final/fkey_map.h"
#include "final/flog.h"
#include "final/fsystem.h" #include "final/fsystem.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermdata.h" #include "final/ftermdata.h"
@ -127,12 +128,11 @@ void FTermcap::termcapError (int status)
static constexpr int no_entry = 0; static constexpr int no_entry = 0;
static constexpr int db_not_found = -1; static constexpr int db_not_found = -1;
static constexpr int uninitialized = -2; static constexpr int uninitialized = -2;
finalcut::FLog& log = *FApplication::getLog();
if ( status == no_entry || status == uninitialized ) if ( status == no_entry || status == uninitialized )
{ {
const char* termtype = fterm_data->getTermType(); const char* termtype = fterm_data->getTermType();
log << FLog::Error std::clog << FLog::Error
<< "Unknown terminal: \"" << termtype << "\". " << "Unknown terminal: \"" << termtype << "\". "
<< "Check the TERM environment variable. " << "Check the TERM environment variable. "
<< "Also make sure that the terminal " << "Also make sure that the terminal "
@ -142,7 +142,7 @@ void FTermcap::termcapError (int status)
} }
else if ( status == db_not_found ) else if ( status == db_not_found )
{ {
log << "The termcap/terminfo database could not be found." std::clog << "The termcap/terminfo database could not be found."
<< std::endl; << std::endl;
std::abort(); std::abort();
} }

View File

@ -171,7 +171,7 @@ void FTermFreeBSD::initCharMap()
if ( ! isFreeBSDConsole() ) if ( ! isFreeBSDConsole() )
return; 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 ) if ( fc::character[i][fc::PC] < 0x1c )
fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; fc::character[i][fc::PC] = fc::character[i][fc::ASCII];
} }
@ -195,7 +195,7 @@ void FTermFreeBSD::finish()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermFreeBSD::warnNotInitialized() void FTermFreeBSD::warnNotInitialized()
{ {
*FApplication::getLog() << FLog::Warn std::clog << FLog::Warn
<< "The FTermFreeBSD object has " << "The FTermFreeBSD object has "
<< "not yet been initialized! " << "not yet been initialized! "
<< "Please call the init() method first." << "Please call the init() method first."

View File

@ -202,7 +202,7 @@ void FTermLinux::init()
} }
else else
{ {
FApplication::getLog()->error("Can not open the console."); std::clog << FLog::Error << "Can not open the console." << std::endl;
std::abort(); std::abort();
} }
} }
@ -217,7 +217,7 @@ void FTermLinux::initCharMap()
if ( screen_unicode_map.entry_ct > 0 && screen_unicode_map.entries ) 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 auto ucs = wchar_t(fc::character[i][fc::UTF8]);
const sInt16 fontpos = getFontPos(ucs); const sInt16 fontpos = getFontPos(ucs);

View File

@ -162,7 +162,7 @@ bool FTermOpenBSD::resetBeep()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermOpenBSD::warnNotInitialized() void FTermOpenBSD::warnNotInitialized()
{ {
*FApplication::getLog() << FLog::Warn std::clog << FLog::Warn
<< "The FTermOpenBSD object has " << "The FTermOpenBSD object has "
<< "not yet been initialized! " << "not yet been initialized! "
<< "Please call the init() method first." << "Please call the init() method first."

View File

@ -311,7 +311,7 @@ void FTermXTerminal::captureFontAndTitle()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::warnNotInitialized() const void FTermXTerminal::warnNotInitialized() const
{ {
*FApplication::getLog() << FLog::Warn std::clog << FLog::Warn
<< "The FTermXTerminal object has " << "The FTermXTerminal object has "
<< "not yet been initialized! " << "not yet been initialized! "
<< "Please call the init() method first." << "Please call the init() method first."

View File

@ -35,7 +35,8 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#include "final/fapplication.h" #include <iostream>
#include "final/flog.h" #include "final/flog.h"
#include "final/fstring.h" #include "final/fstring.h"

View File

@ -207,6 +207,7 @@ class FApplication : public FWidget
char** app_argv{}; char** app_argv{};
uInt64 key_timeout{100000}; // 100 ms uInt64 key_timeout{100000}; // 100 ms
uInt64 dblclick_interval{500000}; // 500 ms uInt64 dblclick_interval{500000}; // 500 ms
std::streambuf* default_clog_rdbuf{std::clog.rdbuf()};
FEventQueue event_queue{}; FEventQueue event_queue{};
static uInt64 next_event_wait; static uInt64 next_event_wait;
static timeval time_last_event; static timeval time_last_event;

View File

@ -37,16 +37,16 @@ namespace fc
{ {
extern uInt character[][fc::NUM_OF_ENCODINGS]; 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 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 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 wchar_t halfwidth_fullwidth[][2];
extern const std::size_t lastHalfWidthItem; extern const std::size_t last_halfwidth_item;
} // namespace fc } // namespace fc

View File

@ -57,9 +57,11 @@ class FData; // Class forward declaration
class FDataAccess class FDataAccess
{ {
public: public:
// Constructor
FDataAccess();
// Destructor // Destructor
virtual ~FDataAccess() virtual ~FDataAccess();
{ }
// Accessors // Accessors
virtual const FString getClassName() const virtual const FString getClassName() const
@ -101,7 +103,31 @@ class FData : public FDataAccess
, value_ref{value} , 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 // 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 T operator () () const
{ {
return value_ref; return value_ref;

View File

@ -108,6 +108,9 @@ class FLog : public std::stringbuf
LineEnding end_of_line{CRLF}; LineEnding end_of_line{CRLF};
FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)};
std::ostream stream{this}; std::ostream stream{this};
// Friend Non-member operator functions
friend std::ostream& operator << (std::ostream&, LogLevel);
}; };
// FLog inline functions // FLog inline functions

View File

@ -39,7 +39,7 @@
#define null nullptr #define null nullptr
#define badAllocOutput(object_name) \ #define badAllocOutput(object_name) \
*FApplication::getLog() << FLog::Error \ std::clog << FLog::Error \
<< __FILE__ << ":" << __LINE__ \ << __FILE__ << ":" << __LINE__ \
<< ": Not enough memory to alloc " \ << ": Not enough memory to alloc " \
<< (object_name) \ << (object_name) \

View File

@ -579,9 +579,9 @@ inline FVTerm& FVTerm::operator << (const std::string& string)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FVTerm& FVTerm::operator << \ inline FVTerm& FVTerm::operator << \
(const std::vector<FChar>& termString) (const std::vector<FChar>& term_string)
{ {
print (termString); print (term_string);
return *this; return *this;
} }

View File

@ -35,16 +35,17 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// functions // 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 // class FDataTest

View File

@ -316,6 +316,9 @@ void FLoggerTest::fileTest()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLoggerTest::applicationObjectTest() 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 // Generation of a logger in a shared_ptr via a pointer
finalcut::FApplication::setLog (std::make_shared<finalcut::FLogger>()); finalcut::FApplication::setLog (std::make_shared<finalcut::FLogger>());
// Get the shared_ptr with the base class // Get the shared_ptr with the base class
@ -348,6 +351,15 @@ void FLoggerTest::applicationObjectTest()
CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" ); CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" );
buf.str(""); // Clear buffer 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 // Replace the logger with another one
finalcut::FApplication::setLog(std::make_shared<myLogger>()); finalcut::FApplication::setLog(std::make_shared<myLogger>());
log = finalcut::FApplication::getLog(); log = finalcut::FApplication::getLog();
@ -369,7 +381,22 @@ void FLoggerTest::applicationObjectTest()
CPPUNIT_ASSERT ( buf.str() == "Debug: myLogger 4\n" ); CPPUNIT_ASSERT ( buf.str() == "Debug: myLogger 4\n" );
buf.str(""); // Clear buffer buf.str(""); // Clear buffer
std::shared_ptr<finalcut::FLog>* logger = &(finalcut::FApplication::getLog()); // 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; delete logger;
} }

View File

@ -819,7 +819,7 @@ wchar_t ftermfreebsdTest::charEncode (wchar_t c)
{ {
wchar_t ch_enc{L'\0'}; 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) ) if ( finalcut::fc::character[i][finalcut::fc::UTF8] == uInt(c) )
{ {