[glom] C++11: Use {} initialization for std::vectors.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] C++11: Use {} initialization for std::vectors.
- Date: Sat, 4 Jul 2015 20:46:24 +0000 (UTC)
commit 299f34f63ab6bb016e4f970c548a28fa50553793
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Jul 3 09:08:33 2015 +0200
C++11: Use {} initialization for std::vectors.
Instead of lots of push_back().
glom/appwindow.cc | 3 +-
.../connectionpool_backends/mysql_central.cc | 17 ++++-----
.../connectionpool_backends/postgres_central.cc | 15 ++++----
glom/libglom/data_structure/field.cc | 37 +++++++++-----------
tests/test_selfhosting_new_empty_then_users.cc | 36 +++++++++---------
5 files changed, 51 insertions(+), 57 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index f1c5de8..5a53dbd 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -465,8 +465,7 @@ void AppWindow::on_menu_help_about()
m_pAbout->set_comments(_("A Database GUI"));
m_pAbout->set_version(PACKAGE_VERSION);
m_pAbout->set_copyright(_("© 2000-2011 Murray Cumming, Openismus GmbH"));
- std::vector<Glib::ustring> vecAuthors;
- vecAuthors.push_back("Murray Cumming <murrayc murrayc com>");
+ const std::vector<Glib::ustring> vecAuthors({"Murray Cumming <murrayc murrayc com>"});
m_pAbout->set_authors(vecAuthors);
//For some reason this use of the resource:// syntax does not work:
diff --git a/glom/libglom/connectionpool_backends/mysql_central.cc
b/glom/libglom/connectionpool_backends/mysql_central.cc
index cb293f0..505c2ca 100644
--- a/glom/libglom/connectionpool_backends/mysql_central.cc
+++ b/glom/libglom/connectionpool_backends/mysql_central.cc
@@ -33,16 +33,15 @@ namespace ConnectionPoolBackends
{
MySQLCentralHosted::MySQLCentralHosted()
-: m_try_other_ports(true)
+: m_list_ports( {
+ //TODO_MySQL:
+ "5432", //Ubuntu Breezy seems to default to this for MySQL 7.4, and this is probably the default for
most mysql installations, including Fedora.
+ "5433", //Ubuntu Dapper seems to default to this for MySQL 8.1, probably to avoid a clash with MySQL 7.4
+ "5434", //Earlier versions of Ubuntu Feisty defaulted to this for MySQL 8.2.
+ "5435", //In case Ubuntu increases the port number again in future.
+ "5436"} ), //In case Ubuntu increases the port number again in future.
+ m_try_other_ports(true)
{
- //TODO_MySQL:
- m_list_ports.push_back("5432"); //Ubuntu Breezy seems to default to this for MySQL 7.4, and this is
probably the default for most mysql installations, including Fedora.
-
- m_list_ports.push_back("5433"); //Ubuntu Dapper seems to default to this for MySQL 8.1, probably to avoid
a clash with MySQL 7.4
-
- m_list_ports.push_back("5434"); //Earlier versions of Ubuntu Feisty defaulted to this for MySQL 8.2.
- m_list_ports.push_back("5435"); //In case Ubuntu increases the port number again in future.
- m_list_ports.push_back("5436"); //In case Ubuntu increases the port number again in future.
}
void MySQLCentralHosted::set_host(const Glib::ustring& value)
diff --git a/glom/libglom/connectionpool_backends/postgres_central.cc
b/glom/libglom/connectionpool_backends/postgres_central.cc
index 379cdab..528ee01 100644
--- a/glom/libglom/connectionpool_backends/postgres_central.cc
+++ b/glom/libglom/connectionpool_backends/postgres_central.cc
@@ -33,15 +33,14 @@ namespace ConnectionPoolBackends
{
PostgresCentralHosted::PostgresCentralHosted()
-: m_try_other_ports(true)
+: m_list_ports( {
+ "5432", //Ubuntu Breezy seems to default to this for Postgres 7.4, and this is probably the default for
most postgres installations, including Fedora.
+ "5433", //Ubuntu Dapper seems to default to this for Postgres 8.1, probably to avoid a clash with
Postgres 7.4
+ "5434", //Earlier versions of Ubuntu Feisty defaulted to this for Postgres 8.2.
+ "5435", //In case Ubuntu increases the port number again in future.
+ "5436"} ), //In case Ubuntu increases the port number again in future.
+ m_try_other_ports(true)
{
- m_list_ports.push_back("5432"); //Ubuntu Breezy seems to default to this for Postgres 7.4, and this is
probably the default for most postgres installations, including Fedora.
-
- m_list_ports.push_back("5433"); //Ubuntu Dapper seems to default to this for Postgres 8.1, probably to
avoid a clash with Postgres 7.4
-
- m_list_ports.push_back("5434"); //Earlier versions of Ubuntu Feisty defaulted to this for Postgres 8.2.
- m_list_ports.push_back("5435"); //In case Ubuntu increases the port number again in future.
- m_list_ports.push_back("5436"); //In case Ubuntu increases the port number again in future.
}
void PostgresCentralHosted::set_host(const Glib::ustring& value)
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index af9e90c..b4636b7 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -691,44 +691,41 @@ void Field::init_map()
//These are the conversions know to be supported by the used version of postgres
m_map_conversions.clear();
- type_list_conversion_targets list_conversions;
-
- //Numeric:
- list_conversions.clear();
- list_conversions.push_back(Field::TYPE_BOOLEAN);
- list_conversions.push_back(Field::TYPE_TEXT);
+ type_list_conversion_targets list_conversions( {
+ Field::TYPE_BOOLEAN,
+ Field::TYPE_TEXT} );
//to_date(numeric) was supported in 8.2 but not in 8.3: list_conversions.push_back(Field::TYPE_DATE);
//to_timestamp(numeric) was supported in 8.2 but not in 8.3:
list_conversions.push_back(Field::TYPE_TIME);
m_map_conversions[Field::TYPE_NUMERIC] = list_conversions;
//Text:
- list_conversions.clear();
- list_conversions.push_back(Field::TYPE_BOOLEAN);
- list_conversions.push_back(Field::TYPE_NUMERIC);
- list_conversions.push_back(Field::TYPE_DATE);
- list_conversions.push_back(Field::TYPE_TIME);
+ list_conversions = {
+ Field::TYPE_BOOLEAN,
+ Field::TYPE_NUMERIC,
+ Field::TYPE_DATE,
+ Field::TYPE_TIME};
m_map_conversions[Field::TYPE_TEXT] = list_conversions;
//Boolean:
- list_conversions.clear();
- list_conversions.push_back(Field::TYPE_TEXT);
- list_conversions.push_back(Field::TYPE_NUMERIC);
+ list_conversions = {
+ Field::TYPE_TEXT,
+ Field::TYPE_NUMERIC};
//to_timestamp(numeric) was supported in 8.2 but not in 8.3:
list_conversions.push_back(Field::TYPE_DATE);
//to_timestamp(numeric) was supported in 8.2 but not in 8.3:
list_conversions.push_back(Field::TYPE_TIME);
m_map_conversions[Field::TYPE_BOOLEAN] = list_conversions;
//Date:
- list_conversions.clear();
- list_conversions.push_back(Field::TYPE_TEXT);
+ list_conversions = {
+ Field::TYPE_TEXT};
//to_number(textcat()) was supported in 8.2 but not in 8.3:
list_conversions.push_back(Field::TYPE_NUMERIC);
//to_number(textcat()) was supported in 8.2 but not in 8.3:
list_conversions.push_back(Field::TYPE_BOOLEAN);
m_map_conversions[Field::TYPE_DATE] = list_conversions;
//Time:
- list_conversions.clear();
- list_conversions.push_back(Field::TYPE_TEXT);
- list_conversions.push_back(Field::TYPE_NUMERIC);
- list_conversions.push_back(Field::TYPE_BOOLEAN);
+ list_conversions = {
+ Field::TYPE_TEXT,
+ Field::TYPE_NUMERIC,
+ Field::TYPE_BOOLEAN};
m_map_conversions[Field::TYPE_TIME] = list_conversions;
diff --git a/tests/test_selfhosting_new_empty_then_users.cc b/tests/test_selfhosting_new_empty_then_users.cc
index b22d940..2d101dc 100644
--- a/tests/test_selfhosting_new_empty_then_users.cc
+++ b/tests/test_selfhosting_new_empty_then_users.cc
@@ -132,12 +132,12 @@ static bool test(Glom::Document::HostingMode hosting_mode)
typedef std::vector<Glib::ustring> type_vec_strings;
- type_vec_strings table_names;
- table_names.push_back("sometable");
- table_names.push_back("SomeTableWithUpperCase");
- table_names.push_back("sometable with space characters");
- table_names.push_back("sometable with a \" doublequote character");
- table_names.push_back("sometable with a ' quote character");
+ type_vec_strings table_names( {
+ "sometable",
+ "SomeTableWithUpperCase",
+ "sometable with space characters",
+ "sometable with a \" doublequote character",
+ "sometable with a ' quote character"} );
//MySQL has a 64-character limit on SQL identifiers:
if(hosting_mode != Glom::Document::HOSTING_MODE_MYSQL_SELF)
@@ -180,12 +180,12 @@ static bool test(Glom::Document::HostingMode hosting_mode)
//Add groups:
- type_vec_strings group_names;
- group_names.push_back("somegroup1");
- group_names.push_back("somegroup with space characters");
- group_names.push_back("somegroup with a \" doublequote character");
- group_names.push_back("somegroup with a ' quote character");
- group_names.push_back("somegroupwithaverylongnameyaddayaddayaddayaddayaddyaddayaddayad"); //Almost too big.
+ type_vec_strings group_names( {
+ "somegroup1",
+ "somegroup with space characters",
+ "somegroup with a \" doublequote character",
+ "somegroup with a ' quote character",
+ "somegroupwithaverylongnameyaddayaddayaddayaddayaddyaddayaddayad"} ); //Almost too big.
//We expect this to fail because of an apparently-undocumented max pg_user size of 63 characters in
PostgreSQL:
//group_names.push_back("somegroupwithaverylongnameyaddayaddayaddayaddayaddyaddayaddayadd");
@@ -200,12 +200,12 @@ static bool test(Glom::Document::HostingMode hosting_mode)
//Add users:
//TODO: Test strange passwords.
- type_vec_strings user_names;
- user_names.push_back("someuser1");
- user_names.push_back("someuser with space characters");
- user_names.push_back("someuser with a \" doublequote character");
- user_names.push_back("someuser with a ' quote character");
- user_names.push_back("someuserwithaverylongnameyaddayaddayaddayaddayaddyaddayadda"); //Almost too big,
with space for the numeric suffix below.
+ type_vec_strings user_names( {
+ "someuser1",
+ "someuser with space characters",
+ "someuser with a \" doublequote character",
+ "someuser with a ' quote character",
+ "someuserwithaverylongnameyaddayaddayaddayaddayaddyaddayadda"} ); //Almost too big, with space for the
numeric suffix below.
//We expect this to fail because of an apparently-undocumented max pg_user size of 63 characters in
PostgreSQL:
//user_names.push_back("someuserwithaverylongnameyaddayaddayaddayaddayaddyaddayaddayadd");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]