[glom] CsvParser: Made some API private.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom] CsvParser: Made some API private.
- Date: Fri, 18 Sep 2009 11:20:51 +0000 (UTC)
commit e0fa4a2adb958cb8dedfd72a03c6e4711af3fd09
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Sep 18 11:17:12 2009 +0200
CsvParser: Made some API private.
* glom/dialog_import_csv.[h|cc]: get_field_for_column(): Return a
sharedptr<const>, not a silly const sharedptr<>&.
* glom/dialog_import_csv_progress.cc:
* glom/import_csv.[h|cc]: add get_state() and get_rows_count(). Make
some API private to make it clearer what needs to be done to make
this a real self-contained class.
ChangeLog | 11 +++++++++
glom/dialog_import_csv.cc | 26 ++++++++++++---------
glom/dialog_import_csv.h | 2 +-
glom/dialog_import_csv_progress.cc | 2 +-
glom/import_csv.cc | 10 ++++++++
glom/import_csv.h | 42 ++++++++++++++++++++++++++++++------
6 files changed, 73 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 06084c3..9d15e07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-09-18 Murray Cumming <murrayc murrayc-desktop>
+
+ CsvParser: Made some API private.
+
+ * glom/dialog_import_csv.[h|cc]: get_field_for_column(): Return a
+ sharedptr<const>, not a silly const sharedptr<>&.
+ * glom/dialog_import_csv_progress.cc:
+ * glom/import_csv.[h|cc]: add get_state() and get_rows_count(). Make
+ some API private to make it clearer what needs to be done to make
+ this a real self-contained class.
+
2009-09-18 Murray Cumming <murrayc murrayc com>
CSV Import: Minor code style changes.
diff --git a/glom/dialog_import_csv.cc b/glom/dialog_import_csv.cc
index 7a0ff65..fae6d04 100644
--- a/glom/dialog_import_csv.cc
+++ b/glom/dialog_import_csv.cc
@@ -179,7 +179,7 @@ Dialog_Import_CSV::Dialog_Import_CSV(BaseObjectType* cobject, const Glib::RefPtr
CsvParser::State Dialog_Import_CSV::get_parser_state() const
{
- return m_parser->m_state;
+ return m_parser->get_state();
}
Glib::ustring Dialog_Import_CSV::get_target_table_name() const
@@ -253,10 +253,12 @@ void Dialog_Import_CSV::import(const Glib::ustring& uri, const Glib::ustring& in
guint Dialog_Import_CSV::get_row_count() const
{
- if(m_first_line_as_title->get_active() && m_parser->m_rows.size() > 1)
- return m_parser->m_rows.size() - 1;
+ const guint parser_count = m_parser->get_rows_count();
- return m_parser->m_rows.size();
+ if(m_first_line_as_title->get_active() && parser_count > 1)
+ return parser_count - 1;
+ else
+ return parser_count;
}
guint Dialog_Import_CSV::get_column_count() const
@@ -264,7 +266,7 @@ guint Dialog_Import_CSV::get_column_count() const
return m_fields.size();
}
-const sharedptr<Field>& Dialog_Import_CSV::get_field_for_column(guint col)
+sharedptr<const Field> Dialog_Import_CSV::get_field_for_column(guint col) const
{
return m_fields[col];
}
@@ -512,7 +514,7 @@ void Dialog_Import_CSV::on_first_line_as_title_toggled()
// Add another row to the end, if one is loaded.
const guint last_index = m_sample_model->children().size();
- if(last_index < m_parser->m_rows.size())
+ if(last_index < m_parser->get_rows_count())
{
iter = m_sample_model->append();
(*iter)[m_sample_columns.m_col_row] = last_index;
@@ -577,7 +579,8 @@ void Dialog_Import_CSV::on_sample_rows_changed()
if(m_first_line_as_title->get_active())
++row_index;
- for(guint i = current_sample_rows; i < new_sample_rows && row_index < m_parser->m_rows.size(); ++i, ++row_index)
+ const guint rows_count = m_parser->get_rows_count();
+ for(guint i = current_sample_rows; i < new_sample_rows && row_index < rows_count; ++i, ++row_index)
{
Gtk::TreeModel::iterator iter = m_sample_model->append();
(*iter)[m_sample_columns.m_col_row] = row_index;
@@ -700,15 +703,16 @@ void Dialog_Import_CSV::on_line_scanned(const Glib::ustring& line, guint line_nu
// Add the row to the treeview if there are not yet as much sample rows
// as the user has chosen (note the first row is to choose the target fields,
// not a sample row, which is why we do -1 here).
- guint sample_rows = m_sample_model->children().size() - 1;
+ const guint sample_rows = m_sample_model->children().size() - 1;
// Don't add if this is the first line and m_first_line_as_title is active:
+ const guint parser_rows_count = m_parser->get_rows_count();
if(line_number > 1 || !m_first_line_as_title->get_active())
{
if(sample_rows < static_cast<guint>(m_sample_rows->get_value_as_int()))
{
Gtk::TreeModel::iterator tree_iter = m_sample_model->append();
- (*tree_iter)[m_sample_columns.m_col_row] = m_parser->m_rows.size() - 1;
+ (*tree_iter)[m_sample_columns.m_col_row] = parser_rows_count - 1;
}
}
}
@@ -808,7 +812,7 @@ void Dialog_Import_CSV::field_data_func(Gtk::CellRenderer* renderer, const Gtk::
{
sharedptr<Field> field = m_fields[column_number];
- if(row != -1 && (unsigned int)row < m_parser->m_rows.size())
+ if(row != -1 && (unsigned int)row < m_parser->get_rows_count())
{
const CsvParser::type_row_strings& row_strings = m_parser->m_rows[row];
if(column_number < row_strings.size())
@@ -905,7 +909,7 @@ void Dialog_Import_CSV::on_field_edited(const Glib::ustring& path, const Glib::u
void Dialog_Import_CSV::set_parser_state(CsvParser::State state)
{
// Calling the member of a member, introduced by refactoring. TODO: clean up set_parser_state() interface.
- if(m_parser->m_state != state)
+ if(m_parser->get_state() != state)
{
m_parser->m_state = state;
// Should be emitted by parser?
diff --git a/glom/dialog_import_csv.h b/glom/dialog_import_csv.h
index 3b6e3f2..1e9eb94 100644
--- a/glom/dialog_import_csv.h
+++ b/glom/dialog_import_csv.h
@@ -57,7 +57,7 @@ public:
unsigned int get_row_count() const;
unsigned int get_column_count() const;
- const sharedptr<Field>& get_field_for_column(unsigned int col);
+ sharedptr<const Field> get_field_for_column(unsigned int col) const;
const Glib::ustring& get_data(unsigned int row, unsigned int col);
SignalStateChanged signal_state_changed() const { return m_signal_state_changed; }
diff --git a/glom/dialog_import_csv_progress.cc b/glom/dialog_import_csv_progress.cc
index 0ec5075..511bc70 100644
--- a/glom/dialog_import_csv_progress.cc
+++ b/glom/dialog_import_csv_progress.cc
@@ -145,7 +145,7 @@ bool Dialog_Import_CSV_Progress::on_idle_import()
// Update the current row values map:
for(unsigned int i = 0; i < m_data_source->get_column_count(); ++ i)
{
- const sharedptr<Field>& field = m_data_source->get_field_for_column(i);
+ sharedptr<const Field> field = m_data_source->get_field_for_column(i);
if(field)
{
// We always assume exported data is in standard CSV format, since
diff --git a/glom/import_csv.cc b/glom/import_csv.cc
index 06d5908..533ec36 100644
--- a/glom/import_csv.cc
+++ b/glom/import_csv.cc
@@ -67,6 +67,16 @@ CsvParser::~CsvParser()
m_idle_connection.disconnect();
}
+CsvParser::State CsvParser::get_state() const
+{
+ return m_state;
+}
+
+guint CsvParser::get_rows_count() const
+{
+ return m_rows.size();
+}
+
CsvParser::type_signal_encoding_error CsvParser::signal_encoding_error() const
{
return m_signal_encoding_error;
diff --git a/glom/import_csv.h b/glom/import_csv.h
index 109e7f1..bc33bdb 100644
--- a/glom/import_csv.h
+++ b/glom/import_csv.h
@@ -50,28 +50,50 @@ public:
STATE_PARSED /**< Finished parsing. */
};
- static const gunichar DELIMITER = ',';
- static const gunichar QUOTE = '\"';
+ /// Get the current state of the parser.
+ State get_state() const;
- static bool next_char_is_quote(const Glib::ustring::const_iterator& iter, const Glib::ustring::const_iterator& end);
- static Glib::ustring::const_iterator advance_field(const Glib::ustring::const_iterator& iter, const Glib::ustring::const_iterator& end, Glib::ustring& field);
+ /// Get the number of rows parsed so far.
+ guint get_rows_count() const;
// Signals:
typedef sigc::signal<void> type_signal_encoding_error;
+
+ /** This signal will be emitted when the parser encounters an error while parsing.
+ * TODO: How do we discover what the error is?
+ */
type_signal_encoding_error signal_encoding_error() const;
typedef sigc::signal<void, std::string, unsigned int> type_signal_line_scanned;
+
+ /** This signal will be emitted each time the parser has scanned a line. TODO: Do we mean row instead of line? - A row contain a newline.
+ */
type_signal_line_scanned signal_line_scanned() const;
/// Make parser object reusable.
void clear();
+ void set_encoding(const char* encoding);
+
+ //TODO: Make this private?
+ typedef std::vector<Glib::ustring> type_row_strings;
+ typedef std::vector<type_row_strings> type_rows;
+
+//TODO: private:
// In order to not make the UI feel sluggish during larger imports we parse
// on chunk at a time in the idle handler.
bool on_idle_parse();
- void set_encoding(const char* encoding);
+private:
+ static const gunichar DELIMITER = ',';
+ static const gunichar QUOTE = '\"';
+ static bool next_char_is_quote(const Glib::ustring::const_iterator& iter, const Glib::ustring::const_iterator& end);
+
+public:
+ static Glib::ustring::const_iterator advance_field(const Glib::ustring::const_iterator& iter, const Glib::ustring::const_iterator& end, Glib::ustring& field);
+
+public:
//For now, everything's public. Until we know how our interface will look like.
//private:
// The raw data in the original encoding. We keep this so we can convert
@@ -79,19 +101,25 @@ public:
// the encoding.
std::vector<char> m_raw;
+private:
std::string m_encoding;
std::vector<char>::size_type m_input_position;
std::string m_current_line;
+
+public:
sigc::connection m_idle_connection;
+
+private:
unsigned int m_line_number;
+
+public:
State m_state;
Glib::RefPtr<Gio::FileInputStream> m_stream;
// Parsed data:
- typedef std::vector<Glib::ustring> type_row_strings;
- typedef std::vector<type_row_strings> type_rows;
type_rows m_rows;
+private:
type_signal_encoding_error m_signal_encoding_error;
type_signal_line_scanned m_signal_line_scanned;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]