diff libinterp/octave-value/cdef-class.h @ 26772:d1419ac09564

split method, package, and property classes from cdef-class file * cdef-method.cc, cdef-method.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h: New files. * libinterp/octave-value/module.mk: Update. * cdef-class.cc, cdef-class.h, cdef-manager.h, cdef-object.cc, cdef-utils.cc, cdef-utils.h, ov-classdef.cc: Adapt as needed for new file arrangement.
author John W. Eaton <jwe@octave.org>
date Fri, 22 Feb 2019 15:28:42 +0000
parents 2f847e3e8d6b
children a95887edd55e
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-class.h	Fri Feb 22 14:51:29 2019 +0000
+++ b/libinterp/octave-value/cdef-class.h	Fri Feb 22 15:28:42 2019 +0000
@@ -31,20 +31,17 @@
 
 #include "oct-refcount.h"
 
+#include "cdef-method.h"
 #include "cdef-object.h"
-#include "ov-base.h"
-#include "ov-builtin.h"
-
-class cdef_object;
-class cdef_property;
-class cdef_method;
-class cdef_package;
+#include "cdef-package.h"
+#include "cdef-property.h"
+#include "ov.h"
+#include "ovl.h"
 
 namespace octave
 {
   class interpreter;
   class tree_classdef;
-  class type_info;
 }
 
 class
@@ -375,269 +372,6 @@
 operator < (const cdef_class& clsa, const cdef_class& clsb)
 { return clsa.get_rep () < clsb.get_rep (); }
 
-class
-cdef_property : public cdef_meta_object
-{
-  friend class cdef_class;
-
-private:
-
-  class
-  cdef_property_rep : public cdef_meta_object_rep
-  {
-  public:
-    cdef_property_rep (void)
-      : cdef_meta_object_rep () { }
-
-    cdef_property_rep& operator = (const cdef_property_rep& p) = delete;
-
-    ~cdef_property_rep (void) = default;
-
-    cdef_object_rep * copy (void) const { return new cdef_property_rep (*this); }
-
-    bool is_property (void) const { return true; }
-
-    std::string get_name (void) const { return get("Name").string_value (); }
-
-    void set_name (const std::string& nm) { put ("Name", nm); }
-
-    bool is_constant (void) const { return get("Constant").bool_value (); }
-
-    octave_value get_value (bool do_check_access = true,
-                            const std::string& who = "");
-
-    octave_value get_value (const cdef_object& obj,
-                            bool do_check_access = true,
-                            const std::string& who = "");
-
-    void set_value (cdef_object& obj, const octave_value& val,
-                    bool do_check_access = true,
-                    const std::string& who = "");
-
-    bool check_get_access (void) const;
-
-    bool check_set_access (void) const;
-
-  private:
-    cdef_property_rep (const cdef_property_rep& p)
-      : cdef_meta_object_rep (p) { }
-
-    bool is_recursive_set (const cdef_object& obj) const;
-
-    cdef_property wrap (void)
-    {
-      refcount++;
-      return cdef_property (this);
-    }
-  };
-
-public:
-  cdef_property (void) : cdef_meta_object () { }
-
-  cdef_property (const std::string& nm)
-    : cdef_meta_object (new cdef_property_rep ())
-  { get_rep ()->set_name (nm); }
-
-  cdef_property (const cdef_property& prop)
-    : cdef_meta_object (prop) { }
-
-  cdef_property (const cdef_object& obj)
-    : cdef_meta_object (obj)
-  {
-    // This should never happen...
-    if (! is_property ())
-      error ("internal error: invalid assignment from %s to meta.property object",
-             class_name ().c_str ());
-  }
-
-  cdef_property& operator = (const cdef_property& prop)
-  {
-    cdef_object::operator = (prop);
-
-    return *this;
-  }
-
-  ~cdef_property (void) = default;
-
-  octave_value get_value (const cdef_object& obj, bool do_check_access = true,
-                          const std::string& who = "")
-  { return get_rep ()->get_value (obj, do_check_access, who); }
-
-  octave_value get_value (bool do_check_access = true,
-                          const std::string& who = "")
-  { return get_rep ()->get_value (do_check_access, who); }
-
-  void set_value (cdef_object& obj, const octave_value& val,
-                  bool do_check_access = true,
-                  const std::string& who = "")
-  { get_rep ()->set_value (obj, val, do_check_access, who); }
-
-  bool check_get_access (void) const
-  { return get_rep ()->check_get_access (); }
-
-  bool check_set_access (void) const
-  { return get_rep ()->check_set_access (); }
-
-  std::string get_name (void) const { return get_rep ()->get_name (); }
-
-  bool is_constant (void) const { return get_rep ()->is_constant (); }
-
-private:
-  cdef_property_rep * get_rep (void)
-  { return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ()); }
-
-  const cdef_property_rep * get_rep (void) const
-  { return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ()); }
-};
-
-class
-cdef_method : public cdef_meta_object
-{
-  friend class cdef_class;
-
-private:
-
-  class
-  cdef_method_rep : public cdef_meta_object_rep
-  {
-  public:
-    cdef_method_rep (void)
-      : cdef_meta_object_rep (), function (), dispatch_type ()
-    { }
-
-    cdef_method_rep& operator = (const cdef_method_rep& m) = delete;
-
-    ~cdef_method_rep (void) = default;
-
-    cdef_object_rep * copy (void) const { return new cdef_method_rep(*this); }
-
-    bool is_method (void) const { return true; }
-
-    std::string get_name (void) const { return get("Name").string_value (); }
-
-    void set_name (const std::string& nm) { put ("Name", nm); }
-
-    bool is_static (void) const { return get("Static").bool_value (); }
-
-    octave_value get_function (void) const { return function; }
-
-    void set_function (const octave_value& fcn) { function = fcn; }
-
-    bool check_access (void) const;
-
-    bool is_external (void) const { return ! dispatch_type.empty (); }
-
-    void mark_as_external (const std::string& dtype)
-    { dispatch_type = dtype; }
-
-    octave_value_list execute (const octave_value_list& args, int nargout,
-                               bool do_check_access = true,
-                               const std::string& who = "");
-
-    octave_value_list execute (const cdef_object& obj,
-                               const octave_value_list& args, int nargout,
-                               bool do_check_access = true,
-                               const std::string& who = "");
-
-    bool is_constructor (void) const;
-
-    octave_value_list
-    meta_subsref (const std::string& type,
-                  const std::list<octave_value_list>& idx, int nargout);
-
-    bool meta_accepts_postfix_index (char type) const
-    { return (type == '(' || type == '.'); }
-
-  private:
-    cdef_method_rep (const cdef_method_rep& m)
-      : cdef_meta_object_rep (m), function (m.function),
-        dispatch_type (m.dispatch_type)
-    { }
-
-    void check_method (void);
-
-    cdef_method wrap (void)
-    {
-      refcount++;
-      return cdef_method (this);
-    }
-
-    octave_value function;
-
-    // When non-empty, the method is externally defined and this member
-    // is used to cache the dispatch type to look for the method.
-    std::string dispatch_type;
-  };
-
-public:
-  cdef_method (void) : cdef_meta_object () { }
-
-  cdef_method (const std::string& nm)
-    : cdef_meta_object (new cdef_method_rep ())
-  { get_rep ()->set_name (nm); }
-
-  cdef_method (const cdef_method& meth)
-    : cdef_meta_object (meth) { }
-
-  cdef_method (const cdef_object& obj)
-    : cdef_meta_object (obj)
-  {
-    // This should never happen...
-    if (! is_method ())
-      error ("internal error: invalid assignment from %s to meta.method object",
-             class_name ().c_str ());
-  }
-
-  cdef_method& operator = (const cdef_method& meth)
-  {
-    cdef_object::operator = (meth);
-
-    return *this;
-  }
-
-  ~cdef_method (void) = default;
-
-  // normal invocation
-  octave_value_list execute (const octave_value_list& args, int nargout,
-                             bool do_check_access = true,
-                             const std::string& who = "")
-  { return get_rep ()->execute (args, nargout, do_check_access, who); }
-
-  // dot-invocation: object is pushed as 1st argument
-  octave_value_list execute (const cdef_object& obj,
-                             const octave_value_list& args, int nargout,
-                             bool do_check_access = true,
-                             const std::string& who = "")
-  { return get_rep ()->execute (obj, args, nargout, do_check_access, who); }
-
-  bool check_access (void) const { return get_rep ()->check_access (); }
-
-  std::string get_name (void) const { return get_rep ()->get_name (); }
-
-  bool is_static (void) const { return get_rep ()->is_static (); }
-
-  void set_function (const octave_value& fcn)
-  { get_rep ()->set_function (fcn); }
-
-  octave_value get_function (void) const
-  { return get_rep ()->get_function (); }
-
-  bool is_constructor (void) const
-  { return get_rep ()->is_constructor (); }
-
-  bool is_external (void) const { return get_rep ()->is_external (); }
-
-  void mark_as_external (const std::string& dtype)
-  { get_rep ()->mark_as_external (dtype); }
-
-private:
-  cdef_method_rep * get_rep (void)
-  { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); }
-
-  const cdef_method_rep * get_rep (void) const
-  { return dynamic_cast<const cdef_method_rep *> (cdef_object::get_rep ()); }
-};
-
 inline cdef_method
 cdef_class::find_method (const std::string& nm, bool local)
 { return get_rep ()->find_method (nm, local); }
@@ -646,160 +380,4 @@
 cdef_class::find_property (const std::string& nm)
 { return get_rep ()->find_property (nm); }
 
-class
-cdef_package : public cdef_meta_object
-{
-  friend class cdef_class;
-
-private:
-
-  class
-  cdef_package_rep : public cdef_meta_object_rep
-  {
-  public:
-    cdef_package_rep (void)
-      : cdef_meta_object_rep (), member_count (0) { }
-
-    cdef_package_rep& operator = (const cdef_package_rep&) = delete;
-
-    ~cdef_package_rep (void) = default;
-
-    cdef_object_rep * copy (void) const { return new cdef_package_rep (*this); }
-
-    bool is_package (void) const { return true; }
-
-    std::string get_name (void) const { return get("Name").string_value (); }
-
-    void set_name (const std::string& nm) { put ("Name", nm); }
-
-    void install_class (const cdef_class& cls, const std::string& nm);
-
-    void install_function (const octave_value& fcn, const std::string& nm);
-
-    void install_package (const cdef_package& pack, const std::string& nm);
-
-    Cell get_classes (void) const;
-
-    Cell get_functions (void) const;
-
-    Cell get_packages (void) const;
-
-    octave_idx_type static_count (void) const { return member_count; }
-
-    void destroy (void)
-    {
-      if (member_count)
-        {
-          refcount++;
-          cdef_package lock (this);
-
-          member_count = 0;
-          class_map.clear ();
-          package_map.clear ();
-        }
-      else
-        delete this;
-    }
-
-    octave_value_list
-    meta_subsref (const std::string& type,
-                  const std::list<octave_value_list>& idx, int nargout);
-
-    void meta_release (void);
-
-    bool meta_accepts_postfix_index (char type) const
-    { return (type == '.'); }
-
-    octave_value find (const std::string& nm);
-
-  private:
-    std::string full_name;
-    std::map<std::string, cdef_class> class_map;
-    std::map<std::string, octave_value> function_map;
-    std::map<std::string, cdef_package> package_map;
-
-    // The number of registered members in this package (classes, packages).
-    // This only accounts for the members that back-reference to this package.
-    octave_idx_type member_count;
-
-    typedef std::map<std::string, cdef_class>::iterator class_iterator;
-    typedef std::map<std::string, cdef_class>::const_iterator class_const_iterator;
-    typedef std::map<std::string, octave_value>::iterator function_iterator;
-    typedef std::map<std::string, octave_value>::const_iterator function_const_iterator;
-    typedef std::map<std::string, cdef_package>::iterator package_iterator;
-    typedef std::map<std::string, cdef_package>::const_iterator package_const_iterator;
-
-    cdef_package_rep (const cdef_package_rep& p)
-      : cdef_meta_object_rep (p), full_name (p.full_name),
-        class_map (p.class_map), function_map (p.function_map),
-        package_map (p.package_map), member_count (p.member_count)
-    { }
-
-    cdef_package wrap (void)
-    {
-      refcount++;
-      return cdef_package (this);
-    }
-  };
-
-public:
-  cdef_package (void) : cdef_meta_object () { }
-
-  cdef_package (const std::string& nm)
-    : cdef_meta_object (new cdef_package_rep ())
-  { get_rep ()->set_name (nm); }
-
-  cdef_package (const cdef_package& pack)
-    : cdef_meta_object (pack) { }
-
-  cdef_package (const cdef_object& obj)
-    : cdef_meta_object (obj)
-  {
-    // This should never happen...
-    if (! is_package ())
-      error ("internal error: invalid assignment from %s to meta.package object",
-             class_name ().c_str ());
-  }
-
-  cdef_package& operator = (const cdef_package& pack)
-  {
-    cdef_object::operator = (pack);
-
-    return *this;
-  }
-
-  ~cdef_package (void) = default;
-
-  void install_class (const cdef_class& cls, const std::string& nm)
-  { get_rep ()->install_class (cls, nm); }
-
-  void install_function (const octave_value& fcn, const std::string& nm)
-  { get_rep ()->install_function (fcn, nm); }
-
-  void install_package (const cdef_package& pack, const std::string& nm)
-  { get_rep ()->install_package (pack, nm); }
-
-  Cell get_classes (void) const
-  { return get_rep ()->get_classes (); }
-
-  Cell get_functions (void) const
-  { return get_rep ()->get_functions (); }
-
-  Cell get_packages (void) const
-  { return get_rep ()->get_packages (); }
-
-  std::string get_name (void) const { return get_rep ()->get_name (); }
-
-  octave_value find (const std::string& nm) { return get_rep ()->find (nm); }
-
-private:
-  cdef_package_rep * get_rep (void)
-  { return dynamic_cast<cdef_package_rep *> (cdef_object::get_rep ()); }
-
-  const cdef_package_rep * get_rep (void) const
-  { return dynamic_cast<const cdef_package_rep *> (cdef_object::get_rep ()); }
-
-  friend void install_classdef (octave::interpreter& interp);
-};
-
 #endif