diff options
author | 2021-08-22 09:06:15 +1000 | |
---|---|---|
committer | 2021-08-22 09:06:15 +1000 | |
commit | e8bbea1fc6e94e14768509d322f6c624403ffb36 (patch) | |
tree | 74dd1606a900d83de8aecff17a6737af4113308d /src/lib/util/path.h | |
parent | e319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff) |
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter.
unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename.
Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums.
Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/lib/util/path.h')
-rw-r--r-- | src/lib/util/path.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lib/util/path.h b/src/lib/util/path.h new file mode 100644 index 00000000000..1291d7b17d3 --- /dev/null +++ b/src/lib/util/path.h @@ -0,0 +1,65 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +/*************************************************************************** + + path.h + + Filesystem path utilties + +***************************************************************************/ +#ifndef MAME_LIB_UTIL_PATH_H +#define MAME_LIB_UTIL_PATH_H + +#include "osdfile.h" // for PATH_SEPARATOR + +#include <string> +#include <utility> + + +namespace util { + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +// is a given character a directory separator? + +constexpr bool is_directory_separator(char c) +{ +#if defined(WIN32) + return ('\\' == c) || ('/' == c) || (':' == c); +#else + return '/' == c; +#endif +} + + +// append to a path + +template <typename T, typename... U> +inline std::string &path_append(std::string &path, T &&next, U &&... more) +{ + if (!path.empty() && !is_directory_separator(path.back())) + path.append(PATH_SEPARATOR); + path.append(std::forward<T>(next)); + if constexpr (sizeof...(U)) + return path_append(std::forward<U>(more)...); + else + return path; +} + + +// concatenate paths + +template <typename T, typename... U> +inline std::string path_concat(T &&first, U &&... more) +{ + std::string result(std::forward<T>(first)); + if constexpr (sizeof...(U)) + path_append(result, std::forward<U>(more)...); + return result; +} + +} // namespace util + +#endif // MAME_LIB_UTIL_PATH_H |