[glom] Document: Use DocumentTableInfo by sharedptr<>.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Document: Use DocumentTableInfo by sharedptr<>.
- Date: Wed, 3 Apr 2013 00:22:38 +0000 (UTC)
commit c2a261c26b3cff4cc95ee258c95a5e62b99449ad
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Apr 3 01:03:48 2013 +0200
Document: Use DocumentTableInfo by sharedptr<>.
* glom/glom/libglom/document/document.[h|cc]:
get_tables(): Have both const and non-const overloads of this
method, to allow proper use of const elsewhere.
* glom/libglom/db_utils.cc: Adapted.
ChangeLog | 9 ++++++++
glom/libglom/db_utils.cc | 6 ++--
glom/libglom/document/document.cc | 38 ++++++++++++++++++++++++++++++------
glom/libglom/document/document.h | 5 +++-
4 files changed, 47 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9443b67..d813a3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,15 @@
Document: Use DocumentTableInfo by sharedptr<>.
* glom/glom/libglom/document/document.[h|cc]:
+ get_tables(): Have both const and non-const overloads of this
+ method, to allow proper use of const elsewhere.
+ * glom/libglom/db_utils.cc: Adapted.
+
+2013-04-03 Murray Cumming <murrayc murrayc com>
+
+ Document: Use DocumentTableInfo by sharedptr<>.
+
+ * glom/glom/libglom/document/document.[h|cc]:
DocumentTableInfo: Remove the copy constructor and operator=(),
making them private and unimplemented. Use it by sharedptr<>
instead to be more efficient and simpler.
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index b1df9cb..7b9b16f 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -609,7 +609,7 @@ bool add_standard_groups(Document* document)
priv_devs.m_create = true;
priv_devs.m_delete = true;
- Document::type_listTableInfo table_list = document->get_tables(true /* including system prefs */);
+ const Document::type_listTableInfo table_list = document->get_tables(true /* including system prefs
*/);
for(Document::type_listTableInfo::const_iterator iter = table_list.begin(); iter != table_list.end();
++iter)
{
@@ -2146,9 +2146,9 @@ bool add_user(const Document* document, const Glib::ustring& user, const Glib::u
}
//Remove any user rights, so that all rights come from the user's presence in the group:
- Document::type_listTableInfo table_list = document->get_tables();
+ const Document::type_listConstTableInfo table_list = document->get_tables();
- for(Document::type_listTableInfo::const_iterator iter = table_list.begin(); iter != table_list.end();
++iter)
+ for(Document::type_listConstTableInfo::const_iterator iter = table_list.begin(); iter != table_list.end();
++iter)
{
const Glib::ustring table_name = (*iter)->get_name();
const Glib::ustring strQuery = "REVOKE ALL PRIVILEGES ON " + DbUtils::escape_sql_id(table_name) + " FROM
" + DbUtils::escape_sql_id(user);
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index d04f3ff..092bd43 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1164,8 +1164,32 @@ void Document::change_relationship_name(const Glib::ustring& table_name, const G
}
-//TODO: Have a const and non-const version()?
-Document::type_listTableInfo Document::get_tables(bool plus_system_prefs) const
+Document::type_listConstTableInfo Document::get_tables(bool plus_system_prefs) const
+{
+ //TODO: Avoid the almost-duplicate implementation in the const and non-const methods.
+
+ type_listConstTableInfo result;
+
+ for(type_tables::const_iterator iter = m_tables.begin(); iter != m_tables.end(); ++iter)
+ {
+ const sharedptr<const DocumentTableInfo> doctableinfo = iter->second;
+ if(doctableinfo)
+ result.push_back(doctableinfo->m_info);
+
+ //std::cout << "debug: " << G_STRFUNC << ": title=" << iter->second->m_info->get_title() << std::endl;
+ }
+
+ //Add the system properties if necessary:
+ if(plus_system_prefs)
+ {
+ if(std::find_if(result.begin(), result.end(),
predicate_FieldHasName<TableInfo>(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME)) == result.end())
+ result.push_back(create_table_system_preferences());
+ }
+
+ return result;
+}
+
+Document::type_listTableInfo Document::get_tables(bool plus_system_prefs)
{
type_listTableInfo result;
@@ -1181,8 +1205,8 @@ Document::type_listTableInfo Document::get_tables(bool plus_system_prefs) const
//Add the system properties if necessary:
if(plus_system_prefs)
{
- if(std::find_if(result.begin(), result.end(),
predicate_FieldHasName<TableInfo>(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME)) == result.end())
- result.push_back(create_table_system_preferences());
+ if(std::find_if(result.begin(), result.end(),
predicate_FieldHasName<TableInfo>(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME)) == result.end())
+ result.push_back(create_table_system_preferences());
}
return result;
@@ -1190,11 +1214,11 @@ Document::type_listTableInfo Document::get_tables(bool plus_system_prefs) const
std::vector<Glib::ustring> Document::get_table_names(bool plus_system_prefs) const
{
- type_listTableInfo list_full = get_tables(plus_system_prefs);
+ type_listConstTableInfo list_full = get_tables(plus_system_prefs);
std::vector<Glib::ustring> result;
- for(type_listTableInfo::iterator iter = list_full.begin(); iter != list_full.end(); ++iter)
+ for(type_listConstTableInfo::const_iterator iter = list_full.begin(); iter != list_full.end(); ++iter)
{
- sharedptr<TableInfo> info = *iter;
+ const sharedptr<const TableInfo> info = *iter;
if(info)
result.push_back(info->get_name());
}
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 6fb91a8..cde3d1f 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -282,7 +282,10 @@ public:
void change_relationship_name(const Glib::ustring& table_name, const Glib::ustring& name, const
Glib::ustring& name_new);
typedef std::vector< sharedptr<TableInfo> > type_listTableInfo;
- type_listTableInfo get_tables(bool plus_system_prefs = false) const;
+ type_listTableInfo get_tables(bool plus_system_prefs = false);
+
+ typedef std::vector< sharedptr<const TableInfo> > type_listConstTableInfo;
+ type_listConstTableInfo get_tables(bool plus_system_prefs = false) const;
std::vector<Glib::ustring> get_table_names(bool plus_system_prefs = false) const;
void set_tables(const type_listTableInfo& tables);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]