[glom] C++11: More use of auto.



commit d02a2e8b0ddfd39562f3ab552be789a4316740bf
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Nov 6 20:19:57 2016 +0100

    C++11: More use of auto.

 glom/base_db.cc                                    |    6 ++--
 glom/import_csv/csv_parser.cc                      |    2 +-
 glom/libglom/data_structure/field.cc               |    4 +-
 glom/libglom/db_utils_export.cc                    |    2 +-
 glom/libglom/document/document.cc                  |    6 ++--
 glom/libglom/file_utils.cc                         |    4 +-
 glom/libglom/python_embed/py_glom_record.cc        |    2 +-
 glom/libglom/string_utils.cc                       |   28 ++++++++++----------
 glom/libglom/translations_po.cc                    |    4 +-
 glom/libglom/utils.cc                              |   10 +++---
 glom/mode_data/datawidget/treemodel_db.cc          |    4 +-
 glom/mode_design/fields/box_db_table_definition.cc |    4 +-
 glom/mode_design/fields/combo_fieldtype.cc         |    2 +-
 glom/mode_design/fields/dialog_fielddefinition.cc  |    2 +-
 glom/utility_widgets/adddel/adddel.cc              |    2 +-
 15 files changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/glom/base_db.cc b/glom/base_db.cc
index ebabd14..2cfc704 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -978,13 +978,13 @@ Base_DB::type_list_const_field_items Base_DB::get_calculation_fields(const Glib:
 
   while(index < count)
   {
-    Glib::ustring::size_type pos_find = calculation.find(prefix, index);
+    auto pos_find = calculation.find(prefix, index);
     if(pos_find != Glib::ustring::npos)
     {
-      Glib::ustring::size_type pos_find_end = calculation.find("\"]", pos_find);
+      auto pos_find_end = calculation.find("\"]", pos_find);
       if(pos_find_end  != Glib::ustring::npos)
       {
-        Glib::ustring::size_type pos_start = pos_find + prefix_size;
+        auto pos_start = pos_find + prefix_size;
         const auto field_name = calculation.substr(pos_start, pos_find_end - pos_start);
 
         auto field_found = document->get_field(table_name, field_name);
diff --git a/glom/import_csv/csv_parser.cc b/glom/import_csv/csv_parser.cc
index 97f208f..c48a21c 100644
--- a/glom/import_csv/csv_parser.cc
+++ b/glom/import_csv/csv_parser.cc
@@ -377,7 +377,7 @@ bool CsvParser::on_idle_parse()
         m_in_quotes = false;
 
         /*
-        const size_t len = pos - prev;
+        const auto len = pos - prev;
         std::string quoted_text;
         if(len)
           quoted_text = std::string(prev, len);
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index dd44b68..aedc723 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -585,7 +585,7 @@ Field::glom_field_type Field::get_glom_type_for_gda_type(GType gda_type)
 {
   init_map();
 
-  Field::glom_field_type result = glom_field_type::INVALID;
+  auto result = glom_field_type::INVALID;
 
   //Get the glom type used for this gda type:
   {
@@ -788,7 +788,7 @@ Glib::ustring Field::get_type_name_ui(glom_field_type glom_type)
 //static:
 Field::glom_field_type Field::get_type_for_ui_name(const Glib::ustring& glom_type)
 {
-  glom_field_type result = glom_field_type::INVALID;
+  auto result = glom_field_type::INVALID;
 
   for(const auto& the_pair : m_map_type_names_ui)
   {
diff --git a/glom/libglom/db_utils_export.cc b/glom/libglom/db_utils_export.cc
index f8d8115..221c4f2 100644
--- a/glom/libglom/db_utils_export.cc
+++ b/glom/libglom/db_utils_export.cc
@@ -146,7 +146,7 @@ void export_data_to_stream(const std::shared_ptr<Document>& document, std::ostre
               // though we believe that all these problems are now fixed in File::to_file_format():
 
               const char* newline_to_find = "\r\n";
-              size_t pos = field_text.find_first_of(newline_to_find);
+              auto pos = field_text.find_first_of(newline_to_find);
               if(pos != std::string::npos)
               {
                 std::cerr << G_STRFUNC << ": export: binary data field text contains an unexpected newline: 
" << field_text << std::endl;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 5a43c29..44a7601 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1899,7 +1899,7 @@ void Document::load_after_layout_item_formatting(const xmlpp::Element* element,
 
   auto field = std::dynamic_pointer_cast<LayoutItem_Field>(layout_item);
 
-  Field::glom_field_type field_type = Field::glom_field_type::INVALID;
+  auto field_type = Field::glom_field_type::INVALID;
   if(field)
     field_type = field->get_glom_type();
 
@@ -2724,7 +2724,7 @@ bool Document::load_after(int& failure_code)
                 const auto field_type = XmlUtils::get_node_attribute_value(node_field, GLOM_ATTRIBUTE_TYPE);
 
                 //Get the type enum for this string representation of the type:
-                Field::glom_field_type field_type_enum = Field::glom_field_type::INVALID;
+                auto field_type_enum = Field::glom_field_type::INVALID;
                 for(const auto& type_pair : type_names)
                 {
                   if(type_pair.second == field_type)
@@ -3083,7 +3083,7 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
 
   auto field = std::dynamic_pointer_cast<const LayoutItem_Field>(layout_item);
 
-  Field::glom_field_type field_type = Field::glom_field_type::INVALID;
+  auto field_type = Field::glom_field_type::INVALID;
   if(field)
     field_type = field->get_glom_type();
 
diff --git a/glom/libglom/file_utils.cc b/glom/libglom/file_utils.cc
index 7417a07..5f025a2 100644
--- a/glom/libglom/file_utils.cc
+++ b/glom/libglom/file_utils.cc
@@ -91,7 +91,7 @@ Glib::ustring get_file_uri_without_extension(const Glib::ustring& uri)
 
   const Glib::ustring filename_part = file->get_basename();
 
-  const Glib::ustring::size_type pos_dot = filename_part.rfind(".");
+  const auto pos_dot = filename_part.rfind(".");
   if(pos_dot == Glib::ustring::npos)
     return uri; //There was no extension, so just return the existing URI.
   else
@@ -117,7 +117,7 @@ std::string get_file_path_without_extension(const std::string& filepath)
 
   const Glib::ustring filename_part = file->get_basename();
 
-  const Glib::ustring::size_type pos_dot = filename_part.rfind(".");
+  const auto pos_dot = filename_part.rfind(".");
   if(pos_dot == Glib::ustring::npos)
     return filepath; //There was no extension, so just return the existing URI.
   else
diff --git a/glom/libglom/python_embed/py_glom_record.cc b/glom/libglom/python_embed/py_glom_record.cc
index 6fdf206..19b3ae3 100644
--- a/glom/libglom/python_embed/py_glom_record.cc
+++ b/glom/libglom/python_embed/py_glom_record.cc
@@ -145,7 +145,7 @@ void PyGlomRecord::setitem(const boost::python::object& key, const boost::python
      return;
   }
 
-  const Field::glom_field_type field_type = field->get_glom_type(); //TODO
+  const auto field_type = field->get_glom_type(); //TODO
 
   Gnome::Gda::Value field_value;
   GValue value_c = {0, {{0}}};
diff --git a/glom/libglom/string_utils.cc b/glom/libglom/string_utils.cc
index 0ac43bf..c53ed30 100644
--- a/glom/libglom/string_utils.cc
+++ b/glom/libglom/string_utils.cc
@@ -111,9 +111,9 @@ Glib::ustring string_replace(const Glib::ustring& src, const Glib::ustring& sear
   //TODO_Performance:
 
   Glib::ustring result;
-  const size_t src_length = src.size();
-  const size_t search_for_length = search_for.size();
-  //const size_t replace_with_length = replace_with.size();
+  const auto src_length = src.size();
+  const auto search_for_length = search_for.size();
+  //const auto replace_with_length = replace_with.size();
 
   size_t src_index = 0;
   size_t src_index_section_start = 0;
@@ -175,14 +175,14 @@ Glib::ustring string_trim(const Glib::ustring& str, const Glib::ustring& to_remo
   Glib::ustring result = str;
 
   //Remove from the start:
-  Glib::ustring::size_type posOpenBracket = result.find(to_remove);
+  auto posOpenBracket = result.find(to_remove);
   if(posOpenBracket == 0)
   {
     result = result.substr(to_remove.size());
   }
 
   //Remove from the end:
-  Glib::ustring::size_type posCloseBracket = result.rfind(to_remove);
+  auto posCloseBracket = result.rfind(to_remove);
   if(posCloseBracket == (result.size() - to_remove.size()))
   {
     result = result.substr(0, posCloseBracket);
@@ -195,8 +195,8 @@ Glib::ustring string_remove_suffix(const Glib::ustring& str, const Glib::ustring
 {
   //There is also g_string_has_suffix(), but I assume that is case sensitive. murrayc.
 
-  const Glib::ustring::size_type size = str.size();
-  const Glib::ustring::size_type suffix_size = suffix.size();
+  const auto size = str.size();
+  const auto suffix_size = suffix.size();
   if(size < suffix_size)
     return str;
 
@@ -262,8 +262,8 @@ type_vec_strings string_separate(const Glib::ustring& str, const Glib::ustring&
 
   type_vec_strings result;
 
-  const Glib::ustring::size_type size = str.size();
-  const Glib::ustring::size_type size_separator = separator.size();
+  const auto size = str.size();
+  const auto size_separator = separator.size();
 
   //A stack of quotes, so that we can handle nested quotes, whether they are " or ':
   std::stack<Glib::ustring> m_current_quotes;
@@ -273,7 +273,7 @@ type_vec_strings string_separate(const Glib::ustring& str, const Glib::ustring&
   while(unprocessed_start < size)
   {
     //std::cout << "while unprocessed: un_processed_start=" << unprocessed_start << std::endl;
-    Glib::ustring::size_type posComma = str.find(separator, unprocessed_start);
+    auto posComma = str.find(separator, unprocessed_start);
 
     Glib::ustring item;
     if(posComma != Glib::ustring::npos)
@@ -285,7 +285,7 @@ type_vec_strings string_separate(const Glib::ustring& str, const Glib::ustring&
       {
         //std::cout << "  debug: attempting to ignore quoted separators: " << separator << std::endl;
 
-        Glib::ustring::size_type posLastQuote = unprocessed_start;
+        auto posLastQuote = unprocessed_start;
 
         //std::cout << "    debug: posLastQuote=" << posLastQuote << std::endl;
         //std::cout << "    debug: posComma=" << posComma << std::endl;
@@ -300,13 +300,13 @@ type_vec_strings string_separate(const Glib::ustring& str, const Glib::ustring&
             closing_quote = m_current_quotes.top();
 
           //std::cout << "   posLastQuote=" << posLastQuote << std::endl;
-          const Glib::ustring::size_type posSingleQuote = str.find("'", posLastQuote);
-          const Glib::ustring::size_type posDoubleQuote = str.find("\"", posLastQuote);
+          const auto posSingleQuote = str.find("'", posLastQuote);
+          const auto posDoubleQuote = str.find("\"", posLastQuote);
 
           // std::cout << "   posSingleQuote=" << posSingleQuote << "posDoubleQuote=" << posDoubleQuote << 
std::endl;
 
           //Which quote, if any, is first:
-          Glib::ustring::size_type posFirstQuote = posSingleQuote;
+          auto posFirstQuote = posSingleQuote;
           if( (posDoubleQuote != Glib::ustring::npos) && (posDoubleQuote < posFirstQuote) )
             posFirstQuote = posDoubleQuote;
 
diff --git a/glom/libglom/translations_po.cc b/glom/libglom/translations_po.cc
index 024ff9d..29120c5 100644
--- a/glom/libglom/translations_po.cc
+++ b/glom/libglom/translations_po.cc
@@ -276,7 +276,7 @@ bool import_translations_from_po_file(const std::shared_ptr<Document>& document,
   error_handler.error = &on_gettextpo_error;
   #endif //HAVE_GETTEXTPO_XERROR
 
-  po_file_t po_file = po_file_read(filename.c_str(), &error_handler);
+  auto po_file = po_file_read(filename.c_str(), &error_handler);
   if(!po_file)
   {
     // error message is already given by error_handle.
@@ -288,7 +288,7 @@ bool import_translations_from_po_file(const std::shared_ptr<Document>& document,
   for (int i = 0; domains[i] != 0; ++i)
   {
     //Look at each message:
-    po_message_iterator_t iter = po_message_iterator(po_file, domains[i]);
+    auto iter = po_message_iterator(po_file, domains[i]);
     po_message_t msg;
     while ((msg = po_next_message(iter)))
     {
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 2a8097d..b9e5a8f 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -48,7 +48,7 @@ Glib::ustring Utils::locale_simplify(const Glib::ustring& locale_id)
   //Look for LC_ALL or LC_COLLATE
   //(We use the locale name only to identify translations
   //Otherwise just start with the whole string.
-  Glib::ustring::size_type posCategory = result.find("LC_ALL=");
+  auto posCategory = result.find("LC_ALL=");
   if(posCategory != Glib::ustring::npos)
   {
     result = result.substr(posCategory);
@@ -63,21 +63,21 @@ Glib::ustring Utils::locale_simplify(const Glib::ustring& locale_id)
   }
 
   //Get everything before the .:
-  const Glib::ustring::size_type posDot = result.find('.');
+  const auto posDot = result.find('.');
   if(posDot != Glib::ustring::npos)
   {
     result = result.substr(0, posDot);
   }
 
   //Get everything before the @:
-  const Glib::ustring::size_type posAt = result.find('@');
+  const auto posAt = result.find('@');
   if(posAt != Glib::ustring::npos)
   {
     result = result.substr(0, posAt);
   }
 
   //Get everything after the =, if any:
-  const Glib::ustring::size_type posEquals = result.find('=');
+  const auto posEquals = result.find('=');
   if(posEquals != Glib::ustring::npos)
   {
     result = result.substr(posEquals + 1);
@@ -88,7 +88,7 @@ Glib::ustring Utils::locale_simplify(const Glib::ustring& locale_id)
 
 Glib::ustring Utils::locale_language_id(const Glib::ustring& locale_id)
 {
-  const Glib::ustring::size_type posUnderscore = locale_id.find('_');
+  const auto posUnderscore = locale_id.find('_');
   if(posUnderscore != Glib::ustring::npos)
   {
     return locale_id.substr(0, posUnderscore);
diff --git a/glom/mode_data/datawidget/treemodel_db.cc b/glom/mode_data/datawidget/treemodel_db.cc
index fd933b2..379c8c1 100644
--- a/glom/mode_data/datawidget/treemodel_db.cc
+++ b/glom/mode_data/datawidget/treemodel_db.cc
@@ -129,7 +129,7 @@ void DbTreeModelRow::fill_values_if_necessary(DbTreeModel& model, int row)
 
             //We don't just create a Gda::Value of the column's gda type,
             //because we should use a NULL-type Gda::Value as the initial value for some fields:
-            const Field::glom_field_type glom_type = Field::get_glom_type_for_gda_type(column->get_g_type());
+            const auto glom_type = Field::get_glom_type_for_gda_type(column->get_g_type());
             m_db_values[col] = Glom::Conversions::get_empty_value(glom_type);
           }
         }
@@ -733,7 +733,7 @@ int DbTreeModel::get_internal_rows_count() const
 
 DbTreeModel::iterator DbTreeModel::append()
 {
-  //const size_type existing_size = m_data_model_rows_count;
+  //const auto existing_size = m_data_model_rows_count;
   //std::cerr << G_STRFUNC << ": existing_size = " << existing_size << std::endl;
   //m_rows.resize(existing_size + 1);
 
diff --git a/glom/mode_design/fields/box_db_table_definition.cc 
b/glom/mode_design/fields/box_db_table_definition.cc
index ac6c809..410eace 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -129,7 +129,7 @@ void Box_DB_Table_Definition::fill_field_row(const Gtk::TreeModel::iterator& ite
   // TODO: Why was this done by converting the field's gtype to a glom type
   // instead of using the glom type directly? This breaks numerical types in
   // sqlite which we store as double.
-  Field::glom_field_type fieldType = field->get_glom_type();
+  auto fieldType = field->get_glom_type();
 
   const auto strType = Field::get_type_name_ui( fieldType );
   m_AddDel.set_value(iter, m_colType, strType);
@@ -490,7 +490,7 @@ std::shared_ptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::
     //Type:
     const auto strType = m_AddDel.get_value(row, m_colType);
 
-    const Field::glom_field_type glom_type =  Field::get_type_for_ui_name(strType);
+    const auto glom_type =  Field::get_type_for_ui_name(strType);
     GType fieldType = Field::get_gda_type_for_glom_type(glom_type);
 
     //Unique:
diff --git a/glom/mode_design/fields/combo_fieldtype.cc b/glom/mode_design/fields/combo_fieldtype.cc
index e4433d2..2b3ab89 100644
--- a/glom/mode_design/fields/combo_fieldtype.cc
+++ b/glom/mode_design/fields/combo_fieldtype.cc
@@ -79,7 +79,7 @@ void Combo_FieldType::set_field_type(Field::glom_field_type fieldType)
 
 Field::glom_field_type Combo_FieldType::get_field_type() const
 {
-  Field::glom_field_type result = Field::glom_field_type::INVALID;
+  auto result = Field::glom_field_type::INVALID;
 
   //Get the active row:
   auto active_row  = get_active();
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc 
b/glom/mode_design/fields/dialog_fielddefinition.cc
index 0d97c17..66a03f7 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -279,7 +279,7 @@ void Dialog_FieldDefinition::on_combo_type_changed()
   //m_Frame_TypeDetails.remove();
 
   //Use FieldType static method to categorise field type:
- // glom_field_type fieldType = m_combo_type->get_field_type();
+ // auto fieldType = m_combo_type->get_field_type();
 
 }
 
diff --git a/glom/utility_widgets/adddel/adddel.cc b/glom/utility_widgets/adddel/adddel.cc
index 49ad2a1..06defd0 100644
--- a/glom/utility_widgets/adddel/adddel.cc
+++ b/glom/utility_widgets/adddel/adddel.cc
@@ -1197,7 +1197,7 @@ void AddDel::on_treeview_cell_edited(const Glib::ustring& path_string, const Gli
       {
         bool do_signal = true;
 
-        const Field::glom_field_type field_type = m_column_types[model_column_index].m_field_type;
+        const auto field_type = m_column_types[model_column_index].m_field_type;
         if(field_type != Field::glom_field_type::INVALID) //If a field type was specified for this column.
         {
           //Make sure that the entered data is suitable for this field type:


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