mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-25 21:35:33 +00:00
Ported hz::scoped_ptr to std::unique_ptr and removed it.
This commit is contained in:
@@ -15,10 +15,10 @@ Copyright:
|
||||
#include <gtkmm.h>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <memory>
|
||||
|
||||
#include "hz/fs_ns.h"
|
||||
#include "hz/string_sprintf.h"
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "applib/app_gtkmm_utils.h"
|
||||
|
||||
#include "gsc_add_device_window.h"
|
||||
@@ -181,8 +181,9 @@ void GscAddDeviceWindow::on_device_name_browse_button_clicked()
|
||||
int result = 0;
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Choose Device..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Choose Device..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
if (path.is_absolute())
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog.get()), path.u8string().c_str());
|
||||
|
||||
@@ -17,10 +17,10 @@ Copyright:
|
||||
#include <gtkmm.h>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <memory>
|
||||
|
||||
#include "applib/app_gtkmm_utils.h" // app_gtkmm_create_tree_view_column
|
||||
#include "applib/app_gtkmm_features.h"
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "hz/fs.h"
|
||||
#include "rconfig/rconfig.h"
|
||||
|
||||
@@ -209,8 +209,9 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked()
|
||||
all_filter->add_pattern("*");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true);
|
||||
|
||||
@@ -326,8 +327,9 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked()
|
||||
all_filter->add_pattern("*");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true);
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ Copyright:
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <vector> // better use vector, it's needed by others too
|
||||
#include <algorithm> // std::min, std::max
|
||||
#include <memory>
|
||||
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "hz/string_num.h" // number_to_string
|
||||
#include "hz/string_sprintf.h" // string_sprintf
|
||||
#include "hz/string_algo.h" // string_join
|
||||
@@ -752,8 +752,9 @@ void GscInfoWindow::on_save_info_button_clicked()
|
||||
all_filter->add_pattern("*");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true);
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ Copyright:
|
||||
#include <gtkmm.h>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "hz/string_algo.h" // string_split
|
||||
#include "hz/string_num.h"
|
||||
#include "hz/debug.h"
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "hz/launch_url.h"
|
||||
#include "hz/fs.h"
|
||||
#include "rconfig/rconfig.h"
|
||||
@@ -1300,8 +1300,9 @@ void GscMainWindow::show_load_virtual_file_chooser()
|
||||
all_filter->add_pattern("*");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Load Data From..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Load Data From..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj());
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj());
|
||||
@@ -1341,7 +1342,8 @@ void GscMainWindow::show_load_virtual_file_chooser()
|
||||
std::vector<std::string> files;
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GSList> file_slist(gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog.get())), g_slist_free);
|
||||
std::unique_ptr<GSList, decltype(&g_slist_free)> file_slist(gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog.get())),
|
||||
&g_slist_free);
|
||||
GSList* iterator = file_slist.get();
|
||||
while(iterator) {
|
||||
files.push_back(app_ustring_from_gchar((gchar*)iterator->data));
|
||||
|
||||
@@ -17,11 +17,11 @@ Copyright:
|
||||
#include <gtkmm.h>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <memory>
|
||||
|
||||
#include "build_config.h"
|
||||
#include "hz/fs_ns.h"
|
||||
#include "hz/string_sprintf.h"
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "rconfig/rconfig.h"
|
||||
#include "applib/storage_settings.h"
|
||||
#include "applib/app_gtkmm_utils.h"
|
||||
@@ -533,8 +533,9 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked()
|
||||
#endif
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Choose Smartctl Binary..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Choose Smartctl Binary..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
if (path.is_absolute())
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog.get()), path.u8string().c_str());
|
||||
|
||||
@@ -15,10 +15,10 @@ Copyright:
|
||||
#include <gtkmm.h>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gdk/gdk.h> // GDK_KEY_Escape
|
||||
#include <memory>
|
||||
|
||||
#include "hz/debug.h"
|
||||
#include "hz/fs.h"
|
||||
#include "hz/scoped_ptr.h"
|
||||
#include "rconfig/rconfig.h"
|
||||
|
||||
#include "applib/app_gtkmm_features.h"
|
||||
@@ -149,8 +149,9 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
|
||||
all_filter->add_pattern("*");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 20, 0)
|
||||
hz::scoped_ptr<GtkFileChooserNative> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr), g_object_unref);
|
||||
std::unique_ptr<GtkFileChooserNative, decltype(&g_object_unref)> dialog(gtk_file_chooser_native_new(
|
||||
_("Save Data As..."), this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, nullptr, nullptr),
|
||||
&g_object_unref);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ BEGIN
|
||||
VALUE "FileDescription", "GSmartControl - Hard disk drive and SSD health inspection tool"
|
||||
VALUE "FileVersion", "@CMAKE_PROJECT_VERSION@"
|
||||
VALUE "InternalName", "gsmartcontrol.exe"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2008 - 2021 Alexander Shaduri"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2008 - 2021 Alexander Shaduri"
|
||||
VALUE "OriginalFilename", "gsmartcontrol.exe"
|
||||
VALUE "ProductName", "GSmartControl"
|
||||
VALUE "ProductVersion", "@CMAKE_PROJECT_VERSION@"
|
||||
|
||||
@@ -20,7 +20,6 @@ target_sources(hz INTERFACE
|
||||
launch_url.h
|
||||
locale_tools.h
|
||||
process_signal.h
|
||||
scoped_ptr.h
|
||||
stream_cast.h
|
||||
string_algo.h
|
||||
string_num.h
|
||||
|
||||
+5
-4
@@ -20,7 +20,7 @@ Copyright:
|
||||
#include <shellapi.h> // ShellExecuteW()
|
||||
#include "win32_tools.h" // hz::win32_utf8_to_utf16
|
||||
#else
|
||||
#include "scoped_ptr.h"
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -49,13 +49,14 @@ inline std::string launch_url(GtkWindow* window, const std::string& link)
|
||||
|
||||
#else
|
||||
|
||||
hz::scoped_ptr<GError> error(0, g_error_free);
|
||||
GError* error = nullptr;
|
||||
#if GTK_CHECK_VERSION(3, 22, 0)
|
||||
bool status = gtk_show_uri_on_window(window, link.c_str(), GDK_CURRENT_TIME, &error.get_ref());
|
||||
bool status = gtk_show_uri_on_window(window, link.c_str(), GDK_CURRENT_TIME, &error);
|
||||
#else
|
||||
GdkScreen* screen = (window ? gtk_window_get_screen(window) : nullptr);
|
||||
bool status = (bool)gtk_show_uri(screen, link.c_str(), GDK_CURRENT_TIME, &error.get_ref());
|
||||
bool status = (bool)gtk_show_uri(screen, link.c_str(), GDK_CURRENT_TIME, &error);
|
||||
#endif
|
||||
std::unique_ptr<GError, decltype(&g_error_free)> uerror(error, &g_error_free);
|
||||
|
||||
if (!status) {
|
||||
return std::string("Cannot open URL: ")
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
/******************************************************************************
|
||||
License: Boost Software License 1.0
|
||||
Copyright:
|
||||
(C) 1998 - 2010 Greg Colvin and Beman Dawes
|
||||
(C) 2001 - 2010 Peter Dimov
|
||||
(C) 2008 - 2021 Alexander Shaduri <ashaduri@gmail.com>
|
||||
******************************************************************************/
|
||||
/// \file
|
||||
/// \author Greg Colvin and Beman Dawes
|
||||
/// \author Peter Dimov
|
||||
/// \author Alexander Shaduri
|
||||
/// \ingroup hz
|
||||
/// \weakgroup hz
|
||||
/// @{
|
||||
|
||||
#ifndef HZ_SCOPED_PTR_H
|
||||
#define HZ_SCOPED_PTR_H
|
||||
|
||||
/**
|
||||
\file
|
||||
Scoped non-reference-counting smart pointer with custom cleanup
|
||||
function. Based on boost::scoped_ptr.
|
||||
|
||||
Original notes and copyright info follow:
|
||||
|
||||
// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
|
||||
// Copyright (c) 2001, 2002 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
|
||||
//
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#ifndef ASSERT // assert() is undefined if NDEBUG is defined.
|
||||
#define ASSERT(a) assert(a)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace hz {
|
||||
|
||||
|
||||
|
||||
namespace internal {
|
||||
|
||||
/// Deleter base
|
||||
template<typename T>
|
||||
struct scoped_ptr_cleaner_base {
|
||||
/// Virtual destructor
|
||||
virtual ~scoped_ptr_cleaner_base() = default;
|
||||
|
||||
/// Delete the pointer. The actual method of deletion is chosen by the overrider.
|
||||
virtual void cleanup(T* p) = 0;
|
||||
};
|
||||
|
||||
/// Deleter which calls F(p), where p is the pointer.
|
||||
template<typename T, typename F>
|
||||
struct scoped_ptr_cleaner : public scoped_ptr_cleaner_base<T> {
|
||||
/// Constructor
|
||||
scoped_ptr_cleaner(F f) : clean_func(f)
|
||||
{ }
|
||||
|
||||
void cleanup(T* p) override
|
||||
{
|
||||
clean_func(p);
|
||||
}
|
||||
|
||||
F clean_func;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
class scoped_ptr { // non-copyable
|
||||
|
||||
private:
|
||||
T* ptr = nullptr;
|
||||
internal::scoped_ptr_cleaner_base<T>* cleaner = nullptr;
|
||||
|
||||
scoped_ptr (const scoped_ptr&);
|
||||
scoped_ptr& operator= (const scoped_ptr&);
|
||||
|
||||
typedef scoped_ptr<T> this_type;
|
||||
typedef T* this_type::*unspecified_bool_type;
|
||||
|
||||
void operator== (const scoped_ptr&) const;
|
||||
void operator!= (const scoped_ptr&) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
/// Constructor with default cleaner
|
||||
explicit scoped_ptr(T* p = nullptr) // never throws
|
||||
: ptr(p), cleaner(nullptr)
|
||||
{ }
|
||||
|
||||
/// Constructor. Takes ownership of \c p. During destruction
|
||||
/// \c cleanup_func will be called with p.
|
||||
template<typename F>
|
||||
explicit scoped_ptr(T* p, F cleanup_func)
|
||||
: ptr(p), cleaner(new internal::scoped_ptr_cleaner<T, F>(cleanup_func))
|
||||
{ }
|
||||
|
||||
/// Destructor - deletes the underlying pointer
|
||||
~scoped_ptr() // never throws
|
||||
{
|
||||
if (cleaner) {
|
||||
if (ptr)
|
||||
cleaner->cleanup(ptr);
|
||||
delete cleaner;
|
||||
} else {
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdelete-incomplete"
|
||||
#endif
|
||||
delete ptr;
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the old pointer and switch to the new one
|
||||
void reset(T* p = 0) // never throws
|
||||
{
|
||||
ASSERT(p == 0 || p != ptr); // catch self-reset errors
|
||||
this_type(p).swap(*this);
|
||||
}
|
||||
|
||||
/// Dereference operator
|
||||
T& operator*() const // never throws
|
||||
{
|
||||
ASSERT(ptr);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/// Arrow operator
|
||||
T* operator->() const // never throws
|
||||
{
|
||||
ASSERT(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// Get the underlying pointer
|
||||
T* get() const // never throws
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// Get a reference to the stored pointer.
|
||||
/// Useful for passing to functions who expect T**.
|
||||
T*& get_ref() // never throws
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
// Bool-like conversion
|
||||
operator unspecified_bool_type () const
|
||||
{
|
||||
return ptr == 0 ? 0 : &this_type::ptr;
|
||||
}
|
||||
|
||||
/// Null-check
|
||||
bool operator! () const // never throws
|
||||
{
|
||||
return ptr == 0;
|
||||
}
|
||||
|
||||
|
||||
/// Swap with another pointer
|
||||
void swap(scoped_ptr& b) // never throws
|
||||
{
|
||||
T * tmp = b.ptr;
|
||||
b.ptr = ptr;
|
||||
ptr = tmp;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Swap two pointers
|
||||
template<typename T> inline
|
||||
void swap(scoped_ptr<T>& a, scoped_ptr<T>& b) // never throws
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
|
||||
/// get_pointer(p) is a generic way to say p.get()
|
||||
template<typename T> inline
|
||||
T* get_pointer(const scoped_ptr<T>& p)
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // ns
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // hg
|
||||
|
||||
/// @}
|
||||
Reference in New Issue
Block a user