Mercurial > octave
changeset 27187:42efd1e986c7
declare classdef property get methods const
* cdef-property.h, cdef-property.cc (classdef_property::get,
classdef_property::classdef_property_rep::get): Declare const.
(classdef_property::classdef_property_rep::err_property_access):
Now a const method instead of a file-scope static function. Change
all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jun 2019 15:32:50 -0500 |
parents | b15b71bcd679 |
children | 792fe198c105 |
files | libinterp/octave-value/cdef-property.cc libinterp/octave-value/cdef-property.h |
diffstat | 2 files changed, 33 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-property.cc Fri Jun 14 12:52:27 2019 -0500 +++ b/libinterp/octave-value/cdef-property.cc Fri Jun 14 15:32:50 2019 -0500 @@ -49,27 +49,6 @@ namespace octave { - OCTAVE_NORETURN static - void - err_property_access (const std::string& from, const cdef_property& prop, - bool is_set = false) - { - octave_value acc = (prop.get (is_set ? "SetAccess" : "GetAccess")); - std::string acc_s; - - if (acc.is_string ()) - acc_s = acc.string_value (); - else - acc_s = "class-restricted"; - - if (is_set) - error ("%s: property `%s' has %s access and cannot be set in this context", - from.c_str (), prop.get_name ().c_str (), acc_s.c_str ()); - else - error ("%s: property `%s' has %s access and cannot be obtained in this context", - from.c_str (), prop.get_name ().c_str (), acc_s.c_str ()); - } - static bool is_method_executing (const octave_value& ov, const cdef_object& obj) { @@ -124,12 +103,12 @@ octave_value cdef_property::cdef_property_rep::get_value (const cdef_object& obj, bool do_check_access, - const std::string& who) + const std::string& who) const { octave_value retval; if (do_check_access && ! check_get_access ()) - err_property_access (who, wrap (), false); + err_property_access (who, false); if (! obj.is_constructed ()) { @@ -162,10 +141,10 @@ octave_value cdef_property::cdef_property_rep::get_value (bool do_check_access, - const std::string& who) + const std::string& who) const { if (do_check_access && ! check_get_access ()) - err_property_access (who, wrap (), false); + err_property_access (who, false); return get ("DefaultValue"); } @@ -177,6 +156,26 @@ return false; } + OCTAVE_NORETURN void + cdef_property::cdef_property_rep::err_property_access + (const std::string& from, bool is_set) const + { + octave_value acc = get (is_set ? "SetAccess" : "GetAccess"); + std::string acc_s; + + if (acc.is_string ()) + acc_s = acc.string_value (); + else + acc_s = "class-restricted"; + + if (is_set) + error ("%s: property `%s' has %s access and cannot be set in this context", + from.c_str (), get_name ().c_str (), acc_s.c_str ()); + else + error ("%s: property `%s' has %s access and cannot be obtained in this context", + from.c_str (), get_name ().c_str (), acc_s.c_str ()); + } + void cdef_property::cdef_property_rep::set_value (cdef_object& obj, const octave_value& val, @@ -184,7 +183,7 @@ const std::string& who) { if (do_check_access && ! check_set_access ()) - err_property_access (who, wrap (), true); + err_property_access (who, true); if (! obj.is_constructed ()) {
--- a/libinterp/octave-value/cdef-property.h Fri Jun 14 12:52:27 2019 -0500 +++ b/libinterp/octave-value/cdef-property.h Fri Jun 14 15:32:50 2019 -0500 @@ -69,11 +69,11 @@ bool is_constant (void) const { return get("Constant").bool_value (); } octave_value get_value (bool do_check_access = true, - const std::string& who = ""); + const std::string& who = "") const; octave_value get_value (const cdef_object& obj, bool do_check_access = true, - const std::string& who = ""); + const std::string& who = "") const; void set_value (cdef_object& obj, const octave_value& val, bool do_check_access = true, @@ -95,6 +95,10 @@ m_count++; return cdef_property (this); } + + OCTAVE_NORETURN + void err_property_access (const std::string& from, + bool is_set = false) const; }; public: @@ -128,13 +132,13 @@ ~cdef_property (void) = default; octave_value get_value (const cdef_object& obj, bool do_check_access = true, - const std::string& who = "") + const std::string& who = "") const { return get_rep ()->get_value (obj, do_check_access, who); } octave_value get_value (bool do_check_access = true, - const std::string& who = "") + const std::string& who = "") const { return get_rep ()->get_value (do_check_access, who); }