Mercurial > octave
changeset 24397:08f19fd144f4
don't use const reference template arguments to create var editor callbacks
Do use const reference arguments for functions, but use simple type
names for template declarations.
* variable-editor-model.h, variable-editor-model.cc
(variable_editor_model::get_data_oct,
variable_editor_model::set_data_oct): Use const reference for all
arguments.
* octave-link.h (octave_link::post_event, octave_link::do_post_event):
Use const reference for 2-, 3-, and 4-argument event methods. Change
all uses.
* action-container.h (action_container::method_arg2_elem,
action_container::method_arg3_elem,
action_container::method_arg4_elem):
Use const reference for constructor data and function arguments.
(action_container::add_method): Use const reference arguments for 2-,
3-, and 4-arg methods.
diff --git a/libgui/src/variable-editor-model.cc b/libgui/src/variable-editor-model.cc
--- a/libgui/src/variable-editor-model.cc
+++ b/libgui/src/variable-editor-model.cc
@@ -299,8 +299,8 @@ variable_editor_model::data (const QMode
{
if (! m_d->is_pending (idx))
{
- octave_link::post_event<variable_editor_model, int, int,
- const std::string&>
+ octave_link::post_event<variable_editor_model,
+ int, int, std::string>
(const_cast<variable_editor_model *> (this),
&variable_editor_model::get_data_oct,
idx.row (), idx.column (), m_d->m_name);
@@ -327,8 +327,8 @@ variable_editor_model::setData (const QM
qDebug () << v.typeName () << " Expected String!";
return false;
}
- octave_link::post_event<variable_editor_model, const std::string&,
- int, int, const std::string&>
+ octave_link::post_event<variable_editor_model,
+ std::string, int, int, std::string>
(this, &variable_editor_model::set_data_oct,
m_d->m_name, idx.row (), idx.column (),
v.toString ().toStdString ());
@@ -342,8 +342,7 @@ bool
variable_editor_model::insertRows (int row, int count, const QModelIndex&)
{
// FIXME: cells?
- octave_link::post_event <variable_editor_model, const std::string&,
- const std::string&>
+ octave_link::post_event <variable_editor_model, std::string, std::string>
(this, &variable_editor_model::eval_oct, m_d->m_name,
QString ("%1 = [ %1(1:%2,:) ; zeros(%3, columns(%1)) ; %1(%2+%3:end,:) ]")
.arg (QString::fromStdString (m_d->m_name))
@@ -364,8 +363,7 @@ variable_editor_model::removeRows (int r
return false;
}
- octave_link::post_event <variable_editor_model, const std::string&,
- const std::string&>
+ octave_link::post_event <variable_editor_model, std::string, std::string>
(this, &variable_editor_model::eval_oct, m_d->m_name,
QString ("%1(%2:%3, :) = []")
.arg (QString::fromStdString (m_d->m_name))
@@ -379,8 +377,7 @@ variable_editor_model::removeRows (int r
bool
variable_editor_model::insertColumns (int col, int count, const QModelIndex&)
{
- octave_link::post_event <variable_editor_model, const std::string&,
- const std::string&>
+ octave_link::post_event <variable_editor_model, std::string, std::string>
(this, &variable_editor_model::eval_oct, m_d->m_name,
QString ("%1 = [ %1(:,1:%2) ; zeros(rows(%1), %3) %1(:,%2+%3:end) ]")
.arg (QString::fromStdString (m_d->m_name))
@@ -401,8 +398,7 @@ variable_editor_model::removeColumns (in
return false;
}
- octave_link::post_event <variable_editor_model, const std::string&,
- const std::string&>
+ octave_link::post_event <variable_editor_model, std::string, std::string>
(this, &variable_editor_model::eval_oct, m_d->m_name,
QString ("%1(:, %2:%3) = []")
.arg (QString::fromStdString (m_d->m_name))
@@ -543,7 +539,8 @@ variable_editor_model::received_initiali
// private
void
-variable_editor_model::get_data_oct (int row, int col, const std::string& x)
+variable_editor_model::get_data_oct (const int& row, const int& col,
+ const std::string& x)
{
int parse_status = 0;
@@ -581,7 +578,8 @@ variable_editor_model::get_data_oct (int
// val has to be copied!
void
-variable_editor_model::set_data_oct (const std::string& x, int row, int col,
+variable_editor_model::set_data_oct (const std::string& x,
+ const int& row, const int& col,
const std::string& val)
{
m_d->m_validity = true;
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Dec 2017 14:21:50 -0500 |
parents | c652f2637063 |
children | 4fda27e1c909 |
files | libgui/src/variable-editor-model.cc libgui/src/variable-editor-model.h libinterp/corefcn/octave-link.h liboctave/util/action-container.h |
diffstat | 4 files changed, 52 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc Mon Dec 11 09:08:34 2017 -0500 +++ b/libgui/src/variable-editor-model.cc Mon Dec 11 14:21:50 2017 -0500 @@ -299,8 +299,8 @@ { if (! m_d->is_pending (idx)) { - octave_link::post_event<variable_editor_model, int, int, - const std::string&> + octave_link::post_event<variable_editor_model, + int, int, std::string> (const_cast<variable_editor_model *> (this), &variable_editor_model::get_data_oct, idx.row (), idx.column (), m_d->m_name); @@ -327,8 +327,8 @@ qDebug () << v.typeName () << " Expected String!"; return false; } - octave_link::post_event<variable_editor_model, const std::string&, - int, int, const std::string&> + octave_link::post_event<variable_editor_model, + std::string, int, int, std::string> (this, &variable_editor_model::set_data_oct, m_d->m_name, idx.row (), idx.column (), v.toString ().toStdString ()); @@ -342,8 +342,7 @@ variable_editor_model::insertRows (int row, int count, const QModelIndex&) { // FIXME: cells? - octave_link::post_event <variable_editor_model, const std::string&, - const std::string&> + octave_link::post_event <variable_editor_model, std::string, std::string> (this, &variable_editor_model::eval_oct, m_d->m_name, QString ("%1 = [ %1(1:%2,:) ; zeros(%3, columns(%1)) ; %1(%2+%3:end,:) ]") .arg (QString::fromStdString (m_d->m_name)) @@ -364,8 +363,7 @@ return false; } - octave_link::post_event <variable_editor_model, const std::string&, - const std::string&> + octave_link::post_event <variable_editor_model, std::string, std::string> (this, &variable_editor_model::eval_oct, m_d->m_name, QString ("%1(%2:%3, :) = []") .arg (QString::fromStdString (m_d->m_name)) @@ -379,8 +377,7 @@ bool variable_editor_model::insertColumns (int col, int count, const QModelIndex&) { - octave_link::post_event <variable_editor_model, const std::string&, - const std::string&> + octave_link::post_event <variable_editor_model, std::string, std::string> (this, &variable_editor_model::eval_oct, m_d->m_name, QString ("%1 = [ %1(:,1:%2) ; zeros(rows(%1), %3) %1(:,%2+%3:end) ]") .arg (QString::fromStdString (m_d->m_name)) @@ -401,8 +398,7 @@ return false; } - octave_link::post_event <variable_editor_model, const std::string&, - const std::string&> + octave_link::post_event <variable_editor_model, std::string, std::string> (this, &variable_editor_model::eval_oct, m_d->m_name, QString ("%1(:, %2:%3) = []") .arg (QString::fromStdString (m_d->m_name)) @@ -543,7 +539,8 @@ // private void -variable_editor_model::get_data_oct (int row, int col, const std::string& x) +variable_editor_model::get_data_oct (const int& row, const int& col, + const std::string& x) { int parse_status = 0; @@ -581,7 +578,8 @@ // val has to be copied! void -variable_editor_model::set_data_oct (const std::string& x, int row, int col, +variable_editor_model::set_data_oct (const std::string& x, + const int& row, const int& col, const std::string& val) { m_d->m_validity = true;
--- a/libgui/src/variable-editor-model.h Mon Dec 11 09:08:34 2017 -0500 +++ b/libgui/src/variable-editor-model.h Mon Dec 11 14:21:50 2017 -0500 @@ -120,9 +120,9 @@ private: // Get data for ov(row, col). This must be executed in the octave thread! - void get_data_oct (int row, int col, const std::string& v) /*const*/; + void get_data_oct (const int& row, const int& col, const std::string& v) /*const*/; - void set_data_oct (const std::string& v, int row, int col, + void set_data_oct (const std::string& v, const int& row, const int& col, const std::string& val); void init_from_oct (const std::string& x);
--- a/libinterp/corefcn/octave-link.h Mon Dec 11 09:08:34 2017 -0500 +++ b/libinterp/corefcn/octave-link.h Mon Dec 11 14:21:50 2017 -0500 @@ -121,8 +121,8 @@ } template <class T, class A, class B> - static void post_event (T *obj, void (T::*method) (A, B), - A arg_a, B arg_b) + static void post_event (T *obj, void (T::*method) (const A&, const B&), + const A& arg_a, const B& arg_b) { if (enabled ()) instance->do_post_event<T, A, B> (obj, method, arg_a, arg_b); @@ -130,17 +130,18 @@ template <class T, class A, class B, class C> static void post_event (T *obj, - void (T::*method) (A, B, C), - A arg_a, B arg_b, C arg_c) + void (T::*method) (const A&, const B&, const C&), + const A& arg_a, const B& arg_b, const C& arg_c) { if (enabled ()) instance->do_post_event<T, A, B, C> (obj, method, arg_a, arg_b, arg_c); } template <class T, class A, class B, class C, class D> - static void post_event (T *obj, - void (T::*method) (A, B, C, D), - A arg_a, B arg_b, C arg_c, D arg_d) + static void + post_event (T *obj, + void (T::*method) (const A&, const B&, const C&, const D&), + const A& arg_a, const B& arg_b, const C& arg_c, const D& arg_d) { if (enabled ()) instance->do_post_event<T, A, B, C, D> @@ -467,24 +468,27 @@ } template <class T, class A, class B> - void do_post_event (T *obj, void (T::*method) (A, B), - A arg_a, B arg_b) + void do_post_event (T *obj, void (T::*method) (const A&, const B&), + const A& arg_a, const B& arg_b) { gui_event_queue.add_method<T, A, B> (obj, method, arg_a, arg_b); } template <class T, class A, class B, class C> - void do_post_event (T *obj, void (T::*method) (A, B, C), - A arg_a, B arg_b, C arg_c) + void do_post_event (T *obj, + void (T::*method) (const A&, const B&, const C&), + const A& arg_a, const B& arg_b, const C& arg_c) { gui_event_queue.add_method<T, A, B, C> (obj, method, arg_a, arg_b, arg_c); } template <class T, class A, class B, class C, class D> - void do_post_event (T *obj, void (T::*method) (A, B, C, D), - A arg_a, B arg_b, C arg_c, D arg_d) + void + do_post_event (T *obj, + void (T::*method) (const A&, const B&, const C&, const D&), + const A& arg_a, const B& arg_b, const C& arg_c, const D& arg_d) { gui_event_queue.add_method<T, A, B, C, D> (obj, method, arg_a, arg_b, arg_c, arg_d);
--- a/liboctave/util/action-container.h Mon Dec 11 09:08:34 2017 -0500 +++ b/liboctave/util/action-container.h Mon Dec 11 14:21:50 2017 -0500 @@ -34,6 +34,9 @@ // FIXME: is there a better name for this class? +// FIXME: we should probably be using std::function, std::bind, and +// related c++11 features to implement this functionality. + namespace octave { class @@ -218,8 +221,8 @@ class method_arg2_elem : public elem { public: - method_arg2_elem (T *obj, void (T::*method) (A, B), - A arg_a, B arg_b) + method_arg2_elem (T *obj, void (T::*method) (const A&, const B&), + const A& arg_a, const B& arg_b) : e_obj (obj), e_method (method), e_arg_a (arg_a), e_arg_b (arg_b) { } @@ -228,7 +231,7 @@ private: T *e_obj; - void (T::*e_method) (A, B); + void (T::*e_method) (const A&, const B&); A e_arg_a; B e_arg_b; @@ -244,8 +247,8 @@ class method_arg3_elem : public elem { public: - method_arg3_elem (T *obj, void (T::*method) (A, B, C), - A arg_a, B arg_b, C arg_c) + method_arg3_elem (T *obj, void (T::*method) (const A&, const B&, const C&), + const A& arg_a, const B& arg_b, const C& arg_c) : e_obj (obj), e_method (method), e_arg_a (arg_a), e_arg_b (arg_b), e_arg_c (arg_c) { } @@ -255,7 +258,7 @@ private: T *e_obj; - void (T::*e_method) (A, B, C); + void (T::*e_method) (const A&, const B&, const C&); A e_arg_a; B e_arg_b; C e_arg_c; @@ -272,8 +275,8 @@ class method_arg4_elem : public elem { public: - method_arg4_elem (T *obj, void (T::*method) (A, B, C, D), - A arg_a, B arg_b, C arg_c, D arg_d) + method_arg4_elem (T *obj, void (T::*method) (const A&, const B&, const C&, const D&), + const A& arg_a, const B& arg_b, const C& arg_c, const D& arg_d) : e_obj (obj), e_method (method), e_arg_a (arg_a), e_arg_b (arg_b), e_arg_c (arg_c), e_arg_d (arg_d) { } @@ -285,7 +288,7 @@ private: T *e_obj; - void (T::*e_method) (A, B, C, D); + void (T::*e_method) (const A&, const B&, const C&, const D&); A e_arg_a; B e_arg_b; C e_arg_c; @@ -417,16 +420,17 @@ // Call to T::method (A, B). template <class T, class A, class B> - void add_method (T *obj, void (T::*method) (A, B), - A arg_a, B arg_b) + void add_method (T *obj, void (T::*method) (const A&, const B&), + const A& arg_a, const B& arg_b) { add (new method_arg2_elem<T, A, B> (obj, method, arg_a, arg_b)); } // Call to T::method (A, B, C). template <class T, class A, class B, class C> - void add_method (T *obj, void (T::*method) (A, B, C), - A arg_a, B arg_b, C arg_c) + void add_method (T *obj, + void (T::*method) (const A&, const B&, const C&), + const A& arg_a, const B& arg_b, const C& arg_c) { add (new method_arg3_elem<T, A, B, C> (obj, method, arg_a, arg_b, arg_c)); @@ -434,9 +438,10 @@ // Call to T::method (A, B, C, D). template <class T, class A, class B, class C, class D> - void add_method (T *obj, void (T::*method) (A, B, C, D), - A arg_a, B arg_b, - C arg_c, D arg_d) + void add_method (T *obj, + void (T::*method) (const A&, const B&, const C&, const D&), + const A& arg_a, const B& arg_b, + const C& arg_c, const D& arg_d) { add (new method_arg4_elem<T, A, B, C, D> (obj, method, arg_a, arg_b, arg_c, arg_d));