Skip to content

Commit

Permalink
make style
Browse files Browse the repository at this point in the history
  • Loading branch information
tzanio committed Jul 25, 2024
1 parent c92aab4 commit c697e0b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
20 changes: 11 additions & 9 deletions lib/aux_vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,24 +1785,26 @@ void SetFont(const std::string& fn)
#endif
}

function<string(double)> NumberFormatter(int precision, char format, bool showsign)
function<string(double)> NumberFormatter(int precision, char format,
bool showsign)
{
return [precision, format, showsign](double x) -> string
{
ostringstream oss;
switch (format) {
switch (format)
{
case 'f':
oss << fixed;
break;
oss << fixed;
break;
case 's':
oss << scientific;
break;
oss << scientific;
break;
case 'd':
oss << defaultfloat;
break;
oss << defaultfloat;
break;
default:
MFEM_WARNING("Unknown formatting type. Using default. "
<< "Valid options include: ['f', 's', 'd']" << endl);
<< "Valid options include: ['f', 's', 'd']" << endl);
oss << defaultfloat;
break;
};
Expand Down
69 changes: 35 additions & 34 deletions lib/aux_vis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ bool SetFont(const vector<std::string>& patterns, int height);
void SetFont(const std::string& fn);

void SetUseHiDPI(bool status);
function<string(double)> NumberFormatter(int precision=4, char format='d', bool showsign=false);
function<string(double)> NumberFormatter(int precision=4, char format='d',
bool showsign=false);
function<string(double)> NumberFormatter(string formatting);
bool isValidNumberFormatting(const string& formatting);

Expand All @@ -148,40 +149,40 @@ bool isValidNumberFormatting(const string& formatting);
template <typename T>
T prompt(const string question,
const T* default_value = nullptr,
function<bool(T)> validator = [](T) { return true; })
function<bool(T)> validator = [](T) { return true; })
{
T input;
string strInput;

while (true)
{
cout << question << " ";
getline(cin, strInput);
stringstream buf(strInput);

if (strInput.empty() && default_value != nullptr)
{
cout << "Input empty. Using default value: " << *default_value << endl;
return *default_value;
}

if (buf >> input)
{
if (validator(input))
{
return input;
}
else
{
cout << "Input is not valid. Please try again." << endl;
}
}
else
{
cout << "Input can not be casted to expected type. Please try again." << endl;
}
}
return input;
T input;
string strInput;

while (true)
{
cout << question << " ";
getline(cin, strInput);
stringstream buf(strInput);

if (strInput.empty() && default_value != nullptr)
{
cout << "Input empty. Using default value: " << *default_value << endl;
return *default_value;
}

if (buf >> input)
{
if (validator(input))
{
return input;
}
else
{
cout << "Input is not valid. Please try again." << endl;
}
}
else
{
cout << "Input can not be casted to expected type. Please try again." << endl;
}
}
return input;
}

#endif
4 changes: 2 additions & 2 deletions lib/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ void SdlWindow::mainIter()
keep_going = true;
break;
case SDL_KEYDOWN:
// For debugging: uncomment the next line to track key events.
// #define TRACK_KEY_EVENTS
// For debugging: uncomment the next line to track key events.
// #define TRACK_KEY_EVENTS
#ifdef TRACK_KEY_EVENTS
cout << "Event: SDL_KEYDOWN sym=" << e.key.keysym.sym
<< " mod=" << e.key.keysym.mod << endl;
Expand Down
6 changes: 4 additions & 2 deletions lib/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,8 @@ void communication_thread::execute()
string formatting;

*is[0] >> ws >> c; // read the opening char
getline(*is[0], formatting, c); // read formatting string & use c for termination
getline(*is[0], formatting,
c); // read formatting string & use c for termination

// all processors sent the command
for (size_t i = 1; i < is.size(); i++)
Expand All @@ -1277,7 +1278,8 @@ void communication_thread::execute()
string formatting;

*is[0] >> ws >> c; // read the opening char
getline(*is[0], formatting, c); // read formatting string & use c for termination
getline(*is[0], formatting,
c); // read formatting string & use c for termination

// all processors sent the command
for (size_t i = 1; i < is.size(); i++)
Expand Down
18 changes: 10 additions & 8 deletions lib/vsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,11 @@ void KeycPressed(GLenum state)

int precision = prompt<int>("Enter precision (4): ",
&default_precision,
[](int p){ return p>=0; });
char format = prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c){ return c=='d' || c=='f' || c=='s'; });
[](int p) { return p>=0; });
char format =
prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c) { return c=='d' || c=='f' || c=='s'; });
bool showsign = prompt<bool>("Show sign? [(1)true, (0)false] (0): ",
&default_showsign);
vsdata->SetColorbarNumberFormat(precision, format, showsign);
Expand Down Expand Up @@ -628,10 +629,11 @@ void Key_Mod_a_Pressed(GLenum state)

int precision = prompt<int>("Enter precision (4): ",
&default_precision,
[](int p){ return p>=0; });
char format = prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c){ return c=='d' || c=='f' || c=='s'; });
[](int p) { return p>=0; });
char format =
prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c) { return c=='d' || c=='f' || c=='s'; });
bool showsign = prompt<bool>("Show sign? [(1)true, (0)false] (0): ",
&default_showsign);
vsdata->SetAxisNumberFormat(precision, format, showsign);
Expand Down

0 comments on commit c697e0b

Please sign in to comment.