mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 13:55:34 +00:00
More C++17 modernization.
This commit is contained in:
@@ -53,12 +53,6 @@ Use std::from_chars() in string_is_numeric_impl_classic_locale() (gcc 8)
|
||||
Mark with gettext
|
||||
|
||||
|
||||
std::string setters -> no const&, use std::move.
|
||||
same for std::vector
|
||||
for iter -> for auto
|
||||
push_back -> static vector
|
||||
|
||||
|
||||
Check TODOs
|
||||
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ inline std::string detect_drives_linux_udev_byid(std::vector<std::string>& devic
|
||||
|
||||
// platform blacklist
|
||||
bool blacked = false;
|
||||
for (std::vector<std::string>::const_iterator iter = blacklist.begin(); iter != blacklist.end(); ++iter) {
|
||||
if (app_pcre_match(*iter, entry)) {
|
||||
for (const auto bl_pattern : blacklist) {
|
||||
if (app_pcre_match(bl_pattern, entry)) {
|
||||
blacked = true;
|
||||
break;
|
||||
}
|
||||
@@ -414,8 +414,8 @@ inline std::string detect_drives_linux_proc_partitions(std::vector<StorageDevice
|
||||
|
||||
// platform blacklist
|
||||
bool blacked = false;
|
||||
for (std::vector<std::string>::const_iterator iter = blacklist.begin(); iter != blacklist.end(); ++iter) {
|
||||
if (app_pcre_match(*iter, dev)) {
|
||||
for (const auto& bl_pattern : blacklist) {
|
||||
if (app_pcre_match(bl_pattern, dev)) {
|
||||
blacked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -191,8 +191,8 @@ std::string detect_drives_other(std::vector<StorageDevicePtr>& drives, const Exe
|
||||
continue;
|
||||
|
||||
bool matched = false;
|
||||
for (std::vector<std::string>::const_iterator iter = whitelist.begin(); iter != whitelist.end(); ++iter) {
|
||||
if (app_pcre_match(*iter, entry)) {
|
||||
for (const auto& wl_pattern : whitelist) {
|
||||
if (app_pcre_match(wl_pattern, entry)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -239,9 +239,9 @@ std::string get_scan_open_multiport_devices(std::vector<StorageDevicePtr>& drive
|
||||
auto drive = std::make_shared<StorageDevice>(full_dev, type);
|
||||
|
||||
std::map<char, std::string> letters_volnames;
|
||||
for (std::map<char, DriveLetterInfo>::const_iterator iter = drive_letter_map.begin(); iter != drive_letter_map.end(); ++iter) {
|
||||
if (iter->second.physical_drives.count(drive_num) > 0) {
|
||||
letters_volnames[iter->first] = iter->second.volume_name;
|
||||
for (const auto& iter : drive_letter_map) {
|
||||
if (iter.second.physical_drives.count(drive_num) > 0) {
|
||||
letters_volnames[iter.first] = iter.second.volume_name;
|
||||
}
|
||||
}
|
||||
drive->set_drive_letters(letters_volnames);
|
||||
@@ -733,9 +733,9 @@ std::string detect_drives_win32(std::vector<StorageDevicePtr>& drives, const Exe
|
||||
auto drive = std::make_shared<StorageDevice>(hz::string_sprintf("pd%d", drive_num));
|
||||
|
||||
std::map<char, std::string> letters_volnames;
|
||||
for (std::map<char, DriveLetterInfo>::const_iterator iter = drive_letter_map.begin(); iter != drive_letter_map.end(); ++iter) {
|
||||
if (iter->second.physical_drives.count(drive_num) > 0) {
|
||||
letters_volnames[iter->first] = iter->second.volume_name;
|
||||
for (const auto& iter : drive_letter_map) {
|
||||
if (iter.second.physical_drives.count(drive_num) > 0) {
|
||||
letters_volnames[iter.first] = iter.second.volume_name;
|
||||
}
|
||||
}
|
||||
drive->set_drive_letters(letters_volnames);
|
||||
|
||||
@@ -58,24 +58,22 @@ std::string StorageDevice::get_status_name(Status status)
|
||||
|
||||
|
||||
|
||||
StorageDevice::StorageDevice(const std::string& dev_or_vfile, bool is_virtual)
|
||||
StorageDevice::StorageDevice(std::string dev_or_vfile, bool is_virtual)
|
||||
{
|
||||
is_virtual_ = is_virtual;
|
||||
|
||||
if (is_virtual) {
|
||||
virtual_file_ = dev_or_vfile;
|
||||
virtual_file_ = std::move(dev_or_vfile);
|
||||
} else {
|
||||
device_ = dev_or_vfile;
|
||||
device_ = std::move(dev_or_vfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
StorageDevice::StorageDevice(const std::string& dev, const std::string& type_arg)
|
||||
{
|
||||
device_ = dev;
|
||||
type_arg_ = type_arg;
|
||||
}
|
||||
StorageDevice::StorageDevice(std::string dev, std::string type_arg)
|
||||
: device_(std::move(dev)), type_arg_(std::move(type_arg))
|
||||
{ }
|
||||
|
||||
|
||||
|
||||
@@ -570,9 +568,9 @@ StorageDevice::DetectedType StorageDevice::get_detected_type() const
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_type_argument(const std::string& arg)
|
||||
void StorageDevice::set_type_argument(std::string arg)
|
||||
{
|
||||
type_arg_ = arg;
|
||||
type_arg_ = std::move(arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -584,9 +582,9 @@ std::string StorageDevice::get_type_argument() const
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_extra_arguments(const std::string& args)
|
||||
void StorageDevice::set_extra_arguments(std::string args)
|
||||
{
|
||||
extra_args_ = args;
|
||||
extra_args_ = std::move(args);
|
||||
}
|
||||
|
||||
|
||||
@@ -598,9 +596,9 @@ std::string StorageDevice::get_extra_arguments() const
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_drive_letters(const std::map<char, std::string>& letters)
|
||||
void StorageDevice::set_drive_letters(std::map<char, std::string> letters)
|
||||
{
|
||||
drive_letters_ = letters;
|
||||
drive_letters_ = std::move(letters);
|
||||
}
|
||||
|
||||
|
||||
@@ -698,9 +696,9 @@ bool StorageDevice::get_is_hdd() const
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_info_output(const std::string& s)
|
||||
void StorageDevice::set_info_output(std::string s)
|
||||
{
|
||||
info_output_ = s;
|
||||
info_output_ = std::move(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -712,9 +710,9 @@ std::string StorageDevice::get_info_output() const
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_full_output(const std::string& s)
|
||||
void StorageDevice::set_full_output(std::string s)
|
||||
{
|
||||
full_output_ = s;
|
||||
full_output_ = std::move(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -847,9 +845,9 @@ void StorageDevice::set_parse_status(ParseStatus value)
|
||||
|
||||
|
||||
|
||||
void StorageDevice::set_properties(const std::vector<StorageProperty>& props)
|
||||
void StorageDevice::set_properties(std::vector<StorageProperty> props)
|
||||
{
|
||||
properties_ = props;
|
||||
properties_ = std::move(props);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -71,10 +71,10 @@ class StorageDevice {
|
||||
|
||||
|
||||
/// Constructor
|
||||
explicit StorageDevice(const std::string& dev_or_vfile, bool is_virtual = false);
|
||||
explicit StorageDevice(std::string dev_or_vfile, bool is_virtual = false);
|
||||
|
||||
/// Constructor
|
||||
StorageDevice(const std::string& dev, const std::string& type_arg);
|
||||
StorageDevice(std::string dev, std::string type_arg);
|
||||
|
||||
|
||||
// clear everything fetched before.
|
||||
@@ -83,7 +83,7 @@ class StorageDevice {
|
||||
/// Calls "smartctl -i -H -c" (info section, health, capabilities), then parse_basic_data().
|
||||
/// Called during drive detection.
|
||||
/// Note: this will clear the non-basic properties!
|
||||
std::string fetch_basic_data_and_parse(const std::shared_ptr<CmdexSync>& smartctl_ex = 0);
|
||||
std::string fetch_basic_data_and_parse(const std::shared_ptr<CmdexSync>& smartctl_ex = nullptr);
|
||||
|
||||
/// Detects type, smart support, smart status (on / off).
|
||||
/// Note: this will clear the non-basic properties!
|
||||
@@ -141,21 +141,21 @@ class StorageDevice {
|
||||
|
||||
|
||||
/// Set argument for "-d" smartctl parameter
|
||||
void set_type_argument(const std::string& arg);
|
||||
void set_type_argument(std::string arg);
|
||||
|
||||
/// Get argument for "-d" smartctl parameter
|
||||
std::string get_type_argument() const;
|
||||
|
||||
|
||||
/// Set extra arguments smartctl
|
||||
void set_extra_arguments(const std::string& args);
|
||||
void set_extra_arguments(std::string args);
|
||||
|
||||
/// Get extra arguments smartctl
|
||||
std::string get_extra_arguments() const;
|
||||
|
||||
|
||||
/// Set windows drive letters for this drive
|
||||
void set_drive_letters(const std::map<char, std::string>& letters_volnames);
|
||||
void set_drive_letters(std::map<char, std::string> letters_volnames);
|
||||
|
||||
/// Get windows drive letters for this drive
|
||||
const std::map<char, std::string>& get_drive_letters() const;
|
||||
@@ -201,14 +201,14 @@ class StorageDevice {
|
||||
|
||||
|
||||
/// Set "info" output to parse
|
||||
void set_info_output(const std::string& s);
|
||||
void set_info_output(std::string s);
|
||||
|
||||
/// Get "info" output to parse
|
||||
std::string get_info_output() const;
|
||||
|
||||
|
||||
/// Set "full" output to parse
|
||||
void set_full_output(const std::string& s);
|
||||
void set_full_output(std::string s);
|
||||
|
||||
/// Get "full" output to parse
|
||||
std::string get_full_output() const;
|
||||
@@ -252,7 +252,7 @@ class StorageDevice {
|
||||
void set_parse_status(ParseStatus value);
|
||||
|
||||
/// Set parsed properties
|
||||
void set_properties(const std::vector<StorageProperty>& props);
|
||||
void set_properties(std::vector<StorageProperty> props);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -1042,7 +1042,7 @@ namespace {
|
||||
/// different smartctl name (fill the other members from the previous attribute).
|
||||
// void add(int32_t id, const std::string& smartctl_name)
|
||||
// {
|
||||
// std::map<int32_t, std::vector< AttributeDescription> >::iterator iter = id_db.find(id);
|
||||
// auto iter = id_db.find(id);
|
||||
// DBG_ASSERT(iter != id_db.end() && !iter->second.empty());
|
||||
// if (iter != id_db.end() || iter->second.empty()) {
|
||||
// AttributeDescription attr = iter->second.front();
|
||||
|
||||
@@ -855,25 +855,25 @@ bool Dir::list(Container& put_here, bool put_with_path, SortFunctor sort_func, F
|
||||
if (sort_using_paths) {
|
||||
std::sort(path_results.begin(), path_results.end(), sort_func);
|
||||
|
||||
for (list_path_list_t::const_iterator iter = path_results.begin(); iter != path_results.end(); ++iter) {
|
||||
for (const auto& path_result : path_results) {
|
||||
if (put_with_path) {
|
||||
put_here.push_back(iter->str());
|
||||
put_here.push_back(path_result.str());
|
||||
} else {
|
||||
put_here.push_back(iter->get_basename());
|
||||
put_here.push_back(path_result.get_basename());
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
std::sort(string_results.begin(), string_results.end(), sort_func);
|
||||
|
||||
for (list_string_list_t::const_iterator iter = string_results.begin(); iter != string_results.end(); ++iter) {
|
||||
for (const auto& string_result : string_results) {
|
||||
if (put_with_path) {
|
||||
FsPath p(this->get_path());
|
||||
p.append(*iter);
|
||||
p.append(string_result);
|
||||
put_here.push_back(p.str());
|
||||
|
||||
} else {
|
||||
put_here.push_back(*iter);
|
||||
put_here.push_back(string_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,6 @@
|
||||
#include <utime.h> // utime()
|
||||
#endif
|
||||
|
||||
#if defined __MINGW32__
|
||||
#include <_mingw.h> // MINGW_HAS_SECURE_API
|
||||
#endif
|
||||
|
||||
#include "fs_common.h" // separator
|
||||
#include "fs_path_utils.h" // path_* functions
|
||||
#include "fs_error_holder.h" // FsErrorHolder
|
||||
@@ -461,7 +457,7 @@ inline bool FsPath::is_readable()
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined MINGW_HAS_SECURE_API || defined _MSC_VER
|
||||
#if defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS
|
||||
if (_waccess_s(this->get_utf16().c_str(), 04)) // msvc uses integers instead (R_OK == 04 anyway).
|
||||
#elif defined _WIN32
|
||||
if (_waccess(this->get_utf16().c_str(), 04) == -1) // *access*() may not work with < win2k with directories.
|
||||
@@ -508,7 +504,7 @@ inline bool FsPath::is_writable()
|
||||
|
||||
// pcheck either doesn't exist, or it's a file. try to open it.
|
||||
std::FILE* f = 0;
|
||||
#if defined MINGW_HAS_SECURE_API || defined _MSC_VER
|
||||
#if defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS
|
||||
errno = _wfopen_s(&f, path_to_check.get_utf16().c_str(), L"ab");
|
||||
#else
|
||||
f = _wfopen(path_to_check.get_utf16().c_str(), L"ab"); // this creates a 0 size file if it doesn't exist!
|
||||
@@ -567,7 +563,7 @@ inline bool FsPath::exists()
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined MINGW_HAS_SECURE_API || defined _MSC_VER
|
||||
#if defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS
|
||||
if (_waccess_s(this->get_utf16().c_str(), 00) != 0) // msvc uses integers instead (F_OK == 00 anyway).
|
||||
#elif defined _WIN32
|
||||
if (_waccess(this->get_utf16().c_str(), 00) != 0) // msvc uses integers instead (F_OK == 00 anyway).
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
// This may throw for invalid domain or level.
|
||||
std::ostream& debug_out(debug_level::flag level, const std::string& domain)
|
||||
{
|
||||
debug_internal::DebugState::domain_map_t& dm = debug_internal::get_debug_state().get_domain_map();
|
||||
auto& dm = debug_internal::get_debug_state().get_domain_map();
|
||||
|
||||
debug_internal::DebugState::domain_map_t::iterator level_map = dm.find(domain);
|
||||
auto level_map = dm.find(domain);
|
||||
if (level_map == dm.end()) { // no such domain
|
||||
std::string msg = "debug_out(): Debug state doesn't contain the requested domain: \"" + domain + "\".";
|
||||
|
||||
@@ -45,7 +45,7 @@ std::ostream& debug_out(debug_level::flag level, const std::string& domain)
|
||||
throw debug_internal_error(msg.c_str());
|
||||
}
|
||||
|
||||
debug_internal::DebugState::level_map_t::iterator os = level_map->second.find(level);
|
||||
auto os = level_map->second.find(level);
|
||||
if (level_map == dm.end()) {
|
||||
std::string msg = std::string("debug_out(): Debug state doesn't contain the requested level ") +
|
||||
debug_level::get_name(level) + " in domain: \"" + domain + "\".";
|
||||
|
||||
@@ -92,7 +92,7 @@ bool debug_register_domain(const std::string& domain)
|
||||
return false;
|
||||
|
||||
// copy the "default" domain - use it as a template
|
||||
DebugState::domain_map_t::iterator def_iter = dm.find("default");
|
||||
auto def_iter = dm.find("default");
|
||||
if (def_iter == dm.end()) {
|
||||
throw debug_internal_error(("debug_register_domain(\"" + domain
|
||||
+ "\"): Domain \"default\" doesn't exist.").c_str());
|
||||
@@ -103,8 +103,8 @@ bool debug_register_domain(const std::string& domain)
|
||||
dm[domain] = DebugState::level_map_t();
|
||||
DebugState::level_map_t& level_map = dm.find(domain)->second;
|
||||
|
||||
for (DebugState::level_map_t::const_iterator iter = def_level_map.begin(); iter != def_level_map.end(); ++iter) {
|
||||
level_map[iter->first] = std::make_shared<DebugOutStream>(*(iter->second), domain);
|
||||
for (const auto& iter : def_level_map) {
|
||||
level_map[iter.first] = std::make_shared<DebugOutStream>(*(iter.second), domain);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -117,7 +117,7 @@ bool debug_unregister_domain(const std::string& domain)
|
||||
using namespace debug_internal;
|
||||
DebugState::domain_map_t& dm = get_debug_state().get_domain_map();
|
||||
|
||||
DebugState::domain_map_t::iterator found = dm.find(domain);
|
||||
auto found = dm.find(domain);
|
||||
if (found == dm.end()) // doesn't exists
|
||||
return false;
|
||||
|
||||
@@ -134,8 +134,8 @@ std::vector<std::string> debug_get_registered_domains()
|
||||
|
||||
std::vector<std::string> domains;
|
||||
domains.reserve(dm.size());
|
||||
for (DebugState::domain_map_t::iterator iter = dm.begin(); iter != dm.end(); ++iter)
|
||||
domains.push_back(iter->first);
|
||||
for (const auto& iter : dm)
|
||||
domains.push_back(iter.first);
|
||||
|
||||
return domains;
|
||||
}
|
||||
|
||||
@@ -102,9 +102,9 @@ namespace debug_internal {
|
||||
/// Flush all the stream buffers. This will write prefixes too.
|
||||
void force_output()
|
||||
{
|
||||
for(domain_map_t::iterator iter = domain_map.begin(); iter != domain_map.end(); ++iter) {
|
||||
for(level_map_t::iterator iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
|
||||
iter2->second->force_output();
|
||||
for (auto& iter : domain_map) {
|
||||
for (auto& iter2 : iter.second)
|
||||
iter2.second->force_output();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,9 +217,9 @@ namespace debug_internal {
|
||||
|
||||
|
||||
/// Set channel list to send the data to.
|
||||
void set_channels(const std::vector<DebugChannelBasePtr>& channels)
|
||||
void set_channels(std::vector<DebugChannelBasePtr> channels)
|
||||
{
|
||||
channels_ = channels;
|
||||
channels_ = std::move(channels);
|
||||
}
|
||||
|
||||
/// Get channel list
|
||||
@@ -261,9 +261,9 @@ namespace debug_internal {
|
||||
|
||||
private:
|
||||
|
||||
debug_level::flag level_; ///< Debug level of this stream
|
||||
debug_level::flag level_ = debug_level::none; ///< Debug level of this stream
|
||||
std::string domain_; ///< Domain of this stream
|
||||
debug_format::type format_; ///< Format flags
|
||||
debug_format::type format_ = debug_format::none; ///< Format flags
|
||||
|
||||
bool is_first_line_ = true; ///< Whether it's the first line of output or not
|
||||
|
||||
|
||||
Reference in New Issue
Block a user