26#if defined (HAVE_CONFIG_H)
40#define OCTAVE_CDEF_OBJECT_DEBUG 0
41#if OCTAVE_CDEF_OBJECT_DEBUG
84 catch (
const interrupt_exception&)
88 warning (
"interrupt occurred in handle class delete method");
94 std::string msg = ee.message ();
96 warning (
"error caught while executing handle class delete method:\n%s\n",
99 catch (
const exit_exception&)
102 warning (
"exit disabled while executing handle class delete method");
107 warning (
"internal error: unhandled exception in handle class delete method");
120 err_invalid_object (
"get_class");
147 "struct: converting a classdef object into a struct "
148 "overrides the access restrictions defined for "
149 "properties. All properties are returned, including "
150 "private and protected ones.");
156 std::map<property_key, cdef_property> props;
161 for (
auto& prop_val : props)
165 if (for_save && prop_val.second.get (
"Transient").bool_value ())
175 cvalue (i) = prop_val.second.get_value (a_obj(i),
false);
177 retval.
setfield (prop_val.second.get_name (), cvalue);
182 prop_val.second.get_value (*
this,
false));
184 retval.
setfield (prop_val.second.get_name (), cvalue);
208 || (m_klass.
ok () && ! cls.
ok ())
209 || (! m_klass.
ok () && cls.
ok ()))
231 new_array(i) = m_array(i).clone ();
252 std::unique_ptr<cdef_object_array> guard (retval);
259 return guard.release ();
265 if (m_array.
ndims () > 2)
266 error (
"transpose not defined for N-D objects");
274 const std::list<octave_value_list>& idx,
275 int , std::size_t& skip,
298 for (
int i = 0; i < ival.
length (); i++)
302 iv(i) = ival(i).index_vector ();
324 retval(0) =
to_ov (ires(0));
331 retval(0) =
to_ov (array_obj);
337 if (m_array.
numel () == 1)
344 std::size_t dummy_skip;
346 retval = m_array(0).subsref (type, idx, 1, dummy_skip, dummy_cls);
350 else if (type.size () == 1 && idx.size () == 1)
357 std::size_t dummy_skip;
377 error (
"can't perform indexing operation on array of %s objects",
387 const std::list<octave_value_list>& idx,
395 if (type.length () == 1)
401 for (
int i = 0; i < ival.
length (); i++)
405 iv(i) = ival(i).index_vector ();
423 error (
"can't assign %s object into array of %s objects",
432 rhs_mat(0) = rhs_obj;
441 if (m_array.
numel () > n)
456 for (
int i = 0; i < ival.
length (); i++)
460 iv(i) = ival(i).index_vector ();
472 error (
"subsasgn: invalid indexing for object array assignment"
473 ", the index must reference a single object in the "
480 error (
"subsasgn: invalid indexing for object array assignment");
484 int ignore_copies = 0;
498 std::list<octave_value_list> next_idx (std::next (idx.begin ()),
509 error (
"subsasgn: invalid assignment into array of %s objects",
516 if (! robj.
is (a(0)))
523 m_array.
assign (iv, rhs_a);
525 if (m_array.
numel () > n)
536 if (m_array.
numel () == 1)
541 retval = m_array(0).subsasgn (type, idx, rhs);
548 error (
"can't perform indexing operation on array of %s objects",
571 int n = arr.
numel ();
573 for (
int i = 0; i < n; i++)
575 if (! arr.
xelem (i).ok ())
593 m_array(i).break_closure_cycles (frame);
605 const std::list<octave_value_list>& idx,
606 int nargout, std::size_t& skip,
622 std::string name = (idx.front ())(0).string_value ();
629 retval(0) = prop.
get_value (
true,
"subsref");
645 error (
"subsref: unknown method or property: %s", name.c_str ());
649 int nargout_mtd = (type.length () > 2
650 || (type.length () == 2 && type[1] !=
'(')
657 if (type.length () > 1 && type[1] ==
'(')
659 auto it = idx.begin ();
667 retval = meth.
execute (args, nargout_mtd,
true,
"subsref");
689 retval(0) =
to_ov (this_obj);
699 retval = new_obj.
subsref (type, idx, nargout, skip, cls, auto_add);
705 error (
"object cannot be indexed with '%c'", type[0]);
714 const std::list<octave_value_list>& idx,
725 std::string name = (idx.front ())(0).string_value ();
730 error (
"subsasgn: unknown property: %s", name.c_str ());
733 error (
"subsasgn: cannot assign constant property: %s",
740 if (type.length () == 1)
742 prop.
set_value (obj, rhs,
true,
"subsasgn");
744 retval =
to_ov (obj);
750 std::list<octave_value_list> args (std::next (idx.begin ()),
754 type.substr (1), args, rhs);
758 prop.
set_value (obj, val,
true,
"subsasgn");
760 retval =
to_ov (obj);
784 error (
"subsasgn: object cannot be index with '%c'", type[0]);
794 if (new_dims.
numel () != 1)
796 std::string new_dims_str = new_dims.
str ();
797 error (
"reshape: cannot reshape scalar classdef object to %s array",
798 new_dims_str.c_str ());
807 if (dv.
numel () == 1)
818 std::unique_ptr<cdef_object_array> guard (retval);
825 return guard.release ();
831 std::string cls_name = cls.
get_name ();
853 std::map<cdef_class, std::list<cdef_class>>::const_iterator it
856 if (it ==
m_ctor_list.end () || it->second.empty ())
859 for (
const auto& cdef_cls : it->second)
874#if OCTAVE_CDEF_OBJECT_DEBUG
876 <<
" object (handle)" << std::endl;
882#if OCTAVE_CDEF_OBJECT_DEBUG
884 <<
" object (value)" << std::endl;
888OCTAVE_END_NAMESPACE(octave)
bool is_scalar(const dim_vector &dim)
cdef_object to_cdef(const octave_value &val)
octave_value to_ov(const cdef_object &obj)
std::list< cdef_class > lookup_classes(const Cell &cls_list)
N Dimensional Array with copy-on-write semantics.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & xelem(octave_idx_type n)
Size of the specified dimension.
Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
void assign(const octave::idx_vector &i, const Array< T, Alloc > &rhs, const T &rfv)
Indexed assignment (always with resize & fill).
int ndims() const
Size of the specified dimension.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
void delete_elements(const octave::idx_vector &i)
Deleting elements.
Array< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
cdef_method find_method(const std::string &nm, bool local=false)
string_vector get_names()
cdef_object construct_object(const octave_value_list &args, const bool default_initialize=false)
std::map< property_key, cdef_property > get_property_map(int mode=property_normal)
std::string get_name() const
void delete_object(const cdef_object &obj)
cdef_property find_property(const std::string &nm)
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
cdef_object_rep * transpose() const
cdef_object_rep * permute(const Array< int > &vec, bool inv=false) const
octave_value reshape(const dim_vector &new_dims) const
cdef_object_rep * clone() const
void break_closure_cycles(const std::shared_ptr< stack_frame > &frame)
cdef_object_rep * resize(const dim_vector &dv, bool fill=false) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout, std::size_t &skip, const cdef_class &context, bool auto_add)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
cdef_class get_class() const
void set_class(const cdef_class &cls)
cdef_object_rep * make_array() const
void release(const cdef_object &obj)
virtual cdef_object_rep * clone() const
virtual void set_class(const cdef_class &)
virtual string_vector map_keys() const
virtual bool is_meta_object() const
virtual bool is_handle_object() const
std::string class_name() const
virtual octave_idx_type static_count() const
virtual cdef_class get_class() const
refcount< octave_idx_type > m_count
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::map< cdef_class, std::list< cdef_class > > m_ctor_list
bool is_constructed() const
void mark_for_construction(const cdef_class &)
cdef_object_rep * resize(const dim_vector &dv, bool fill=false) const
bool is_partially_constructed_for(const cdef_class &cls) const
void mark_as_constructed()
void break_closure_cycles(const std::shared_ptr< stack_frame > &frame)
octave_value reshape(const dim_vector &new_dims) const
bool is_constructed_for(const cdef_class &cls) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout, std::size_t &skip, const cdef_class &context, bool auto_add)
cdef_class get_class() const
void set_class(const cdef_class &cls)
std::string class_name() const
octave_map map_value(bool warn=true, bool for_save=false) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs, int ignore_copies=0)
bool is(const cdef_object &obj) const
octave_value get(const std::string &pname) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout, std::size_t &skip, const cdef_class &context, bool auto_add=false)
Array< cdef_object > array_value() const
void set_value(cdef_object &obj, const octave_value &val, 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="") const
Vector representing the dimensions (size) of an Array.
std::string str(char sep='x') const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
void recover_from_exception()
void setfield(const std::string &key, const Cell &val)
const octave_value & contents(const_iterator p) const
octave_idx_type nfields() const
octave_idx_type length() const
std::string class_name() const
void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &)
octave_value & assign(assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void interpreter_try(unwind_protect &frame)
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
interpreter & __get_interpreter__()
std::atomic< int > octave_interrupt_state