26 #if defined (HAVE_CONFIG_H)
53 in_class_method (
const octave::cdef_class& cls)
60 int octave_classdef::s_t_id (-1);
62 const 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");
99 bool maybe_cs_list_query = (type[0] ==
'.' || type[0] ==
'{'
100 || (type.length () > 1 && type[0] ==
'('
103 if (maybe_cs_list_query)
108 if (type[0] !=
'.') tmp = idx.front ();
110 if (nargout != 0 || nout > 1)
113 else if (nargout < 0)
117 retval = meth.execute (args, nargout,
true,
"subsref");
123 if (retval.
length () > 1 && (nargout < 0 || nargout > 1))
125 if (nargout <= 0 || nargout >= retval.
length ())
139 retval = m_object.subsref (type, idx, nargout, skip, octave::cdef_class ());
141 if (type.length () > skip && idx.size () > skip)
142 retval = retval(0).next_subsref (nargout, type, idx, skip);
149 const std::list<octave_value_list>& idx,
152 std::size_t skip = 0;
159 octave::cdef_class cls = m_object.get_class ();
161 if (! in_class_method (cls))
163 octave::cdef_method meth = cls.find_method (
"subsref");
174 retval = meth.execute (args, 1,
true,
"subsref");
180 retval = m_object.subsref (type, idx, 1, skip,
181 octave::cdef_class (), auto_add);
183 if (type.length () > skip && idx.size () > skip)
184 retval = retval(0).next_subsref (1, type, idx, skip);
191 const std::list<octave_value_list>& idx,
196 octave::cdef_class cls = m_object.get_class ();
200 octave::cdef_method meth = cls.find_method (
"subsasgn");
214 retlist = meth.execute (args, 1,
true,
"subsasgn");
216 if (retlist.
empty ())
217 error (
"overloaded method 'subsasgn' did not return any value");
224 retval = m_object.subsasgn (type, idx, rhs);
231 const std::list<octave_value_list>& idx,
234 if (type.length () == 1 && type[0] ==
'(')
236 m_object = m_object.make_array ();
249 octave::cdef_class cls = m_object.get_class ();
253 octave::cdef_method meth = cls.find_method (
"size");
265 return lv(0).matrix_value ();
277 octave::cdef_class cls = m_object.get_class ();
281 octave::cdef_method meth = cls.find_method (
"numel");
296 octave::tree_evaluator& tw = interp.get_evaluator();
298 octave::unwind_action act ([&tw] (
const std::list<octave::octave_lvalue> *lvl)
300 tw.set_lvalue_list (lvl);
301 }, tw.lvalue_list ());
302 tw.set_lvalue_list (
nullptr);
306 error (
"@%s/numel: invalid return value", cls.get_name ().c_str ());
308 retval = lv(0).idx_type_value (
true);
328 octave::cdef_class cls = m_object.get_class ();
332 bool is_array = m_object.is_array ();
340 os <<
" with properties:";
347 std::map<std::string, octave::cdef_property> property_map
348 = cls.get_property_map ();
350 std::size_t max_len = 0;
351 for (
const auto& pname_prop : property_map)
356 const octave::cdef_property& prop = pname_prop.second;
358 const std::string nm = prop.get_name ();
370 std::size_t sz = nm.
size ();
376 for (
auto& pname_prop : property_map)
378 const octave::cdef_property& prop = pname_prop.second;
380 const std::string nm = prop.get_name ();
401 os << std::setw (max_len+2) << nm <<
": ";
431 const std::string& cls)
447 if (m_object.is_method ())
453 octave::cdef_method meth (m_object);
455 return meth.is_defined_in_class (cname);
467 if (m_object.is_class ())
473 octave::cdef_class cls (m_object);
475 if (cls.get_name () == cname)
479 else if (m_object.is_method ())
481 octave::cdef_method meth (m_object);
483 if (meth.is_constructor ())
485 std::string meth_name = meth.get_name ();
491 if (cname == meth_name)
509 if (m_object.is_class ())
511 octave::cdef_class cls (m_object);
513 if (meth_name.empty ())
514 return cls.doc_string ();
516 octave::cdef_method cdef_meth = cls.find_method (meth_name);
519 return cdef_meth.get_doc_string ();
528 if (m_object.is_class ())
530 octave::cdef_class cls (m_object);
532 return cls.file_name ();
545 std::string meth_name;
547 octave::cdef_class ctx;
552 error (
"superclass calls can only occur in methods or constructors");
554 std::string mname = m_method_name;
555 std::string cname = m_class_name;
565 error (
"'%s' is not a direct superclass of '%s'",
566 cname.c_str (), ctx.get_name ().c_str ());
568 if (! is_constructed_object (tw, mname))
569 error (
"cannot call superclass constructor with variable '%s'",
580 std::size_t pos = mname.find (
'.');
582 octave::cdef_object obj;
584 if (pos != std::string::npos)
588 std::string oname = m_method_name.substr (0, pos);
589 mname = mname.substr (pos + 1);
612 if (mname != meth_name)
613 error (
"method name mismatch ('%s' != '%s')",
614 mname.c_str (), meth_name.c_str ());
617 error (
"'%s' is not a superclass of '%s'",
618 cname.c_str (), ctx.get_name ().c_str ());
631 octave::cdef_method meth = cls.find_method (meth_name,
false);
634 error (
"no method '%s' found in superclass '%s'",
635 meth_name.c_str (), cname.c_str ());
638 ? meth.execute (obj, idx, nargout,
true, meth_name)
639 : meth.execute (idx, nargout,
true, meth_name));
646 octave_classdef_superclass_ref::is_constructed_object (octave::tree_evaluator& tw,
647 const std::string& nm)
657 octave::tree_parameter_list *ret_list = uf->
return_list ();
659 if (ret_list && ret_list->length () == 1)
660 return (ret_list->front ()->name () == nm);
669 DEFUN (__meta_get_package__, args, ,
675 if (args.length () != 1)
678 std::string cname = args(0).xstring_value (
"PKG_NAME must be a string");
683 DEFUN (metaclass, args, ,
689 if (args.length () != 1)
702 DEFUN (properties, args, nargout,
718 if (args.length () != 1)
723 std::string class_name;
737 error (
"invalid class: %s", class_name.c_str ());
739 std::map<std::string, cdef_property> property_map =
742 std::list<std::string> property_names;
744 for (
const auto& pname_prop : property_map)
760 property_names.push_back (pname_prop.first);
766 octave_stdout <<
"properties for class " << class_name <<
":\n\n";
768 for (
const auto& nm : property_names)
796 std::string class_name;
813 std::map<std::string, cdef_method> method_map
816 std::list<std::string> method_names;
818 for (
const auto& nm_mthd : method_map)
832 method_names.push_back (nm_mthd.first);
844 found = ! sv.
empty ();
855 OCTAVE_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_object & to_cdef_ref(const octave_value &val)
cdef_class get_class_context(std::string &name, bool &in_constructor)
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< std::string, 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
Vector representing the dimensions (size) of an Array.
std::string str(char sep='x') 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
std::string string_value(bool force=false) const
octave_classdef * classdef_object_value(bool silent=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)
interpreter & __get_interpreter__()
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
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.