26#if defined (HAVE_CONFIG_H)
53in_class_method (
const octave::cdef_class& cls)
55 octave::cdef_class ctx = octave::get_class_context ();
57 return (ctx.ok () && octave::is_superclass (ctx, cls));
60int octave_classdef::s_t_id (-1);
62const std::string octave_classdef::s_t_name (
"object");
67 s_t_id = ti.register_type (octave_classdef::s_t_name,
"<unknown>",
73 const std::list<octave_value_list>& idx,
79 octave::cdef_class cls = m_object.get_class ();
83 octave::cdef_method meth = cls.find_method (
"subsref");
94 octave::cdef_method meth_nargout
95 = cls.find_method (
"numArgumentsFromSubscript");
96 if (meth_nargout.ok ())
100 args_nargout(0) = args(0);
101 args_nargout(1) = args(1);
105 retval = meth_nargout.execute (args_nargout, 1,
true,
106 "numArgumentsFromSubscript");
108 nargout = retval(0).strict_int_value
109 (
"subsref: return value of 'numArgumentsFromSubscript' must be integer");
111 else if (nargout <= 0)
116 bool maybe_cs_list_query = (type[0] ==
'.' || type[0] ==
'{'
117 || (type.length () > 1 && type[0] ==
'('
120 if (maybe_cs_list_query)
132 if (type[0] !=
'.' || nout != 1 || nargout < 0)
135 else if (nargout < 0)
139 retval = meth.execute (args, nargout,
true,
"subsref");
145 if (retval.
length () > 1 && (nargout < 0 || nargout > 1))
147 if (nargout <= 0 || nargout >= retval.
length ())
161 retval = m_object.subsref (type, idx, nargout, skip, octave::cdef_class ());
163 if (type.length () > skip && idx.size () > skip)
164 retval = retval(0).next_subsref (nargout, type, idx, skip);
171 const std::list<octave_value_list>& idx,
174 std::size_t skip = 0;
181 octave::cdef_class cls = m_object.get_class ();
183 if (! in_class_method (cls))
185 octave::cdef_method meth = cls.find_method (
"subsref");
196 retval = meth.execute (args, 1,
true,
"subsref");
202 retval = m_object.subsref (type, idx, 1, skip,
203 octave::cdef_class (), auto_add);
205 if (type.length () > skip && idx.size () > skip)
206 retval = retval(0).next_subsref (1, type, idx, skip);
213 const std::list<octave_value_list>& idx,
218 octave::cdef_class cls = m_object.get_class ();
222 octave::cdef_method meth = cls.find_method (
"subsasgn");
236 retlist = meth.execute (args, 1,
true,
"subsasgn");
238 if (retlist.
empty ())
239 error (
"overloaded method 'subsasgn' did not return any value");
246 retval = m_object.subsasgn (type, idx, rhs);
253 const std::list<octave_value_list>& idx,
256 if (type.length () == 1 && type[0] ==
'(')
258 m_object = m_object.make_array ();
271 octave::cdef_class cls = m_object.get_class ();
275 octave::cdef_method meth = cls.find_method (
"size");
287 return lv(0).matrix_value ();
299 octave::cdef_class cls = m_object.get_class ();
303 octave::cdef_method meth = cls.find_method (
"numel");
317 octave::interpreter& interp = octave::__get_interpreter__ ();
318 octave::tree_evaluator& tw = interp.get_evaluator();
320 octave::unwind_action act ([&tw] (
const std::list<octave::octave_lvalue> *lvl)
322 tw.set_lvalue_list (lvl);
323 }, tw.lvalue_list ());
324 tw.set_lvalue_list (
nullptr);
328 error (
"@%s/numel: invalid return value", cls.get_name ().c_str ());
330 retval = lv(0).idx_type_value (
true);
350 octave::cdef_class cls = m_object.get_class ();
354 bool is_array = m_object.is_array ();
362 os <<
" with properties:";
369 std::map<octave::property_key, octave::cdef_property> property_map
370 = cls.get_property_map ();
372 std::size_t max_len = 0;
373 for (
const auto& pname_prop : property_map)
378 const octave::cdef_property& prop = pname_prop.second;
380 const std::string nm = prop.get_name ();
392 std::size_t sz = nm.
size ();
398 for (
auto& pname_prop : property_map)
400 const octave::cdef_property& prop = pname_prop.second;
402 const std::string nm = prop.get_name ();
420 os << std::setw (max_len+2) << nm <<
": ";
438 octave::cdef_class cls = octave::lookup_class (cls_name,
false,
false);
448 const std::string& cls)
456 return octave::to_ov (octave::lookup_class (cls));
464 if (m_object.is_method ())
470 octave::cdef_method meth (m_object);
472 return meth.is_defined_in_class (cname);
484 if (m_object.is_class ())
490 octave::cdef_class cls (m_object);
492 if (cls.get_name () == cname)
496 else if (m_object.is_method ())
498 octave::cdef_method meth (m_object);
500 if (meth.is_constructor ())
502 std::string meth_name = meth.get_name ();
508 if (cname == meth_name)
512 octave::cdef_class meth_cls = octave::lookup_class (meth_name,
false,
false);
513 octave::cdef_class dispatch_cls = octave::lookup_class (cname,
false,
false);
515 retval = octave::is_superclass (meth_cls, dispatch_cls);
526 if (m_object.is_class ())
528 octave::cdef_class cls (m_object);
530 if (meth_name.empty ())
531 return cls.doc_string ();
533 octave::cdef_method cdef_meth = cls.find_method (meth_name);
536 return cdef_meth.get_doc_string ();
545 if (m_object.is_class ())
547 octave::cdef_class cls (m_object);
549 return cls.file_name ();
562 std::string meth_name;
564 octave::cdef_class ctx;
566 ctx = octave::get_class_context (meth_name, in_constructor);
569 error (
"superclass calls can only occur in methods or constructors");
571 std::string mname = m_method_name;
572 std::string cname = m_class_name;
577 octave::cdef_class cls = octave::lookup_class (cname);
582 error (
"'%s' is not a direct superclass of '%s'",
583 cname.c_str (), ctx.get_name ().c_str ());
585 if (! is_constructed_object (tw, mname))
586 error (
"cannot call superclass constructor with variable '%s'",
591 cls.run_constructor (octave::to_cdef_ref (sym), idx);
597 std::size_t pos = mname.find (
'.');
599 octave::cdef_object obj;
601 if (pos != std::string::npos)
605 std::string oname = m_method_name.substr (0, pos);
606 mname = mname.substr (pos + 1);
629 if (mname != meth_name)
630 error (
"method name mismatch ('%s' != '%s')",
631 mname.c_str (), meth_name.c_str ());
634 error (
"'%s' is not a superclass of '%s'",
635 cname.c_str (), ctx.get_name ().c_str ());
648 octave::cdef_method meth = cls.find_method (meth_name,
false);
651 error (
"no method '%s' found in superclass '%s'",
652 meth_name.c_str (), cname.c_str ());
655 ? meth.execute (obj, idx, nargout,
true, meth_name)
656 : meth.execute (idx, nargout,
true, meth_name));
663octave_classdef_superclass_ref::is_constructed_object (octave::tree_evaluator& tw,
664 const std::string& nm)
674 octave::tree_parameter_list *ret_list = uf->
return_list ();
676 if (ret_list && ret_list->size () == 1)
677 return (ret_list->front ()->name () == nm);
686DEFUN (__meta_get_package__, args, ,
692 if (args.length () != 1)
695 std::string cname = args(0).xstring_value (
"PKG_NAME must be a string");
700DEFUN (metaclass, args, ,
706 if (args.length () != 1)
719DEFUN (properties, args, nargout,
735 if (args.length () != 1)
740 std::string class_name;
754 error (
"invalid class: %s", class_name.c_str ());
756 std::map<octave::property_key, cdef_property> property_map =
759 std::list<std::string> property_names;
761 for (
const auto& pname_prop : property_map)
777 property_names.push_back (pname_prop.second.get_name ());
783 octave_stdout <<
"properties for class " << class_name <<
":\n\n";
785 for (
const auto& nm : property_names)
813 std::string class_name;
830 std::map<std::string, cdef_method> method_map
833 std::list<std::string> method_names;
835 for (
const auto& nm_mthd : method_map)
849 method_names.push_back (nm_mthd.first);
861 found = ! sv.
empty ();
872OCTAVE_END_NAMESPACE(octave)
bool isvector(const dim_vector &dim)
bool is_superclass(const cdef_class &clsa, const cdef_class &clsb, bool allow_equal, int max_depth)
bool is_strict_superclass(const cdef_class &clsa, const cdef_class &clsb)
cdef_object to_cdef(const octave_value &val)
cdef_class lookup_class(const std::string &name, bool error_if_not_found, bool load_if_not_found)
octave_value to_ov(const cdef_object &obj)
cdef_package lookup_package(const std::string &name, bool error_if_not_found, bool load_if_not_found)
bool is_direct_superclass(const cdef_class &clsa, const cdef_class &clsb)
std::map< property_key, cdef_property > get_property_map(int mode=property_normal)
std::map< std::string, cdef_method > get_method_map(bool only_inherited=false, bool include_ctor=false)
cdef_class get_class() const
octave_value get(const std::string &pname) const
std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
virtual bool is_scalar_type() const
void increment_indent_level() const
void indent(std::ostream &os) const
void newline(std::ostream &os) const
static void register_type()
octave::refcount< octave_idx_type > m_count
virtual octave_idx_type xnumel(const octave_value_list &)
void decrement_indent_level() const
virtual octave_user_function * user_function_value(bool silent=false)
virtual octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
friend class octave_value
virtual bool is_matrix_type() const
octave_value_list execute(octave::tree_evaluator &tw, int nargout, const octave_value_list &idx)
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
bool is_instance_of(const std::string &cls_name) const
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave::cdef_object get_object() const
static octave_value metaclass_query(const std::string &cls)
octave_idx_type xnumel(const octave_value_list &)
static octave_value superclass_ref(const std::string &meth, const std::string &cls)
std::string class_name() const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
virtual bool is_classdef_constructor(const std::string &="") const
octave::tree_parameter_list * return_list()
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
octave_idx_type length() const
bool is_classdef_object() const
std::string class_name() const
bool bool_value(bool warn=false) const
octave_classdef * classdef_object_value(bool silent=false) const
void short_disp(std::ostream &os) const
std::string string_value(bool force=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
void err_wrong_type_arg(const char *name, const char *s)
octave_value make_idx_args(const std::string &type, const std::list< octave_value_list > &idx, const std::string &who)
bool called_from_builtin()
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.