mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 13:55:34 +00:00
Further removal of old code and porting to C++17.
This commit is contained in:
+17
-8
@@ -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:
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
#ifndef APP_GTKMM_FEATURES_H
|
||||
#define APP_GTKMM_FEATURES_H
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,13 @@
|
||||
/// \weakgroup applib_tests
|
||||
/// @{
|
||||
|
||||
#include <iostream>
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <iostream>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "app_ui_res_utils.h"
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
/// \weakgroup applib
|
||||
/// @{
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cerrno> // 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<gchar*> argvp(0, g_strfreev); // args vector
|
||||
|
||||
std::vector<std::string> argvp;
|
||||
try {
|
||||
argvp = Glib::shell_parse_argv(cmd);
|
||||
}
|
||||
catch(Glib::ShellError& e)
|
||||
{
|
||||
int argcp = 0; // number of args
|
||||
hz::scoped_ptr<GError> 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<void>("gshell", ErrorLevel::error, shell_error->message), false);
|
||||
return false;
|
||||
}
|
||||
push_error(Error<void>("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<gchar> curr_dir(g_get_current_dir(), g_free);
|
||||
hz::scoped_ptr<GError> spawn_error(0, g_error_free);
|
||||
|
||||
/*
|
||||
#if defined APP_CMDEX_USE_SYNC && APP_CMDEX_USE_SYNC
|
||||
|
||||
hz::scoped_ptr<gchar*> stdout_str(0, g_free);
|
||||
hz::scoped_ptr<gchar*> 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<void>("gspawn", ErrorLevel::error, spawn_error->message), false);
|
||||
return false;
|
||||
try {
|
||||
Glib::spawn_async_with_pipes(Glib::get_current_dir(), argvp, std::vector<std::string>(),
|
||||
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<void>("gspawn", ErrorLevel::error, spawn_error->message), false);
|
||||
push_error(Error<void>("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<GError> 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<void>("giochannel", ErrorLevel::error, channel_error->message), false);
|
||||
g_error_free(channel_error);
|
||||
break; // stop on next invocation (is this correct?)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
/// \weakgroup applib
|
||||
/// @{
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <gtkmm.h> // Gtk::Main
|
||||
#include <gdkmm.h>
|
||||
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
#ifndef APP_CMDEX_SYNC_GUI_H
|
||||
#define APP_CMDEX_SYNC_GUI_H
|
||||
|
||||
#include <gtkmm/messagedialog.h>
|
||||
#include <glibmm/timer.h>
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "hz/noncopyable.h"
|
||||
|
||||
|
||||
@@ -12,10 +12,15 @@
|
||||
#ifndef SELFTEST_H
|
||||
#define SELFTEST_H
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h>
|
||||
#undef throw
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "hz/cstdint.h"
|
||||
#include "hz/intrusive_ptr.h"
|
||||
|
||||
#include "storage_device.h"
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
/// \weakgroup applib_tests
|
||||
/// @{
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <iostream>
|
||||
#include <gtkmm.h>
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
/// @{
|
||||
|
||||
#include <clocale> // localeconv
|
||||
#include <cstdint>
|
||||
|
||||
#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
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <bitset>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "hz/win32_tools.h"
|
||||
#include "hz/string_sprintf.h"
|
||||
@@ -146,7 +147,7 @@ std::map<char, DriveLetterInfo> win32_get_drive_letter_map()
|
||||
std::string volume_name;
|
||||
wchar_t volume_name_w[MAX_PATH+1] = {0};
|
||||
DWORD dummy = 0;
|
||||
hz::scoped_array<wchar_t> drive_name(hz::win32_utf8_to_utf16((drive + std::string(":\\")).c_str()));
|
||||
hz::unique_ptr<wchar_t[]> 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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <sigc++/sigc++.h>
|
||||
|
||||
#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<bool> smart_supported_; ///< SMART support status
|
||||
hz::OptionalValue<bool> smart_enabled_; ///< SMART enabled status
|
||||
mutable hz::OptionalValue<status_t> aodc_status_; ///< Cached aodc status.
|
||||
hz::OptionalValue<std::string> model_name_; ///< Model name
|
||||
hz::OptionalValue<std::string> family_name_; ///< Family name
|
||||
hz::OptionalValue<std::string> serial_number_; ///< Serial number
|
||||
hz::OptionalValue<std::string> size_; ///< Formatted size
|
||||
hz::OptionalValue<bool> hdd_; ///< Whether it's a rotational drive (HDD) or something else (SSD, flash, etc...)
|
||||
mutable hz::OptionalValue<StorageProperty> health_property_; ///< Cached health property.
|
||||
std::optional<bool> smart_supported_; ///< SMART support status
|
||||
std::optional<bool> smart_enabled_; ///< SMART enabled status
|
||||
mutable std::optional<status_t> aodc_status_; ///< Cached aodc status.
|
||||
std::optional<std::string> model_name_; ///< Model name
|
||||
std::optional<std::string> family_name_; ///< Family name
|
||||
std::optional<std::string> serial_number_; ///< Serial number
|
||||
std::optional<std::string> size_; ///< Formatted size
|
||||
std::optional<bool> hdd_; ///< Whether it's a rotational drive (HDD) or something else (SSD, flash, etc...)
|
||||
mutable std::optional<StorageProperty> health_property_; ///< Cached health property.
|
||||
|
||||
SmartctlParser::prop_list_t properties_; ///< Smart properties. Detected through full output.
|
||||
|
||||
|
||||
@@ -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<int>(p.value.value());
|
||||
} else {
|
||||
os << "-";
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iosfwd>
|
||||
|
||||
#include "hz/optional_value.h"
|
||||
#include "hz/cstdint.h"
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
|
||||
|
||||
@@ -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<uint8_t> value; ///< Normalized value. May be unset ("---").
|
||||
hz::OptionalValue<uint8_t> worst; ///< Worst ever value. May be unset ("---").
|
||||
hz::OptionalValue<uint8_t> threshold; ///< Threshold for normalized value. May be unset ("---").
|
||||
std::optional<uint8_t> value; ///< Normalized value. May be unset ("---").
|
||||
std::optional<uint8_t> worst; ///< Worst ever value. May be unset ("---").
|
||||
std::optional<uint8_t> 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
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
/// \weakgroup gsc
|
||||
/// @{
|
||||
|
||||
// TODO Remove this in gtkmm4.
|
||||
#include <bits/stdc++.h> // to avoid throw() macro errors.
|
||||
#define throw(a) // glibmm uses dynamic exception specifications, remove them.
|
||||
#include <glibmm.h> // NOT NEEDED
|
||||
#undef throw
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1118,9 +1118,11 @@ void GscMainWindow::run_update_drivedb()
|
||||
update_binary = "xterm -hold -e " + update_binary;
|
||||
#endif
|
||||
|
||||
hz::scoped_ptr<GError> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#ifndef GSC_SETTINGS_H
|
||||
#define GSC_SETTINGS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "rconfig/rconfig_mini.h"
|
||||
#include "hz/cstdint.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/**************************************************************************
|
||||
Copyright:
|
||||
(C) 2009 - 2012 Alexander Shaduri <ashaduri 'at' gmail.com>
|
||||
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 <stdint.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
@@ -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 <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> 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 <wchar.h>
|
||||
#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 <wchar.h>
|
||||
#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_ ]
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <string>
|
||||
#include <cstddef> // std::size_t
|
||||
#include <ctime> // for time.h, std::strftime, std::time, std::localtime, ...
|
||||
#include <cstdint>
|
||||
|
||||
#include "cstdint.h"
|
||||
#include "locale_tools.h" // hz::ScopedCLocale
|
||||
#include "string_num.h" // hz::number_to_string
|
||||
#include "i18n.h" // HZ_NC_, HZ_C_
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
#include "format_unit.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "cstdint.h"
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <cstddef> // std::size_t
|
||||
#include <cstring> // for string.h
|
||||
#include <string.h> // wcslen()
|
||||
#include <memory>
|
||||
#else
|
||||
#include <sys/types.h> // dirent needs this
|
||||
#include <dirent.h>
|
||||
@@ -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<wchar_t> wpath(hz::win32_utf8_to_utf16(path));
|
||||
hz::unique_ptr<wchar_t[]> wpath(hz::win32_utf8_to_utf16(path));
|
||||
if (!wpath) {
|
||||
errno = ENOENT; // not specified by opendir (3), not sure about this.
|
||||
return 0;
|
||||
|
||||
@@ -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<wchar_t>(hz::win32_utf8_to_utf16(dir.c_str())).get()) == 0);
|
||||
return (_wchdir(hz::unique_ptr<wchar_t[]>(hz::win32_utf8_to_utf16(dir.c_str())).get()) == 0);
|
||||
#else
|
||||
return (chdir(dir.c_str()) == 0);
|
||||
#endif
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/**************************************************************************
|
||||
Copyright:
|
||||
(C) 2012 Alexander Shaduri <ashaduri 'at' gmail.com>
|
||||
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 T>
|
||||
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 T>
|
||||
class initialized<T*> {
|
||||
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 T, T initial_value>
|
||||
class value_initialized : public initialized<T> {
|
||||
public :
|
||||
|
||||
value_initialized() : initialized<T>(initial_value)
|
||||
{ }
|
||||
|
||||
value_initialized(const initialized<T>& arg) : initialized<T>(arg)
|
||||
{ }
|
||||
|
||||
explicit value_initialized(const T& arg) : initialized<T>(arg)
|
||||
{ }
|
||||
|
||||
value_initialized& operator=(const initialized<T>& arg)
|
||||
{
|
||||
initialized<T>::operator=(arg);
|
||||
return *this;
|
||||
}
|
||||
|
||||
value_initialized& operator=(const T& arg)
|
||||
{
|
||||
initialized<T>::operator=(arg);
|
||||
return *this;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // ns
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
@@ -84,7 +84,7 @@ struct intrusive_ptr_error : virtual public std::exception { // from <exception
|
||||
|
||||
/// Constructor
|
||||
intrusive_ptr_error(const char* msg, const std::type_info& type)
|
||||
: msg_(0), type_(type)
|
||||
: type_(type)
|
||||
{
|
||||
const char* tname = type.name();
|
||||
const char* tmsg = " Type: ";
|
||||
@@ -111,7 +111,7 @@ struct intrusive_ptr_error : virtual public std::exception { // from <exception
|
||||
return msg_;
|
||||
}
|
||||
|
||||
char* msg_; ///< Error message
|
||||
char* msg_ = 0; ///< Error message
|
||||
const std::type_info& type_; ///< Type information of the pointee
|
||||
};
|
||||
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
/**************************************************************************
|
||||
Copyright:
|
||||
(C) 2008 - 2013 Alexander Shaduri <ashaduri 'at' gmail.com>
|
||||
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 <ostream> // std::ostream, operator<<(ostream, const char*). iosfwd is not enough.
|
||||
|
||||
#if __cplusplus > 201100L
|
||||
#include <utility> // move
|
||||
#endif
|
||||
|
||||
|
||||
namespace hz {
|
||||
|
||||
|
||||
/// A simple wrapper around type T, providing additional state - defined / undefined.
|
||||
template<class T>
|
||||
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<T>& other)
|
||||
// {
|
||||
// value_ = other.value_;
|
||||
// defined_ = other.defined_;
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
// /// Assignment operator
|
||||
// OptionalValue& operator= (OptionalValue<T>& 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<T>& 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<class T>
|
||||
std::ostream& operator<< (std::ostream& os, const OptionalValue<T>& v)
|
||||
{
|
||||
if (v.defined()) {
|
||||
os << v.value();
|
||||
} else {
|
||||
os << "[value undefined]";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // ns
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
@@ -15,8 +15,8 @@
|
||||
#include "hz_config.h" // feature macros
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "cstdint.h"
|
||||
#include "data_file.h"
|
||||
#include "fs_file.h"
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
|
||||
#include <limits>
|
||||
#include <iostream>
|
||||
|
||||
#include "cstdint.h"
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
#include <ostream> // std::ostream definition (calling bad() member)
|
||||
#include <ios> // std::ios::*
|
||||
#include <locale> // std::locale::classic()
|
||||
#include <cstdint>
|
||||
|
||||
#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()
|
||||
|
||||
Reference in New Issue
Block a user