[gnote] Move semantics for main window actions



commit 28c4cef20a8c77fe411494d2ba9fca757f6813a7
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Mon Apr 18 22:27:21 2022 +0300

    Move semantics for main window actions

 src/mainwindowaction.cpp | 34 +++++++++++++++++-----------------
 src/mainwindowaction.hpp | 18 +++++++++---------
 src/recentchanges.cpp    | 22 ++++++++++------------
 3 files changed, 36 insertions(+), 38 deletions(-)
---
diff --git a/src/mainwindowaction.cpp b/src/mainwindowaction.cpp
index a395a0bc..f0324ca5 100644
--- a/src/mainwindowaction.cpp
+++ b/src/mainwindowaction.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2015-2016 Aurimas Cernius
+ * Copyright (C) 2015-2016,2022 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,46 +21,46 @@
 
 namespace gnote {
 
-MainWindowAction::Ptr MainWindowAction::create(const Glib::ustring & name)
+MainWindowAction::Ptr MainWindowAction::create(Glib::ustring && name)
 {
-  return Ptr(new MainWindowAction(name));
+  return Ptr(new MainWindowAction(std::move(name)));
 }
 
-MainWindowAction::Ptr MainWindowAction::create(const Glib::ustring & name, bool state)
+MainWindowAction::Ptr MainWindowAction::create(Glib::ustring && name, bool state)
 {
-  return Ptr(new MainWindowAction(name, state));
+  return Ptr(new MainWindowAction(std::move(name), state));
 }
 
-MainWindowAction::Ptr MainWindowAction::create(const Glib::ustring & name, int state)
+MainWindowAction::Ptr MainWindowAction::create(Glib::ustring && name, int state)
 {
-  return Ptr(new MainWindowAction(name, state));
+  return Ptr(new MainWindowAction(std::move(name), state));
 }
 
-MainWindowAction::Ptr MainWindowAction::create(const Glib::ustring & name, const Glib::ustring & state)
+MainWindowAction::Ptr MainWindowAction::create(Glib::ustring && name, Glib::ustring && state)
 {
-  return Ptr(new MainWindowAction(name, state));
+  return Ptr(new MainWindowAction(std::move(name), std::move(state)));
 }
 
-MainWindowAction::MainWindowAction(const Glib::ustring & name)
-  : Gio::SimpleAction(name)
+MainWindowAction::MainWindowAction(Glib::ustring && name)
+  : Gio::SimpleAction(std::move(name))
   , m_modifying(true)
 {
 }
 
-MainWindowAction::MainWindowAction(const Glib::ustring & name, bool state)
-  : Gio::SimpleAction(name, Glib::Variant<bool>::create(state))
+MainWindowAction::MainWindowAction(Glib::ustring && name, bool state)
+  : Gio::SimpleAction(std::move(name), Glib::Variant<bool>::create(state))
   , m_modifying(true)
 {
 }
 
-MainWindowAction::MainWindowAction(const Glib::ustring & name, int state)
-  : Gio::SimpleAction(name, Glib::VARIANT_TYPE_INT32, Glib::Variant<gint32>::create(state))
+MainWindowAction::MainWindowAction(Glib::ustring && name, int state)
+  : Gio::SimpleAction(std::move(name), Glib::VARIANT_TYPE_INT32, Glib::Variant<gint32>::create(state))
   , m_modifying(true)
 {
 }
 
-MainWindowAction::MainWindowAction(const Glib::ustring & name, const Glib::ustring & state)
-  : Gio::SimpleAction(name, Glib::VARIANT_TYPE_STRING, Glib::Variant<Glib::ustring>::create(state))
+MainWindowAction::MainWindowAction(Glib::ustring && name, Glib::ustring && state)
+  : Gio::SimpleAction(std::move(name), Glib::VARIANT_TYPE_STRING, 
Glib::Variant<Glib::ustring>::create(std::move(state)))
   , m_modifying(true)
 {
 }
diff --git a/src/mainwindowaction.hpp b/src/mainwindowaction.hpp
index 4eb115ad..01e81c98 100644
--- a/src/mainwindowaction.hpp
+++ b/src/mainwindowaction.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2015-2016,2019 Aurimas Cernius
+ * Copyright (C) 2015-2016,2019,2022 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,10 +31,10 @@ class MainWindowAction
 public:
   typedef Glib::RefPtr<MainWindowAction> Ptr;
 
-  static Ptr create(const Glib::ustring & name);
-  static Ptr create(const Glib::ustring & name, bool state);
-  static Ptr create(const Glib::ustring & name, int state);
-  static Ptr create(const Glib::ustring & name, const Glib::ustring & state);
+  static Ptr create(Glib::ustring && name);
+  static Ptr create(Glib::ustring && name, bool state);
+  static Ptr create(Glib::ustring && name, int state);
+  static Ptr create(Glib::ustring && name, Glib::ustring && state);
 
   void set_state(const Glib::VariantBase & value)
     {
@@ -49,10 +49,10 @@ public:
       return m_modifying;
     }
 protected:
-  MainWindowAction(const Glib::ustring & name);
-  MainWindowAction(const Glib::ustring & name, bool state);
-  MainWindowAction(const Glib::ustring & name, int state);
-  MainWindowAction(const Glib::ustring & name, const Glib::ustring & state);
+  MainWindowAction(Glib::ustring && name);
+  MainWindowAction(Glib::ustring && name, bool state);
+  MainWindowAction(Glib::ustring && name, int state);
+  MainWindowAction(Glib::ustring && name, Glib::ustring && state);
 private:
   bool m_modifying;
 };
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 624b7e1b..35875c9f 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -181,24 +181,22 @@ namespace gnote {
   void NoteRecentChanges::register_actions()
   {
     auto & am = m_gnote.action_manager();
-    std::map<Glib::ustring, const Glib::VariantType*> actions = am.get_main_window_actions();
-    for(std::map<Glib::ustring, const Glib::VariantType*>::iterator iter = actions.begin();
-        iter != actions.end(); ++iter) {
+    for(auto & action_def : am.get_main_window_actions()) {
       MainWindowAction::Ptr action;
-      if(iter->second == NULL) {
-        add_action(action = MainWindowAction::create(iter->first));
+      if(action_def.second == NULL) {
+        add_action(action = MainWindowAction::create(Glib::ustring(action_def.first)));
       }
-      else if(iter->second == &Glib::Variant<bool>::variant_type()) {
-        add_action(action = MainWindowAction::create(iter->first, false));
+      else if(action_def.second == &Glib::Variant<bool>::variant_type()) {
+        add_action(action = MainWindowAction::create(Glib::ustring(action_def.first), false));
       }
-      else if(iter->second == &Glib::Variant<gint32>::variant_type()) {
-        add_action(action = MainWindowAction::create(iter->first, 0));
+      else if(action_def.second == &Glib::Variant<gint32>::variant_type()) {
+        add_action(action = MainWindowAction::create(Glib::ustring(action_def.first), 0));
       }
-      else if(iter->second == &Glib::Variant<Glib::ustring>::variant_type()) {
-        add_action(action = MainWindowAction::create(iter->first, Glib::ustring("")));
+      else if(action_def.second == &Glib::Variant<Glib::ustring>::variant_type()) {
+        add_action(action = MainWindowAction::create(Glib::ustring(action_def.first), Glib::ustring("")));
       }
       if(action) {
-        action->is_modifying(am.is_modifying_main_window_action(iter->first));
+        action->is_modifying(am.is_modifying_main_window_action(action_def.first));
       }
     }
     find_action("close-window")->signal_activate()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]