Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ 20 #1237

Merged
merged 6 commits into from
Nov 9, 2023
Merged

C++ 20 #1237

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/megamol_config.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MegaMol configuration

# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 99)

# Warnings
Expand Down
2 changes: 1 addition & 1 deletion core/include/mmcore/param/FilePathParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class FilePathParam : public AbstractParam {
* @return The value of the parameter as string.
*/
std::string ValueString() const override {
return this->value.generic_u8string();
return this->value.generic_string();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions core/include/mmcore/utility/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool megamol::core::utility::FileUtils::FileWithExtensionExists(const T& path_st
try {
if (FileUtils::FileExists<T>(path_str)) {
auto filepath = std::filesystem::u8path(path_str);
return (filepath.extension().generic_u8string() == std::string("." + ext));
return (filepath.extension().generic_string() == std::string("." + ext));
}
} catch (std::filesystem::filesystem_error const& e) {
megamol::core::utility::log::Log::DefaultLog.WriteError(
Expand All @@ -151,7 +151,7 @@ bool megamol::core::utility::FileUtils::FileWithExtensionExists(const T& path_st
template<typename T>
bool megamol::core::utility::FileUtils::FileHasExtension(const T& path_str, const std::string& ext) {
auto filepath = std::filesystem::u8path(path_str);
return (filepath.extension().generic_u8string() == ext);
return (filepath.extension().generic_string() == ext);
}


Expand All @@ -161,7 +161,7 @@ std::string megamol::core::utility::FileUtils::GetFileNameStem(const T& path_str
auto filepath = std::filesystem::u8path(path_str);
std::string filename;
if (filepath.has_stem()) {
filename = filepath.stem().generic_u8string();
filename = filepath.stem().generic_string();
}
return filename;
} catch (std::filesystem::filesystem_error const& e) {
Expand All @@ -179,9 +179,9 @@ std::string megamol::core::utility::FileUtils::GetFilePathStem(const T& path_str
std::string filename;
if (filepath.has_stem()) {
if (filepath.has_parent_path()) {
filename = (filepath.parent_path() / filepath.stem()).generic_u8string();
filename = (filepath.parent_path() / filepath.stem()).generic_string();
} else {
filename = filepath.stem().generic_u8string();
filename = filepath.stem().generic_string();
}
}
return filename;
Expand All @@ -201,7 +201,7 @@ std::string megamol::core::utility::FileUtils::SearchFileRecursive(const T& sear
std::string found_path;
for (const auto& entry : std::filesystem::recursive_directory_iterator(search_path)) {
if (entry.path().filename() == file_path) {
found_path = entry.path().generic_u8string();
found_path = entry.path().generic_string();
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/include/mmcore/utility/log/Log.inl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Log::writeMessage(log_level level, std::string const& msg, Args&&... args)
auto fmsg = msg;
if constexpr (sizeof...(Args) > 0) {
if (msg.find("%") == std::string::npos) {
fmsg = fmt::format(msg, std::forward<Args>(args)...);
fmsg = fmt::format(fmt::runtime(msg), std::forward<Args>(args)...);
} else {
fmsg = fmt::sprintf(msg, std::forward<Args>(args)...);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/AbstractWriterParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ AbstractWriterParams::AbstractWriterParams(std::function<void(AbstractSlot* slot

std::pair<bool, std::string> AbstractWriterParams::getNextFilename() {
const std::string filepath_param =
this->filePathSlot.template Param<param::FilePathParam>()->Value().generic_u8string().c_str();
this->filePathSlot.template Param<param::FilePathParam>()->Value().generic_string().c_str();

const std::string filepath = filepath_param.find_last_of("/\\") != std::string::npos
? filepath_param.substr(0, filepath_param.find_last_of("/\\") + 1)
Expand Down
12 changes: 6 additions & 6 deletions core/src/param/FilePathParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool FilePathParam::ParseValue(std::string const& v) {
void FilePathParam::SetValue(const std::filesystem::path& v, bool setDirty) {

try {
auto tmp_val_str = v.generic_u8string();
auto tmp_val_str = v.generic_string();
std::replace(tmp_val_str.begin(), tmp_val_str.end(), '\\', '/');
auto new_value = std::filesystem::path(tmp_val_str);
if (this->value != new_value) {
Expand All @@ -52,16 +52,16 @@ void FilePathParam::SetValue(const std::filesystem::path& v, bool setDirty) {
if (error_flags & Flag_File) {
megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[FilePathParam] Omitting value '%s'. Expected file but directory is given.",
new_value.generic_u8string().c_str());
new_value.generic_string().c_str());
}
if (error_flags & Flag_Directory) {
megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[FilePathParam] Omitting value '%s'. Expected directory but file is given.",
new_value.generic_u8string().c_str());
new_value.generic_string().c_str());
}
if (error_flags & Internal_NoExistenceCheck) {
megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[FilePathParam] Omitting value '%s'. File does not exist.", new_value.generic_u8string().c_str());
"[FilePathParam] Omitting value '%s'. File does not exist.", new_value.generic_string().c_str());
}
if (error_flags & Internal_RestrictExtension) {
std::string log_exts;
Expand All @@ -70,7 +70,7 @@ void FilePathParam::SetValue(const std::filesystem::path& v, bool setDirty) {
}
megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[FilePathParam] Omitting value '%s'. File does not have required extension: %s",
new_value.generic_u8string().c_str(), log_exts.c_str());
new_value.generic_string().c_str(), log_exts.c_str());
}
if (error_flags == 0) {
this->value = new_value;
Expand Down Expand Up @@ -116,7 +116,7 @@ FilePathParam::Flags_t FilePathParam::ValidatePath(const std::filesystem::path&
if (f & FilePathParam::Internal_RestrictExtension) {
bool valid_ext = false;
for (auto& ext : e) {
if (p.extension().generic_u8string() == std::string("." + ext)) {
if (p.extension().generic_string() == std::string("." + ext)) {
valid_ext = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/utility/graphics/ScreenShotComments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::string mcu_graphics::ScreenShotComments::GetProjectFromPNG(const std::files
if (fp == nullptr) {
megamol::core::utility::log::Log::DefaultLog.WriteError(
"ScreenShotComments::GetProjectFromPNG: Unable to open png file \"%s\"",
filename.generic_u8string().c_str());
filename.generic_string().c_str());
} else {
png_infop info = png_create_info_struct(png);
if (!info) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/main/src/CLIConfigParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::pair<RuntimeConfig, GlobalValueStore> megamol::frontend::handle_cli_and_con
const int argc, const char** argv, megamol::core::LuaAPI& lua) {
RuntimeConfig config;

config.megamol_executable_directory = getExecutableDirectory().u8string();
config.megamol_executable_directory = getExecutableDirectory().string();

// config files are already checked to exist in file system
config.configuration_files = extract_config_file_paths(argc, argv);
Expand Down
4 changes: 2 additions & 2 deletions frontend/services/gui/src/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ bool megamol::gui::GUIManager::SynchronizeGraphs(megamol::core::MegaMolGraph& me
}
if (!script_filename.empty()) {
auto script_path = std::filesystem::u8path(script_filename);
graph_ptr->SetFilename(script_path.generic_u8string(), false);
graph_ptr->SetFilename(script_path.generic_string(), false);
}
}

Expand Down Expand Up @@ -1556,7 +1556,7 @@ bool megamol::gui::GUIManager::create_unique_screenshot_filename(std::string& in
filename + id_separator + std::to_string(this->gui_state.screenshot_filepath_id) + ".png";
}
} while (megamol::core::utility::FileUtils::FileExists<std::string>(ret_filepath));
inout_filepath = std::filesystem::u8path(ret_filepath).generic_u8string();
inout_filepath = std::filesystem::u8path(ret_filepath).generic_string();
created_filepath = true;
}
return created_filepath;
Expand Down
12 changes: 6 additions & 6 deletions frontend/services/gui/src/graph/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ bool megamol::gui::Parameter::widget_filepath(megamol::gui::Parameter::WidgetSco
if (scope == megamol::gui::Parameter::WidgetScope::LOCAL) {
ImGui::BeginGroup();
if (!std::holds_alternative<std::string>(this->gui_widget_value)) {
this->gui_widget_value = val.generic_u8string();
this->gui_widget_value = val.generic_string();
}
ImGuiStyle& style = ImGui::GetStyle();

Expand Down Expand Up @@ -1487,21 +1487,21 @@ bool megamol::gui::Parameter::widget_filepath(megamol::gui::Parameter::WidgetSco
auto error_flags = FilePathParam::ValidatePath(val, file_extensions, file_flags);
if (error_flags & FilePathParam::FilePathParam::Flag_File) {
this->gui_popup_msg =
"Omitting value '" + val.generic_u8string() + "'. Expected file but directory is given.";
"Omitting value '" + val.generic_string() + "'. Expected file but directory is given.";
}
if (error_flags & FilePathParam::Flag_Directory) {
this->gui_popup_msg =
"Omitting value '" + val.generic_u8string() + "'. Expected directory but file is given.";
"Omitting value '" + val.generic_string() + "'. Expected directory but file is given.";
}
if (error_flags & FilePathParam::Internal_NoExistenceCheck) {
this->gui_popup_msg = "Omitting value '" + val.generic_u8string() + "'. File does not exist.";
this->gui_popup_msg = "Omitting value '" + val.generic_string() + "'. File does not exist.";
}
if (error_flags & FilePathParam::Internal_RestrictExtension) {
std::string log_exts;
for (auto& ext : file_extensions) {
log_exts += "'." + ext + "' ";
}
this->gui_popup_msg = "Omitting value '" + val.generic_u8string() +
this->gui_popup_msg = "Omitting value '" + val.generic_string() +
"'. File does not have required extension: " + log_exts;
}
if (error_flags != 0) {
Expand All @@ -1520,7 +1520,7 @@ bool megamol::gui::Parameter::widget_filepath(megamol::gui::Parameter::WidgetSco
this->filepath_scroll_xmax = true;
retval = true;
} else if (!ImGui::IsItemActive() && !ImGui::IsItemEdited()) {
this->gui_widget_value = val.generic_u8string();
this->gui_widget_value = val.generic_string();
}
ImGui::PopItemWidth();

Expand Down
46 changes: 23 additions & 23 deletions frontend/services/gui/src/widgets/FileBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool megamol::gui::FileBrowserWidget::popup(FileBrowserWidget::DialogMode mode,
// Path ---------------------------------------------------
auto last_file_path_str = this->current_directory_str;
if (ImGui::ArrowButton("arrow_home_dir", ImGuiDir_Right)) {
this->current_directory_str = std::filesystem::current_path().generic_u8string();
this->current_directory_str = std::filesystem::current_path().generic_string();
}
this->tooltip.ToolTip("Working Directory", ImGui::GetID("arrow_home_dir"), 0.5f, 5.0f);
ImGui::SameLine();
Expand Down Expand Up @@ -198,16 +198,16 @@ bool megamol::gui::FileBrowserWidget::popup(FileBrowserWidget::DialogMode mode,

// Sort path and file names case insensitive alphabetically ascending
std::sort(paths.begin(), paths.end(), [&](ChildData_t const& a, ChildData_t const& b) {
std::string a_str = a.first.filename().generic_u8string();
std::string a_str = a.first.filename().generic_string();
core::utility::string::ToUpperAscii(a_str);
std::string b_str = b.first.filename().generic_u8string();
std::string b_str = b.first.filename().generic_string();
core::utility::string::ToUpperAscii(b_str);
return (a_str < b_str);
});
std::sort(files.begin(), files.end(), [&](ChildData_t const& a, ChildData_t const& b) {
std::string a_str = a.first.filename().generic_u8string();
std::string a_str = a.first.filename().generic_string();
core::utility::string::ToUpperAscii(a_str);
std::string b_str = b.first.filename().generic_u8string();
std::string b_str = b.first.filename().generic_string();
core::utility::string::ToUpperAscii(b_str);
return (a_str < b_str);
});
Expand All @@ -225,7 +225,7 @@ bool megamol::gui::FileBrowserWidget::popup(FileBrowserWidget::DialogMode mode,
// Files and directories ----------------
for (const auto& path_pair : this->child_directories) {

auto select_label = path_pair.first.filename().generic_u8string();
auto select_label = path_pair.first.filename().generic_string();
bool showSearchedParameter = true;
if (!currentSearchString.empty()) {
showSearchedParameter =
Expand All @@ -240,7 +240,7 @@ bool megamol::gui::FileBrowserWidget::popup(FileBrowserWidget::DialogMode mode,
if (ImGui::Selectable(
select_label.c_str(), (select_label == this->current_file_str), select_flags)) {
last_file_path_str = this->current_directory_str;
auto new_path = path_pair.first.generic_u8string();
auto new_path = path_pair.first.generic_string();
this->validate_split_path(
new_path, flags, this->current_directory_str, this->current_file_str);
this->validate_file(
Expand Down Expand Up @@ -351,7 +351,7 @@ bool megamol::gui::FileBrowserWidget::popup(FileBrowserWidget::DialogMode mode,
tmp_path = dir;
}
}
inout_filename = tmp_path.generic_u8string();
inout_filename = tmp_path.generic_string();
inout_save_gui_state = this->save_gui_state;
inout_save_all_param_values = this->save_all_param_values;
ImGui::CloseCurrentPopup();
Expand Down Expand Up @@ -397,29 +397,29 @@ bool megamol::gui::FileBrowserWidget::validate_split_path(

if ((flags & FilePathParam::Flag_Any) == FilePathParam::Flag_Any) {
if ((status_known(status(out_path)) && is_directory(out_path))) {
out_dir = out_path.generic_u8string();
out_file = out_path.filename().generic_u8string();
out_dir = out_path.generic_string();
out_file = out_path.filename().generic_string();
} else {
out_dir = out_path.parent_path().generic_u8string();
out_file = out_path.filename().generic_u8string();
out_dir = out_path.parent_path().generic_string();
out_file = out_path.filename().generic_string();
}
} else if (flags & FilePathParam::Flag_File) {
if ((status_known(status(out_path)) && is_directory(out_path))) {
out_dir = out_path.generic_u8string();
out_dir = out_path.generic_string();
if (!(flags & FilePathParam::Internal_NoExistenceCheck)) {
out_file.clear();
}
} else {
out_dir = out_path.parent_path().generic_u8string();
out_file = out_path.filename().generic_u8string();
out_dir = out_path.parent_path().generic_string();
out_file = out_path.filename().generic_string();
}
} else if (flags & FilePathParam::Flag_Directory) {
if ((status_known(status(out_path)) && is_directory(out_path))) {
out_dir = out_path.generic_u8string();
out_file = out_path.filename().generic_u8string();
out_dir = out_path.generic_string();
out_file = out_path.filename().generic_string();
} else {
out_dir = out_path.parent_path().generic_u8string();
out_file = out_path.filename().generic_u8string();
out_dir = out_path.parent_path().generic_string();
out_file = out_path.filename().generic_string();
}
}
if (out_dir.empty()) {
Expand Down Expand Up @@ -533,7 +533,7 @@ std::string FileBrowserWidget::get_parent_path(const std::string& dir) const {
auto retdir = this->get_absolute_path(dir);
auto parent_dir = std::filesystem::u8path(retdir);
if (parent_dir.has_parent_path() && parent_dir.has_relative_path()) {
retdir = parent_dir.parent_path().generic_u8string();
retdir = parent_dir.parent_path().generic_string();
}
return retdir;
} catch (std::filesystem::filesystem_error& e) {
Expand All @@ -548,18 +548,18 @@ std::string megamol::gui::FileBrowserWidget::get_absolute_path(const std::string

try {
auto retval = std::filesystem::u8path(dir);
if ((retval.generic_u8string() == "..") || (retval.generic_u8string() == ".")) {
if ((retval.generic_string() == "..") || (retval.generic_string() == ".")) {
retval = absolute(retval);
#if (_MSC_VER < 1916) /// XXX Fixed/No more required since VS 2019
if (retval.has_parent_path()) {
retval = retval.parent_path();
if ((retval.generic_u8string() == "..") && retval.has_parent_path()) {
if ((retval.generic_string() == "..") && retval.has_parent_path()) {
retval = retval.parent_path();
}
}
#endif // _MSC_VER > 1916
}
return retval.generic_u8string();
return retval.generic_string();
} catch (std::filesystem::filesystem_error& e) {
megamol::core::utility::log::Log::DefaultLog.WriteError(
"[GUI] Filesystem Error: %s [%s, %s, line %d]\n", e.what(), __FILE__, __FUNCTION__, __LINE__);
Expand Down
Loading
Loading