diff libinterp/octave-value/ov-classdef.h @ 15968:cdeb6eb656be classdef

Move property/method access check down to cdef_property/cdef_method classes. * libinterp/octave-value/ov-classdef.h (cdef_property::cdef_property_rep::get_value, cdef_property::cdef_property_rep::set_value): Add arguments (do_check_access and who) to control access checking and pass down to gripe utility function. (cdef_property::get_value, cdef_property::set_value): Likewise. (cdef_method::cdef_method_rep::execute): Likewise. (cdef_method::execute): Likewise. (cdef_property::check_get_access, cdef_property::check_set_access): Move implementation to cdef_property::cdef_property_rep. (cdef_property::cdef_property_rep::check_get_access, cdef_property::cdef_property_rep::check_set_access): New methods, moved from cdef_property. (cdef_method::check_access): Move implementation to cdef_method::cdef_method_rep. (cdef_method::cdef_method_rep::check_access): New method, moved from cdef_method. (cdef_property::cdef_property_rep::wrap): New method. (cdef_method::cdef_method_rep::wrap): New method. * libinterp/octave-value/ov-classdef.cc (cdef_property::cdef_property_rep::get_value, cdef_property::cdef_property_rep::set_value): Add arguments (do_check_access and who) to control access checking and pass down to gripe utility function. (cdef_property::cdef_property_rep::check_get_access, (cdef_method::cdef_method_rep::execute): Likewise. cdef_property::cdef_property_rep::check_set_access): New methods, moved from cdef_property. (cdef_method::cdef_method_rep::check_access): New method, moved from cdef_method. (class_fevalStatic, octave_classdef_superclass_ref::do_multi_index_op, cdef_object_scalar::subsref, cdef_class::cdef_class_rep::subsref_meta, cdef_class::cdef_class_rep::construct_object): Do not check access, let cdef_method::execute handle it. (class_getConstant, cdef_object_scalar::subsref, cdef_object_scalar::subsasgn, cdef_class::cdef_class_rep::subsref_meta): Do not check get/set access, let cdef_property::get_value and cdef_property::set_value handle it. (cdef_class::cdef_class_rep::delete_object): Execute "delete" method without access checking.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 20 Jan 2013 23:03:17 -0500
parents da4cd4ab36db
children 14aa0b5a980c
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.h
+++ b/libinterp/octave-value/ov-classdef.h
@@ -834,17 +834,32 @@
 
     bool is_constant (void) const { return get("Constant").bool_value (); }
 
-    octave_value get_value (void) const { return get ("DefaultValue"); }
+    octave_value get_value (bool do_check_access = true,
+                            const std::string& who = std::string ());
+
+    octave_value get_value (const cdef_object& obj,
+                            bool do_check_access = true,
+                            const std::string& who = std::string ());
 
-    octave_value get_value (const cdef_object& obj);
+    void set_value (cdef_object& obj, const octave_value& val,
+                    bool do_check_access = true,
+                    const std::string& who = std::string ());
 
-    void set_value (cdef_object& obj, const octave_value& val);
+    bool check_get_access (void) const;
+
+    bool check_set_access (void) const;
 
   private:
     cdef_property_rep (const cdef_property_rep& p)
       : handle_cdef_object (p) { }
 
     bool is_recursive_set (const cdef_object& obj) const;
+
+    cdef_property wrap (void)
+      {
+        refcount++;
+        return cdef_property (this);
+      }
   };
 
 public:
@@ -873,17 +888,24 @@
       return *this;
     }
 
-  octave_value get_value (const cdef_object& obj)
-    { return get_rep ()->get_value (obj); }
+  octave_value get_value (const cdef_object& obj, bool do_check_access = true,
+                          const std::string& who = std::string ())
+    { return get_rep ()->get_value (obj, do_check_access, who); }
 
-  octave_value get_value (void) { return get_rep ()->get_value (); }
+  octave_value get_value (bool do_check_access = true,
+                          const std::string& who = std::string ())
+    { return get_rep ()->get_value (do_check_access, who); }
 
-  void set_value (cdef_object& obj, const octave_value& val)
-    { get_rep ()->set_value (obj, val); }
+  void set_value (cdef_object& obj, const octave_value& val,
+                  bool do_check_access = true,
+                  const std::string& who = std::string ())
+    { get_rep ()->set_value (obj, val, do_check_access, who); }
 
-  bool check_get_access (void) const;
+  bool check_get_access (void) const
+    { return get_rep ()->check_get_access (); }
   
-  bool check_set_access (void) const;
+  bool check_set_access (void) const
+    { return get_rep ()->check_set_access (); }
 
   std::string get_name (void) const { return get_rep ()->get_name (); }
 
@@ -924,10 +946,16 @@
 
     void set_function (const octave_value& fcn) { function = fcn; }
 
-    octave_value_list execute (const octave_value_list& args, int nargout);
+    bool check_access (void) const;
+
+    octave_value_list execute (const octave_value_list& args, int nargout,
+                               bool do_check_access = true,
+                               const std::string& who = std::string ());
 
     octave_value_list execute (const cdef_object& obj,
-			       const octave_value_list& args, int nargout);
+			       const octave_value_list& args, int nargout,
+                               bool do_check_access = true,
+                               const std::string& who = std::string ());
 
     bool is_constructor (void) const;
 
@@ -937,6 +965,12 @@
 
     void check_method (void);
 
+    cdef_method wrap (void)
+      {
+        refcount++;
+        return cdef_method (this);
+      }
+
   private:
     octave_value function;
   };
@@ -968,15 +1002,19 @@
     }
 
   /* normal invokation */
-  octave_value_list execute (const octave_value_list& args, int nargout)
-    { return get_rep ()->execute (args, nargout); }
+  octave_value_list execute (const octave_value_list& args, int nargout,
+                             bool do_check_access = true,
+                             const std::string& who = std::string ())
+    { return get_rep ()->execute (args, nargout, do_check_access, who); }
 
   /* dot-invokation: object is pushed as 1st argument */
   octave_value_list execute (const cdef_object& obj,
-			     const octave_value_list& args, int nargout)
-    { return get_rep ()->execute (obj, args, nargout); }
+			     const octave_value_list& args, int nargout,
+                             bool do_check_access = true,
+                             const std::string& who = std::string ())
+    { return get_rep ()->execute (obj, args, nargout, do_check_access, who); }
 
-  bool check_access (void) const;
+  bool check_access (void) const { return get_rep ()->check_access (); }
   
   std::string get_name (void) const { return get_rep ()->get_name (); }