diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index f428058..aebade6 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -33,15 +33,24 @@ Port to C++17 (or at least 14, that's what libsigc++ requires) Remove glibmm thread stuff (it's gone in gtkmm4). -Remove strtold / strtof. -DISABLE_STRTOF -DISABLE_STRTOLD +strtold / strtof, DISABLE_STRTOF, DISABLE_STRTOLD (after ascii.h) Port to std::filesystem. -convert hz::any_type to std::any -type_properties.h -static_assert -scoped_ptr -cstdint +type_properties.h / type_categories.h (after ascii.h and string_num.h) +scoped_ptr (after we have GtkFileChooserNative in gtkmm) +scoped_array (after we get rid of hz::fs) +Fix ResourceDataAnyDumper. +sync. +common_types (after sync). +format_date() -> C++17 has it. +noncopyable (after sync) +snprintf +ptr_container +stream_cast? +some string_algo +string_sprintf? +wcmatch (through regex)? +std::wstring in mingw instead of wchar_t? +Check licenses - do we still use boost, bsd? After JSON: diff --git a/gsmartcontrol/src/applib/app_gtkmm_features.h b/gsmartcontrol/src/applib/app_gtkmm_features.h index 7d5d1a7..0e8dfeb 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_features.h +++ b/gsmartcontrol/src/applib/app_gtkmm_features.h @@ -12,6 +12,12 @@ #ifndef APP_GTKMM_FEATURES_H #define APP_GTKMM_FEATURES_H +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + #include diff --git a/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp b/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp index b1703d0..c2d7590 100644 --- a/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp +++ b/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp @@ -9,8 +9,13 @@ /// \weakgroup applib_tests /// @{ -#include +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw +#include #include #include "app_ui_res_utils.h" diff --git a/gsmartcontrol/src/applib/cmdex.cpp b/gsmartcontrol/src/applib/cmdex.cpp index 60dfeff..ecbaeef 100644 --- a/gsmartcontrol/src/applib/cmdex.cpp +++ b/gsmartcontrol/src/applib/cmdex.cpp @@ -9,6 +9,12 @@ /// \weakgroup applib /// @{ +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + #include #include // errno (not std::errno, it may be a macro) @@ -23,7 +29,6 @@ #include "hz/debug.h" #include "hz/string_num.h" // hz::number_to_string() #include "hz/env_tools.h" // hz::ScopedEnv -#include "hz/scoped_ptr.h" #include "cmdex.h" @@ -105,16 +110,14 @@ bool Cmdex::execute() // Make command vector - - hz::scoped_ptr argvp(0, g_strfreev); // args vector - + std::vector argvp; + try { + argvp = Glib::shell_parse_argv(cmd); + } + catch(Glib::ShellError& e) { - int argcp = 0; // number of args - hz::scoped_ptr shell_error(0, g_error_free); - if (!g_shell_parse_argv(cmd.c_str(), &argcp, &argvp.get_ref(), &shell_error.get_ref())) { - push_error(Error("gshell", ErrorLevel::error, shell_error->message), false); - return false; - } + push_error(Error("gshell", ErrorLevel::error, e.what()), false); + return false; } @@ -132,57 +135,23 @@ bool Cmdex::execute() debug_out_info("app", DBG_FUNC_MSG << "Executing \"" << cmd << "\".\n"); -/* - if (argvp) { - debug_out_dump("app", DBG_FUNC_MSG << "Dumping argvp:\n"); - gchar** elem = argvp.get(); - while (*elem) { - debug_out_dump("app", *elem << "\n"); - ++elem; - } - } -*/ // Execute the command - hz::scoped_ptr curr_dir(g_get_current_dir(), g_free); - hz::scoped_ptr spawn_error(0, g_error_free); - -/* -#if defined APP_CMDEX_USE_SYNC && APP_CMDEX_USE_SYNC - - hz::scoped_ptr stdout_str(0, g_free); - hz::scoped_ptr stderr_str(0, g_free); - gint exit_status = 0; - - g_timer_start(timer_); // start the timer - - if (!g_spawn_sync(curr_dir.get(), argvp.get(), NULL, - GSpawnFlags(G_SPAWN_SEARCH_PATH), - NULL, NULL, // child setup function - &stdout_str.get_ref(), &stderr_str.get_ref(), &exit_status, &spawn_error.get_ref())) - { - // no data is returned to &-parameters on error. - push_error(Error("gspawn", ErrorLevel::error, spawn_error->message), false); - return false; + try { + Glib::spawn_async_with_pipes(Glib::get_current_dir(), argvp, std::vector(), + Glib::SpawnFlags::SPAWN_SEARCH_PATH | Glib::SpawnFlags::SPAWN_DO_NOT_REAP_CHILD, + Glib::SlotSpawnChildSetup(), + &this->pid_, nullptr, &fd_stdout_, &fd_stderr_); } - -#else // async way: -*/ - if (!g_spawn_async_with_pipes(curr_dir.get(), argvp.get(), NULL, - GSpawnFlags(G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD), - NULL, NULL, // child setup function - &this->pid_, 0, &fd_stdout_, &fd_stderr_, &spawn_error.get_ref())) - { + catch(Glib::SpawnError& e) { // no data is returned to &-parameters on error. - push_error(Error("gspawn", ErrorLevel::error, spawn_error->message), false); + push_error(Error("gspawn", ErrorLevel::error, e.what()), false); return false; } g_timer_start(timer_); // start the timer -// #endif - #ifdef _WIN32 channel_stdout_ = g_io_channel_win32_new_fd(fd_stdout_); @@ -461,14 +430,15 @@ gboolean Cmdex::on_channel_io(GIOChannel* channel, // while there's anything to read, read it do { - hz::scoped_ptr channel_error(0, g_error_free); + GError* channel_error = 0; gsize bytes_read = 0; - GIOStatus status = g_io_channel_read_chars(channel, buf, count, &bytes_read, &channel_error.get_ref()); + GIOStatus status = g_io_channel_read_chars(channel, buf, count, &bytes_read, &channel_error); if (bytes_read) output_str->append(buf, bytes_read); if (channel_error) { self->push_error(Error("giochannel", ErrorLevel::error, channel_error->message), false); + g_error_free(channel_error); break; // stop on next invocation (is this correct?) } diff --git a/gsmartcontrol/src/applib/cmdex_sync_gui.cpp b/gsmartcontrol/src/applib/cmdex_sync_gui.cpp index 288f1bf..ebcb204 100644 --- a/gsmartcontrol/src/applib/cmdex_sync_gui.cpp +++ b/gsmartcontrol/src/applib/cmdex_sync_gui.cpp @@ -9,6 +9,12 @@ /// \weakgroup applib /// @{ +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + #include // Gtk::Main #include diff --git a/gsmartcontrol/src/applib/cmdex_sync_gui.h b/gsmartcontrol/src/applib/cmdex_sync_gui.h index f4c47af..428ef4d 100644 --- a/gsmartcontrol/src/applib/cmdex_sync_gui.h +++ b/gsmartcontrol/src/applib/cmdex_sync_gui.h @@ -12,8 +12,13 @@ #ifndef APP_CMDEX_SYNC_GUI_H #define APP_CMDEX_SYNC_GUI_H -#include -#include +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + +#include #include "hz/noncopyable.h" diff --git a/gsmartcontrol/src/applib/selftest.h b/gsmartcontrol/src/applib/selftest.h index 397e08f..e010724 100644 --- a/gsmartcontrol/src/applib/selftest.h +++ b/gsmartcontrol/src/applib/selftest.h @@ -12,10 +12,15 @@ #ifndef SELFTEST_H #define SELFTEST_H +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. #include +#undef throw + #include +#include -#include "hz/cstdint.h" #include "hz/intrusive_ptr.h" #include "storage_device.h" diff --git a/gsmartcontrol/src/applib/smartctl_executor_test.cpp b/gsmartcontrol/src/applib/smartctl_executor_test.cpp index 731a89a..cb8c3e5 100644 --- a/gsmartcontrol/src/applib/smartctl_executor_test.cpp +++ b/gsmartcontrol/src/applib/smartctl_executor_test.cpp @@ -9,6 +9,12 @@ /// \weakgroup applib_tests /// @{ +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + #include #include diff --git a/gsmartcontrol/src/applib/smartctl_parser.cpp b/gsmartcontrol/src/applib/smartctl_parser.cpp index ba02f9d..32fc94a 100644 --- a/gsmartcontrol/src/applib/smartctl_parser.cpp +++ b/gsmartcontrol/src/applib/smartctl_parser.cpp @@ -10,9 +10,9 @@ /// @{ #include // localeconv +#include #include "hz/locale_tools.h" // ScopedCLocale, locale_c_get(). -#include "hz/cstdint.h" // uint64_t #include "hz/string_algo.h" // string_* #include "hz/string_num.h" // string_is_numeric, number_to_string #include "hz/format_unit.h" // format_size diff --git a/gsmartcontrol/src/applib/storage_detector_win32.cpp b/gsmartcontrol/src/applib/storage_detector_win32.cpp index 296fe16..591ee3d 100644 --- a/gsmartcontrol/src/applib/storage_detector_win32.cpp +++ b/gsmartcontrol/src/applib/storage_detector_win32.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "hz/win32_tools.h" #include "hz/string_sprintf.h" @@ -146,7 +147,7 @@ std::map win32_get_drive_letter_map() std::string volume_name; wchar_t volume_name_w[MAX_PATH+1] = {0}; DWORD dummy = 0; - hz::scoped_array drive_name(hz::win32_utf8_to_utf16((drive + std::string(":\\")).c_str())); + hz::unique_ptr drive_name(hz::win32_utf8_to_utf16((drive + std::string(":\\")).c_str())); if (drive_name && GetVolumeInformationW(drive_name.get(), volume_name_w, MAX_PATH+1, NULL, &dummy, &dummy, NULL, 0)) { diff --git a/gsmartcontrol/src/applib/storage_device.cpp b/gsmartcontrol/src/applib/storage_device.cpp index bd2993a..3bcae63 100644 --- a/gsmartcontrol/src/applib/storage_device.cpp +++ b/gsmartcontrol/src/applib/storage_device.cpp @@ -289,7 +289,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si // been parsed by parse_data() which failed at it). if (do_set_properties) { StorageAttribute::DiskType disk_type = StorageAttribute::DiskAny; - if (hdd_.defined()) { + if (hdd_.has_value()) { disk_type = hdd_.value() ? StorageAttribute::DiskHDD : StorageAttribute::DiskSSD; } SmartctlParser ps; @@ -299,7 +299,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si } // A model field (and its aliases) is a good indication whether there was any data or not - set_parse_status(model_name_.defined() ? parse_status_info : parse_status_none); + set_parse_status(model_name_.has_value() ? parse_status_info : parse_status_none); if (emit_signal) signal_changed.emit(this); // notify listeners @@ -353,7 +353,7 @@ std::string StorageDevice::parse_data() this->clear_fetched(false); // clear everything fetched before, except outputs StorageAttribute::DiskType disk_type = StorageAttribute::DiskAny; - if (hdd_.defined()) { + if (hdd_.has_value()) { disk_type = hdd_.value() ? StorageAttribute::DiskHDD : StorageAttribute::DiskSSD; } SmartctlParser ps; @@ -475,11 +475,11 @@ A mandatory SMART command failed: exiting. To continue, add one or more '-T perm StorageDevice::status_t StorageDevice::get_smart_status() const { status_t status = status_unsupported; - if (smart_enabled_.defined()) { + if (smart_enabled_.has_value()) { if (smart_enabled_.value()) { // enabled, supported status = status_enabled; } else { // if it's disabled, maybe it's unsupported, check that: - if (smart_supported_.defined()) { + if (smart_supported_.has_value()) { if (smart_supported_.value()) { // disabled, supported status = status_disabled; } else { // disabled, unsupported @@ -490,7 +490,7 @@ StorageDevice::status_t StorageDevice::get_smart_status() const } } } else { // status unknown - if (smart_supported_.defined()) { + if (smart_supported_.has_value()) { if (smart_supported_.value()) { // status unknown, supported status = status_disabled; // at least give the user a chance to try enabling it } else { // status unknown, unsupported @@ -512,7 +512,7 @@ StorageDevice::status_t StorageDevice::get_aodc_status() const if (get_smart_status() != status_enabled) return status_unsupported; - if (aodc_status_.defined()) // cached return value + if (aodc_status_.has_value()) // cached return value return aodc_status_.value(); status_t status = status_unknown; // for now @@ -552,14 +552,14 @@ StorageDevice::status_t StorageDevice::get_aodc_status() const std::string StorageDevice::get_device_size_str() const { - return (size_.defined() ? size_.value() : ""); + return (size_.has_value() ? size_.value() : ""); } StorageProperty StorageDevice::get_health_property() const { - if (health_property_.defined()) // cached return value + if (health_property_.has_value()) // cached return value return health_property_.value(); StorageProperty p = this->lookup_property("overall_health", @@ -725,28 +725,28 @@ StorageProperty StorageDevice::lookup_property(const std::string& generic_name, std::string StorageDevice::get_model_name() const { - return (model_name_.defined() ? model_name_.value() : ""); + return (model_name_.has_value() ? model_name_.value() : ""); } std::string StorageDevice::get_family_name() const { - return (family_name_.defined() ? family_name_.value() : ""); + return (family_name_.has_value() ? family_name_.value() : ""); } std::string StorageDevice::get_serial_number() const { - return (serial_number_.defined() ? serial_number_.value() : ""); + return (serial_number_.has_value() ? serial_number_.value() : ""); } bool StorageDevice::get_is_hdd() const { - return hdd_.defined() ? hdd_.value() : false; + return hdd_.has_value() ? hdd_.value() : false; } diff --git a/gsmartcontrol/src/applib/storage_device.h b/gsmartcontrol/src/applib/storage_device.h index f3c6587..27d42bf 100644 --- a/gsmartcontrol/src/applib/storage_device.h +++ b/gsmartcontrol/src/applib/storage_device.h @@ -14,9 +14,9 @@ #include #include +#include #include -#include "hz/optional_value.h" #include "hz/intrusive_ptr.h" #include "storage_property.h" @@ -290,15 +290,15 @@ class StorageDevice : public hz::intrusive_ptr_referenced { // Note: These are detected through info output detected_type_t detected_type_; ///< e.g. type_unknown - hz::OptionalValue smart_supported_; ///< SMART support status - hz::OptionalValue smart_enabled_; ///< SMART enabled status - mutable hz::OptionalValue aodc_status_; ///< Cached aodc status. - hz::OptionalValue model_name_; ///< Model name - hz::OptionalValue family_name_; ///< Family name - hz::OptionalValue serial_number_; ///< Serial number - hz::OptionalValue size_; ///< Formatted size - hz::OptionalValue hdd_; ///< Whether it's a rotational drive (HDD) or something else (SSD, flash, etc...) - mutable hz::OptionalValue health_property_; ///< Cached health property. + std::optional smart_supported_; ///< SMART support status + std::optional smart_enabled_; ///< SMART enabled status + mutable std::optional aodc_status_; ///< Cached aodc status. + std::optional model_name_; ///< Model name + std::optional family_name_; ///< Family name + std::optional serial_number_; ///< Serial number + std::optional size_; ///< Formatted size + std::optional hdd_; ///< Whether it's a rotational drive (HDD) or something else (SSD, flash, etc...) + mutable std::optional health_property_; ///< Cached health property. SmartctlParser::prop_list_t properties_; ///< Smart properties. Detected through full output. diff --git a/gsmartcontrol/src/applib/storage_property.cpp b/gsmartcontrol/src/applib/storage_property.cpp index aa0d656..e25f5df 100644 --- a/gsmartcontrol/src/applib/storage_property.cpp +++ b/gsmartcontrol/src/applib/storage_property.cpp @@ -55,7 +55,7 @@ std::string StorageAttribute::format_raw_value() const std::ostream& operator<< (std::ostream& os, const StorageAttribute& p) { // os << p.name << ": " - if (p.value.defined()) { + if (p.value.has_value()) { os << static_cast(p.value.value()); } else { os << "-"; diff --git a/gsmartcontrol/src/applib/storage_property.h b/gsmartcontrol/src/applib/storage_property.h index b0d9147..e51b12e 100644 --- a/gsmartcontrol/src/applib/storage_property.h +++ b/gsmartcontrol/src/applib/storage_property.h @@ -15,9 +15,8 @@ #include #include #include - -#include "hz/optional_value.h" -#include "hz/cstdint.h" +#include +#include @@ -130,9 +129,9 @@ class StorageAttribute { int32_t id; ///< Attribute ID (most vendors agree on this) std::string flag; ///< "Old" format is "0xXXXX", "brief" format is "PO--C-". - hz::OptionalValue value; ///< Normalized value. May be unset ("---"). - hz::OptionalValue worst; ///< Worst ever value. May be unset ("---"). - hz::OptionalValue threshold; ///< Threshold for normalized value. May be unset ("---"). + std::optional value; ///< Normalized value. May be unset ("---"). + std::optional worst; ///< Worst ever value. May be unset ("---"). + std::optional threshold; ///< Threshold for normalized value. May be unset ("---"). attr_t attr_type; ///< Attribute pre-fail / old-age type update_t update_type; ///< When-updated type fail_time_t when_failed; ///< When-failed type diff --git a/gsmartcontrol/src/gsc_add_device_window.cpp b/gsmartcontrol/src/gsc_add_device_window.cpp index 03963ca..4494dc1 100644 --- a/gsmartcontrol/src/gsc_add_device_window.cpp +++ b/gsmartcontrol/src/gsc_add_device_window.cpp @@ -9,6 +9,12 @@ /// \weakgroup gsc /// @{ +// TODO Remove this in gtkmm4. +#include // to avoid throw() macro errors. +#define throw(a) // glibmm uses dynamic exception specifications, remove them. +#include // NOT NEEDED +#undef throw + #include #include // GDK_KEY_Escape #include diff --git a/gsmartcontrol/src/gsc_info_window.cpp b/gsmartcontrol/src/gsc_info_window.cpp index cff164e..c15105c 100644 --- a/gsmartcontrol/src/gsc_info_window.cpp +++ b/gsmartcontrol/src/gsc_info_window.cpp @@ -715,9 +715,9 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests row[col_id] = iter->value_attribute.id; row[col_name] = iter->readable_name; row[col_flag_value] = iter->value_attribute.flag; // it's a string, not int. - row[col_value] = (iter->value_attribute.value.defined() ? hz::number_to_string(iter->value_attribute.value.value()) : "-"); - row[col_worst] = (iter->value_attribute.worst.defined() ? hz::number_to_string(iter->value_attribute.worst.value()) : "-"); - row[col_threshold] = (iter->value_attribute.threshold.defined() ? hz::number_to_string(iter->value_attribute.threshold.value()) : "-"); + row[col_value] = (iter->value_attribute.value.has_value() ? hz::number_to_string(iter->value_attribute.value.value()) : "-"); + row[col_worst] = (iter->value_attribute.worst.has_value() ? hz::number_to_string(iter->value_attribute.worst.value()) : "-"); + row[col_threshold] = (iter->value_attribute.threshold.has_value() ? hz::number_to_string(iter->value_attribute.threshold.value()) : "-"); row[col_raw] = iter->value_attribute.format_raw_value(); row[col_type] = attr_type; // row[col_updated] = StorageAttribute::get_update_type_name(iter->value_attribute.update_type); diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index ed4640e..9f0e41d 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -1118,9 +1118,11 @@ void GscMainWindow::run_update_drivedb() update_binary = "xterm -hold -e " + update_binary; #endif - hz::scoped_ptr spawn_error(0, g_error_free); - if (!g_spawn_command_line_async(update_binary.c_str(), &spawn_error.get_ref())) { - gui_show_error_dialog("Error Updating Drive Database", spawn_error->message, this); + try { + Glib::spawn_command_line_async(update_binary); + } + catch(Glib::Error& e) { + gui_show_error_dialog("Error Updating Drive Database", e.what(), this); } } diff --git a/gsmartcontrol/src/gsc_settings.h b/gsmartcontrol/src/gsc_settings.h index 2b4058c..36545a7 100644 --- a/gsmartcontrol/src/gsc_settings.h +++ b/gsmartcontrol/src/gsc_settings.h @@ -12,8 +12,8 @@ #ifndef GSC_SETTINGS_H #define GSC_SETTINGS_H +#include #include "rconfig/rconfig_mini.h" -#include "hz/cstdint.h" diff --git a/gsmartcontrol/src/hz/Makefile.am b/gsmartcontrol/src/hz/Makefile.am index ca983d0..25f970f 100644 --- a/gsmartcontrol/src/hz/Makefile.am +++ b/gsmartcontrol/src/hz/Makefile.am @@ -2,12 +2,12 @@ AM_CPPFLAGS = $(all_includes) METASOURCES = AUTO noinst_HEADERS = ascii.h \ - bad_cast_exception.h bin2ascii_encoder.h common_types.h cstdint.h cstdint_impl_msvc.h \ + bad_cast_exception.h bin2ascii_encoder.h common_types.h \ data_file.h debug.h env_tools.h errno_string.h error.h error_holder.h \ format_unit.h fs_common.h fs_dir.h fs_dir_platform.h fs_error_holder.h \ fs_file.h fs_path.h fs_path_utils.h fs_tools.h hz_config.h i18n.h \ instance_manager.h intrusive_ptr.h intrusive_scoped_lock.h launch_url.h local_algo.h \ - locale_tools.h noncopyable.h optional_value.h portable_snprintf.h process_signal.h \ + locale_tools.h noncopyable.h portable_snprintf.h process_signal.h \ ptr_container.h res_data.h scoped_array.h scoped_ptr.h stream_cast.h \ string_algo.h string_num.h string_sprintf.h string_sprintf_macros.h string_wcmatch.h sync.h \ sync_lock_ptr.h sync_multilock.h sync_part_get_policy.h \ diff --git a/gsmartcontrol/src/hz/cstdint.h b/gsmartcontrol/src/hz/cstdint.h deleted file mode 100644 index a4695cb..0000000 --- a/gsmartcontrol/src/hz/cstdint.h +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************** - Copyright: - (C) 2009 - 2012 Alexander Shaduri - License: See LICENSE_zlib.txt file -***************************************************************************/ -/// \file -/// \author Alexander Shaduri -/// \ingroup applib -/// \weakgroup applib -/// @{ - -#ifndef HZ_CSTDINT_H -#define HZ_CSTDINT_H - -#include "hz_config.h" // feature macros - - -// Use this file instead of stdint.h for portability. -// It contains all the C99 stdint.h stuff in global namespace. - - -// C++11 defines these automatically for cstdint, so we do it too for compatibility. -#ifndef __STDC_LIMIT_MACROS - #define __STDC_LIMIT_MACROS -#endif -#ifndef __STDC_CONSTANT_MACROS - #define __STDC_CONSTANT_MACROS -#endif - - -// Assume stdint.h is present on all platforms except msvc -#ifdef _MSC_VER - - #include "cstdint_impl_msvc.h" - -#else - - #include - -#endif - - - - -#endif - -/// @} diff --git a/gsmartcontrol/src/hz/cstdint_impl_msvc.h b/gsmartcontrol/src/hz/cstdint_impl_msvc.h deleted file mode 100644 index e236bb0..0000000 --- a/gsmartcontrol/src/hz/cstdint_impl_msvc.h +++ /dev/null @@ -1,247 +0,0 @@ -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2008 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -// For Visual Studio 6 in C++ mode and for many Visual Studio versions when -// compiling for ARM we should wrap include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#ifdef __cplusplus -extern "C" { -#endif -# include -#ifdef __cplusplus -} -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types - -// Visual Studio 6 and Embedded Visual C++ 4 doesn't -// realize that, e.g. char has the same size as __int8 -// so we give up on __intX for them. -#if (_MSC_VER < 1300) - typedef char int8_t; - typedef short int16_t; - typedef int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef __int8 int8_t; - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -#define INTMAX_C INT64_C -#define UINTMAX_C UINT64_C - -#endif // __STDC_CONSTANT_MACROS ] - - -#endif // _MSC_STDINT_H_ ] diff --git a/gsmartcontrol/src/hz/format_unit.h b/gsmartcontrol/src/hz/format_unit.h index 818998e..80444fb 100644 --- a/gsmartcontrol/src/hz/format_unit.h +++ b/gsmartcontrol/src/hz/format_unit.h @@ -17,8 +17,8 @@ #include #include // std::size_t #include // for time.h, std::strftime, std::time, std::localtime, ... +#include -#include "cstdint.h" #include "locale_tools.h" // hz::ScopedCLocale #include "string_num.h" // hz::number_to_string #include "i18n.h" // HZ_NC_, HZ_C_ diff --git a/gsmartcontrol/src/hz/format_unit_test.cpp b/gsmartcontrol/src/hz/format_unit_test.cpp index 8b37c09..a148b6a 100644 --- a/gsmartcontrol/src/hz/format_unit_test.cpp +++ b/gsmartcontrol/src/hz/format_unit_test.cpp @@ -21,8 +21,7 @@ #include "format_unit.h" #include - -#include "cstdint.h" +#include diff --git a/gsmartcontrol/src/hz/fs_dir_platform.h b/gsmartcontrol/src/hz/fs_dir_platform.h index 2272524..54746ae 100644 --- a/gsmartcontrol/src/hz/fs_dir_platform.h +++ b/gsmartcontrol/src/hz/fs_dir_platform.h @@ -22,6 +22,7 @@ #include // std::size_t #include // for string.h #include // wcslen() + #include #else #include // dirent needs this #include @@ -29,7 +30,6 @@ #ifdef _WIN32 #include "win32_tools.h" // hz::win32_utf8_to_utf16(), hz::win32_utf16_to_utf8 - #include "scoped_array.h" // hz::scoped_array #endif // Limited dirent-like API to hide platform differences. @@ -140,7 +140,7 @@ inline directory_handle_type directory_open(const char* path) // NULL on error, return 0; } - hz::scoped_array wpath(hz::win32_utf8_to_utf16(path)); + hz::unique_ptr wpath(hz::win32_utf8_to_utf16(path)); if (!wpath) { errno = ENOENT; // not specified by opendir (3), not sure about this. return 0; diff --git a/gsmartcontrol/src/hz/fs_tools.h b/gsmartcontrol/src/hz/fs_tools.h index a8075f2..b5bbef0 100644 --- a/gsmartcontrol/src/hz/fs_tools.h +++ b/gsmartcontrol/src/hz/fs_tools.h @@ -165,7 +165,7 @@ inline bool set_current_dir(const std::string& dir) { #ifdef _WIN32 // Dont check the parameter, let the function do it. - return (_wchdir(hz::scoped_array(hz::win32_utf8_to_utf16(dir.c_str())).get()) == 0); + return (_wchdir(hz::unique_ptr(hz::win32_utf8_to_utf16(dir.c_str())).get()) == 0); #else return (chdir(dir.c_str()) == 0); #endif diff --git a/gsmartcontrol/src/hz/initialized.h b/gsmartcontrol/src/hz/initialized.h deleted file mode 100644 index 42bcca1..0000000 --- a/gsmartcontrol/src/hz/initialized.h +++ /dev/null @@ -1,179 +0,0 @@ -/************************************************************************** - Copyright: - (C) 2012 Alexander Shaduri - License: See LICENSE_zlib.txt file -***************************************************************************/ -/// \file -/// \author Alexander Shaduri -/// \ingroup hz -/// \weakgroup hz -/// @{ - -#ifndef HZ_INITIALIZED_H -#define HZ_INITIALIZED_H - -#include "hz_config.h" // feature macros - - - -namespace hz { - - -/// This template is useful for default-initializing POD class members. -template -class initialized { - public: - - initialized() : x() - { } - - initialized(const initialized& arg) : x(arg.x) - { } - - explicit initialized(const T& arg) : x(arg) - { } - - initialized& operator=(const initialized& arg) - { - x = arg.x; - return *this; - } - - initialized& operator=(const T& arg) - { - x = arg; - return *this; - } - - operator const T&() const - { - return x; - } - - operator T&() - { - return x; - } - - const T& data() const - { - return x; - } - - T& data() - { - return x; - } - - - protected: - - T x ; - -} ; - - - -/// This template specialization is useful for default-initializing raw pointers. -template -class initialized { - public: - - initialized() : x() - { } - - initialized(const initialized& arg) : x(arg.x) - { } - - explicit initialized(T* arg) : x(arg) - { } - - initialized& operator=(const initialized& arg) - { - x = arg.x; - return *this; - } - - initialized& operator=(T* arg) - { - x = arg; - return *this; - } - - T* operator->() - { - return x; - } - - operator const T*() const - { - return x; - } - - // Avoid gcc warning about choosing one cast over another (-Wconversion) -// operator T*&() -// { -// return x; -// } - - const T*& data() const - { - return x; - } - - T*& data() - { - return x; - } - - - protected: - - T* x ; - -} ; - - - -/// This template is useful for initializing enum-type and integral variables. -template -class value_initialized : public initialized { - public : - - value_initialized() : initialized(initial_value) - { } - - value_initialized(const initialized& arg) : initialized(arg) - { } - - explicit value_initialized(const T& arg) : initialized(arg) - { } - - value_initialized& operator=(const initialized& arg) - { - initialized::operator=(arg); - return *this; - } - - value_initialized& operator=(const T& arg) - { - initialized::operator=(arg); - return *this; - } - -} ; - - - - - - - - -} // ns - - - -#endif - -/// @} diff --git a/gsmartcontrol/src/hz/intrusive_ptr.h b/gsmartcontrol/src/hz/intrusive_ptr.h index d956255..1db9b65 100644 --- a/gsmartcontrol/src/hz/intrusive_ptr.h +++ b/gsmartcontrol/src/hz/intrusive_ptr.h @@ -84,7 +84,7 @@ struct intrusive_ptr_error : virtual public std::exception { // from - License: See LICENSE_zlib.txt file -***************************************************************************/ -/// \file -/// \author Alexander Shaduri -/// \ingroup hz -/// \weakgroup hz -/// @{ - -#ifndef HZ_OPTIONAL_VALUE_H -#define HZ_OPTIONAL_VALUE_H - -#include "hz_config.h" // feature macros - -#include // std::ostream, operator<<(ostream, const char*). iosfwd is not enough. - -#if __cplusplus > 201100L - #include // move -#endif - - -namespace hz { - - -/// A simple wrapper around type T, providing additional state - defined / undefined. -template -class OptionalValue { - public: - - /// Wrapped type - typedef T value_type; - - - /// Constructor. Initial value is default-constructed, and the state is undefined. - OptionalValue() : value_(), defined_(false) - { } - - -#if __cplusplus > 201100L - /// Construct from value \c v, setting the state to defined. - explicit OptionalValue(T v) : value_(std::move(v)), defined_(true) - { } -#else - /// Construct from value \c v, setting the state to defined. - OptionalValue(const T& v) : value_(v), defined_(true) - { } -#endif - - - // Don't Define any of the following: move, copy, destruct. - // This will make the compiler generate the defaults. - -// /// Assignment operator -// OptionalValue& operator= (const OptionalValue& other) -// { -// value_ = other.value_; -// defined_ = other.defined_; -// return *this; -// } - -// /// Assignment operator -// OptionalValue& operator= (OptionalValue& other) -// { -// value_ = other.value_; -// defined_ = other.defined_; -// return *this; -// } - - -#if __cplusplus > 201100L - /// Assignment operator. - /// \post state is defined. - OptionalValue& operator= (T v) - { - value_ = std::move(v); - defined_ = true; - return *this; - } -#else - /// Assignment operator. - /// \post state is defined. - OptionalValue& operator= (const T& v) - { - value_ = v; - defined_ = true; - return *this; - } -#endif - - -// /// Assignment operator. -// /// \post state is defined. -// OptionalValue& operator= (T& v) -// { -// value_ = v; -// defined_ = true; -// return *this; -// } - - - /// Comparison operator - bool operator== (const OptionalValue& v) - { - return (defined_ == v.defined_ && value_ == v.value_); - } - - - /// Comparison operator - bool operator== (const T& v) - { - return (defined_ && value_ == v); - } - - - /// Set the state to undefined, set internal value to a default-constructed one. - void reset() - { - defined_ = false; - value_ = T(); // how else? (it should be needed, e.g. to clear ref-ptr) - } - - - /// Get the stored value. You may use this function only if defined() returns true. - const T& value() const - { - return value_; - } - - - /// Check the defined state. - bool defined() const - { - return defined_; - } - - - private: - - T value_; ///< Wrapped value - bool defined_; ///< "Defined" state - -}; - - - -/// Stream output operator -template -std::ostream& operator<< (std::ostream& os, const OptionalValue& v) -{ - if (v.defined()) { - os << v.value(); - } else { - os << "[value undefined]"; - } - return os; -} - - - - - -} // ns - - - - - -#endif - -/// @} diff --git a/gsmartcontrol/src/hz/res_data.h b/gsmartcontrol/src/hz/res_data.h index 0fb9762..3a7ed2c 100644 --- a/gsmartcontrol/src/hz/res_data.h +++ b/gsmartcontrol/src/hz/res_data.h @@ -15,8 +15,8 @@ #include "hz_config.h" // feature macros #include +#include -#include "cstdint.h" #include "data_file.h" #include "fs_file.h" diff --git a/gsmartcontrol/src/hz/string_num_test.cpp b/gsmartcontrol/src/hz/string_num_test.cpp index ed13480..f6a750e 100644 --- a/gsmartcontrol/src/hz/string_num_test.cpp +++ b/gsmartcontrol/src/hz/string_num_test.cpp @@ -22,8 +22,7 @@ #include #include - -#include "cstdint.h" +#include diff --git a/gsmartcontrol/src/rmn/resource_serialization.h b/gsmartcontrol/src/rmn/resource_serialization.h index 190b5aa..4e3a7ab 100644 --- a/gsmartcontrol/src/rmn/resource_serialization.h +++ b/gsmartcontrol/src/rmn/resource_serialization.h @@ -38,8 +38,8 @@ #include // std::ostream definition (calling bad() member) #include // std::ios::* #include // std::locale::classic() +#include -#include "hz/cstdint.h" #include "hz/hz_config.h" // RMN_* (global_macros.h) #include "hz/string_algo.h" // string_split(), string_trim(), string_trim_copy() #include "hz/string_num.h" // string_is_numeric(), number_to_string()