[glom] Replace std::shared<>(new) with std::make_shared<>.



commit c3324e1d048f578f41d1bf4210f99293ad842842
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Aug 20 20:14:39 2015 +0200

    Replace std::shared<>(new) with std::make_shared<>.
    
    This is generally safer and more efficient.

 glom/box_reports.cc                                |    2 +-
 glom/dialog_existing_or_new.cc                     |    4 +-
 .../data_structure/layout/layoutitem_text.cc       |    4 +-
 glom/libglom/db_utils.cc                           |   20 ++++++------
 glom/libglom/document/document.cc                  |   30 ++++++++++----------
 glom/libglom/report_builder.cc                     |    2 +-
 glom/mode_data/test_flowtablewithfields.cc         |   22 +++++++-------
 glom/mode_design/fields/box_db_table_definition.cc |    2 +-
 .../mode_design/print_layouts/box_print_layouts.cc |    2 +-
 glom/utility_widgets/notebooklabelglom.cc          |    2 +-
 tests/test_document_change.cc                      |    2 +-
 11 files changed, 46 insertions(+), 46 deletions(-)
---
diff --git a/glom/box_reports.cc b/glom/box_reports.cc
index dcaa784..1b97687 100644
--- a/glom/box_reports.cc
+++ b/glom/box_reports.cc
@@ -187,7 +187,7 @@ void Box_Reports::save_to_document()
 
       if(!report_name.empty() && std::find(listReports.begin(), listReports.end(), report_name) == 
listReports.end())
       {
-        std::shared_ptr<Report> report(new Report());
+        auto report = std::make_shared<Report>();
         report->set_name(report_name);
 
         report->set_title( m_AddDel.get_value(item, m_colTitle) , AppWindow::get_current_locale()); //TODO: 
Translations: Store the original in the TreeView.
diff --git a/glom/dialog_existing_or_new.cc b/glom/dialog_existing_or_new.cc
index f9e85f0..5d5241e 100644
--- a/glom/dialog_existing_or_new.cc
+++ b/glom/dialog_existing_or_new.cc
@@ -435,7 +435,7 @@ std::shared_ptr<Gtk::TreeModel::iterator> Dialog_ExistingOrNew::create_dummy_ite
 {
   auto iter = m_existing_model->append(parent->children());
   (*iter)[m_existing_columns.m_col_title] = text;
-  return std::shared_ptr<Gtk::TreeModel::iterator>(new Gtk::TreeModel::iterator(iter));
+  return std::make_shared<Gtk::TreeModel::iterator>(iter);
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -443,7 +443,7 @@ std::shared_ptr<Gtk::TreeModel::iterator> Dialog_ExistingOrNew::create_dummy_ite
 {
   auto iter = m_new_model->append(parent->children());
   (*iter)[m_new_columns.m_col_title] = text;
-  return std::shared_ptr<Gtk::TreeModel::iterator>(new Gtk::TreeModel::iterator(iter));
+  return std::make_shared<Gtk::TreeModel::iterator>(iter);
 }
 #endif //GLOM_ENABLE_CLIENT_ONLY
 
diff --git a/glom/libglom/data_structure/layout/layoutitem_text.cc 
b/glom/libglom/data_structure/layout/layoutitem_text.cc
index 5fb9638..448f9c9 100644
--- a/glom/libglom/data_structure/layout/layoutitem_text.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_text.cc
@@ -35,7 +35,7 @@ LayoutItem_Text::LayoutItem_Text(const LayoutItem_Text& src)
 {
   //Copy the underlying TranslatableItem, not the std::shared_ptr to it:
   const auto src_item = *(src.m_text);
-  m_text = std::shared_ptr<StaticText>(new StaticText(src_item));
+  m_text = std::make_shared<StaticText>(src_item);
 }
 
 LayoutItem_Text::~LayoutItem_Text()
@@ -62,7 +62,7 @@ LayoutItem_Text& LayoutItem_Text::operator=(const LayoutItem_Text& src)
 
   //Copy the underlying TranslatableItem, not the shardptr to it:
   const auto src_item = *(src.m_text);
-  m_text = std::shared_ptr<StaticText>(new StaticText(src_item));
+  m_text = std::make_shared<StaticText>(src_item);
 
   return *this;
 }
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index e699919..0d37f5a 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -519,29 +519,29 @@ bool add_standard_tables(const Document* document)
     //Auto-increment next values:
     if(!get_table_exists_in_database(GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME))
     {
-      std::shared_ptr<TableInfo> table_info(new TableInfo());
+      auto table_info = std::make_shared<TableInfo>();
       table_info->set_name(GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME);
       table_info->set_title_original(_("System: Auto Increments"));
       table_info->set_hidden(true);
 
       Document::type_vec_fields fields;
 
-      std::shared_ptr<Field> primary_key(new Field()); //It's not used, because there's only one record, but 
we must have one.
+      auto primary_key = std::make_shared<Field>(); //It's not used, because there's only one record, but we 
must have one.
       primary_key->set_name(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_ID);
       primary_key->set_glom_type(Field::TYPE_NUMERIC);
       fields.push_back(primary_key);
 
-      std::shared_ptr<Field> field_table_name(new Field());
+      auto field_table_name = std::make_shared<Field>();
       field_table_name->set_name(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME);
       field_table_name->set_glom_type(Field::TYPE_TEXT);
       fields.push_back(field_table_name);
 
-      std::shared_ptr<Field> field_field_name(new Field());
+      auto field_field_name = std::make_shared<Field>();
       field_field_name->set_name(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME);
       field_field_name->set_glom_type(Field::TYPE_TEXT);
       fields.push_back(field_field_name);
 
-      std::shared_ptr<Field> field_next_value(new Field());
+      auto field_next_value = std::make_shared<Field>();
       field_next_value->set_name(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_NEXT_VALUE);
       field_next_value->set_glom_type(Field::TYPE_TEXT);
       fields.push_back(field_next_value);
@@ -1163,7 +1163,7 @@ bool create_table_with_default_fields(Document* document, const Glib::ustring& t
   bool created = false;
 
   //Primary key:
-  std::shared_ptr<Field> field_primary_key(new Field());
+  auto field_primary_key = std::make_shared<Field>();
   field_primary_key->set_name(table_name + "_id");
   field_primary_key->set_title_original( Glib::ustring::compose("%1 ID", table_name) );
   field_primary_key->set_primary_key();
@@ -1180,21 +1180,21 @@ bool create_table_with_default_fields(Document* document, const Glib::ustring& t
   fields.push_back(field_primary_key);
 
   //Description:
-  std::shared_ptr<Field> field_description(new Field());
+  auto field_description = std::make_shared<Field>();
   field_description->set_name("description");
   field_description->set_title_original(_("Description")); //Use a translation, because the original locale 
will be marked as non-English if the current locale is non-English.
   field_description->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_description);
 
   //Comments:
-  std::shared_ptr<Field> field_comments(new Field());
+  auto field_comments = std::make_shared<Field>();
   field_comments->set_name("comments");
   field_comments->set_title_original(_("Comments"));
   field_comments->set_glom_type(Field::TYPE_TEXT);
   field_comments->m_default_formatting.set_text_format_multiline();
   fields.push_back(field_comments);
 
-  std::shared_ptr<TableInfo> table_info(new TableInfo());
+  auto table_info = std::make_shared<TableInfo>();
   table_info->set_name(table_name);
   table_info->set_title_original( Utils::title_from_string( table_name ) ); //Start with a title that might 
be appropriate.
 
@@ -2306,7 +2306,7 @@ type_map_fields get_record_field_values(const Document* document, const Glib::us
   type_vecLayoutFields fieldsToGet;
   for(const auto& field : fields)
   {
-    const auto layout_item = std::shared_ptr<LayoutItem_Field>(new LayoutItem_Field());
+    const auto layout_item = std::make_shared<LayoutItem_Field>();
     layout_item->set_full_field_details(field);
 
     fieldsToGet.push_back(layout_item);
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 2e05e34..900eaf3 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -531,60 +531,60 @@ std::shared_ptr<TableInfo> Document::create_table_system_preferences(type_vec_fi
 
   fields.clear();
 
-  std::shared_ptr<Field> primary_key(new Field()); //It's not used, because there's only one record, but we 
must have one.
+  auto primary_key = std::make_shared<Field>(); //It's not used, because there's only one record, but we 
must have one.
   primary_key->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ID);
   primary_key->set_glom_type(Field::TYPE_NUMERIC);
   fields.push_back(primary_key);
 
-  std::shared_ptr<Field> field_name(new Field());
+  auto field_name = std::make_shared<Field>();
   field_name->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_NAME);
   field_name->set_title_original(_("System Name"));
   field_name->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_name);
 
-  std::shared_ptr<Field> field_org_name(new Field());
+  auto field_org_name = std::make_shared<Field>();
   field_org_name->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_NAME);
   field_org_name->set_title_original(_("Organisation Name"));
   field_org_name->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_name);
 
-  std::shared_ptr<Field> field_org_logo(new Field());
+  auto field_org_logo = std::make_shared<Field>();
   field_org_logo->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_LOGO);
   field_org_logo->set_title_original(_("Organisation Logo"));
   field_org_logo->set_glom_type(Field::TYPE_IMAGE);
   fields.push_back(field_org_logo);
 
-  std::shared_ptr<Field> field_org_address_street(new Field());
+  auto field_org_address_street = std::make_shared<Field>();
   field_org_address_street->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_STREET);
   field_org_address_street->set_title_original(_("Street"));
   field_org_address_street->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_address_street);
 
-  std::shared_ptr<Field> field_org_address_street2(new Field());
+  auto field_org_address_street2 = std::make_shared<Field>();
   field_org_address_street2->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_STREET2);
   field_org_address_street2->set_title_original(_("Street (line 2)"));
   field_org_address_street2->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_address_street2);
 
-  std::shared_ptr<Field> field_org_address_town(new Field());
+  auto field_org_address_town = std::make_shared<Field>();
   field_org_address_town->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_TOWN);
   field_org_address_town->set_title_original(_("City"));
   field_org_address_town->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_address_town);
 
-  std::shared_ptr<Field> field_org_address_county(new Field());
+  auto field_org_address_county = std::make_shared<Field>();
   field_org_address_county->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_COUNTY);
   field_org_address_county->set_title_original(_("State"));
   field_org_address_county->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_address_county);
 
-  std::shared_ptr<Field> field_org_address_country(new Field());
+  auto field_org_address_country = std::make_shared<Field>();
   field_org_address_country->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_COUNTRY);
   field_org_address_country->set_title_original(_("Country"));
   field_org_address_country->set_glom_type(Field::TYPE_TEXT);
   fields.push_back(field_org_address_country);
 
-  std::shared_ptr<Field> field_org_address_postcode(new Field());
+  auto field_org_address_postcode = std::make_shared<Field>();
   field_org_address_postcode->set_name(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_POSTCODE);
   field_org_address_postcode->set_title_original(_("Zip Code"));
   field_org_address_postcode->set_glom_type(Field::TYPE_TEXT);
@@ -2647,7 +2647,7 @@ bool Document::load_after(int& failure_code)
           const auto doctableinfo = std::make_shared<DocumentTableInfo>();
           m_tables[table_name] = doctableinfo;
 
-          std::shared_ptr<TableInfo> table_info(new TableInfo());
+          auto table_info = std::make_shared<TableInfo>();
           table_info->set_name(table_name);
           table_info->set_hidden( XmlUtils::get_node_attribute_value_as_bool(nodeTable, 
GLOM_ATTRIBUTE_HIDDEN) );
           table_info->set_default( XmlUtils::get_node_attribute_value_as_bool(nodeTable, 
GLOM_ATTRIBUTE_DEFAULT) );
@@ -2702,7 +2702,7 @@ bool Document::load_after(int& failure_code)
               const auto node_field = dynamic_cast<xmlpp::Element*>(item_field);
               if(node_field)
               {
-                std::shared_ptr<Field> field(new Field());
+                auto field = std::make_shared<Field>();
 
                 const auto strName = XmlUtils::get_node_attribute_value(node_field, GLOM_ATTRIBUTE_NAME);
                 field->set_name( strName );
@@ -2849,7 +2849,7 @@ bool Document::load_after(int& failure_code)
                       const auto group_name = XmlUtils::get_node_attribute_value(node_layout_group, 
GLOM_ATTRIBUTE_NAME);
                       if(!group_name.empty())
                       {
-                        std::shared_ptr<LayoutGroup> group(new LayoutGroup());
+                        auto group = std::make_shared<LayoutGroup>();
                         load_after_layout_group(node_layout_group, table_name, group);
 
                         layout_groups.push_back(group);
@@ -2882,7 +2882,7 @@ bool Document::load_after(int& failure_code)
 
                 //type_list_layout_groups layout_groups;
 
-                std::shared_ptr<Report> report(new Report());
+                auto report = std::make_shared<Report>();
                 report->set_name(report_name);
                 report->set_show_table_title(show_table_title);
 
@@ -2925,7 +2925,7 @@ bool Document::load_after(int& failure_code)
                 const auto name = XmlUtils::get_node_attribute_value(node_print_layout, GLOM_ATTRIBUTE_NAME);
                 const auto show_table_title = XmlUtils::get_node_attribute_value_as_bool(node_print_layout, 
GLOM_ATTRIBUTE_REPORT_SHOW_TABLE_TITLE);
 
-                std::shared_ptr<PrintLayout> print_layout(new PrintLayout());
+                auto print_layout = std::make_shared<PrintLayout>();
                 print_layout->set_name(name);
                 print_layout->set_show_table_title(show_table_title);
 
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index d63a8a1..b5abd7a 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -743,7 +743,7 @@ static void fill_standard_list_report_fill(const std::shared_ptr<Report>& report
 
 std::shared_ptr<Report> ReportBuilder::create_standard_list_report(const Document* document, const 
Glib::ustring& table_name)
 {
-  std::shared_ptr<Report> result(new Report());
+  auto result = std::make_shared<Report>();
   result->set_name("list");
   //Translators: This is a noun. It is the title of a report.
   result->set_title_original(_("List"));
diff --git a/glom/mode_data/test_flowtablewithfields.cc b/glom/mode_data/test_flowtablewithfields.cc
index 0273485..6c3d46a 100644
--- a/glom/mode_data/test_flowtablewithfields.cc
+++ b/glom/mode_data/test_flowtablewithfields.cc
@@ -40,36 +40,36 @@ void on_drag_data_get_entry(const Glib::RefPtr<Gdk::DragContext>&, Gtk::Selectio
 static void fill_flowtable(Glom::FlowTableWithFields& flowtable)
 {
   {
-    std::shared_ptr<Glom::LayoutItem_Text> item =
-      std::shared_ptr<Glom::LayoutItem_Text>(new Glom::LayoutItem_Text());
+    auto item =
+      std::make_shared<Glom::LayoutItem_Text>();
     item->set_text("test static text 1");
     flowtable.add_layout_item(item);
   }
 
   {
-    std::shared_ptr<Glom::LayoutItem_Text> item =
-      std::shared_ptr<Glom::LayoutItem_Text>(new Glom::LayoutItem_Text());
+    auto item =
+      std::make_shared<Glom::LayoutItem_Text>();
     item->set_text("test static text 2");
     item->set_title("title for text 2", AppWindow::get_current_locale());
     flowtable.add_layout_item(item);
   }
 
   {
-    std::shared_ptr<Glom::LayoutItem_Image> item =
-      std::shared_ptr<Glom::LayoutItem_Image>(new Glom::LayoutItem_Image());
+    auto item =
+      std::make_shared<Glom::LayoutItem_Image>();
     //item->set_image(somevalue);
     item->set_title("title for image", AppWindow::get_current_locale());
     flowtable.add_layout_item(item);
   }
   
-  std::shared_ptr<Glom::LayoutGroup> group = 
-    std::shared_ptr<Glom::LayoutGroup>(new Glom::LayoutGroup());
-  std::shared_ptr<Glom::LayoutItem_Text> item =
-    std::shared_ptr<Glom::LayoutItem_Text>(new Glom::LayoutItem_Text());
+  auto group = 
+    std::make_shared<Glom::LayoutGroup>();
+  auto item =
+    std::make_shared<Glom::LayoutItem_Text>();
   item->set_text("inner text 1");
   group->add_item(item);
   item =
-    std::shared_ptr<Glom::LayoutItem_Text>(new Glom::LayoutItem_Text());
+    std::make_shared<Glom::LayoutItem_Text>();
   item->set_text("inner text 2");
   group->add_item(item);
   flowtable.add_layout_item(group);
diff --git a/glom/mode_design/fields/box_db_table_definition.cc 
b/glom/mode_design/fields/box_db_table_definition.cc
index 90e63ef..14f52ce 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -191,7 +191,7 @@ void Box_DB_Table_Definition::on_adddel_add(const Gtk::TreeModel::iterator& row)
   Glib::ustring name = m_AddDel.get_value(row, m_colName);
   if(!name.empty())
   {
-    std::shared_ptr<Field> field(new Field());
+    auto field = std::make_shared<Field>();
     field->set_name(name);
     field->set_title( Utils::title_from_string(name) , AppWindow::get_current_locale()); //Start with a 
title that might be useful.
     field->set_glom_type(Field::TYPE_NUMERIC);
diff --git a/glom/mode_design/print_layouts/box_print_layouts.cc 
b/glom/mode_design/print_layouts/box_print_layouts.cc
index 9b4b67d..bc7d16f 100644
--- a/glom/mode_design/print_layouts/box_print_layouts.cc
+++ b/glom/mode_design/print_layouts/box_print_layouts.cc
@@ -185,7 +185,7 @@ void Box_Print_Layouts::save_to_document()
 
       if(!name.empty() && std::find(listItems.begin(), listItems.end(), name) == listItems.end())
       {
-        std::shared_ptr<PrintLayout> item(new PrintLayout());
+        auto item = std::make_shared<PrintLayout>();
         item->set_name(name);
 
         item->set_title( m_AddDel.get_value(row, m_colTitle) , AppWindow::get_current_locale()); //TODO: 
Translations: Store the original in the TreeView.
diff --git a/glom/utility_widgets/notebooklabelglom.cc b/glom/utility_widgets/notebooklabelglom.cc
index 4cc0252..250a7ea 100644
--- a/glom/utility_widgets/notebooklabelglom.cc
+++ b/glom/utility_widgets/notebooklabelglom.cc
@@ -73,7 +73,7 @@ AppWindow* NotebookLabel::get_appwindow()
 
 void NotebookLabel::on_menu_new_group_activate()
 {
-  std::shared_ptr<LayoutGroup> group(new LayoutGroup());
+  auto group = std::make_shared<LayoutGroup>();
   group->set_title_original(_("New Group"));
   group->set_name(_("Group"));
   
diff --git a/tests/test_document_change.cc b/tests/test_document_change.cc
index 8cb4139..59e9437 100644
--- a/tests/test_document_change.cc
+++ b/tests/test_document_change.cc
@@ -64,7 +64,7 @@ int main()
 
 
   const Glib::ustring table_name = "sometable";
-  std::shared_ptr<Glom::TableInfo> table_info(new Glom::TableInfo());
+  auto table_info = std::make_shared<Glom::TableInfo>();
   table_info->set_name(table_name);
   
   const Glib::ustring table_title = "sometabletitle";


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