23 #if !defined (octave_classdef_h)
24 #define octave_classdef_h 1
60 { gripe_invalid_object (
"set_class"); }
64 gripe_invalid_object (
"clone");
70 gripe_invalid_object (
"empty_clone");
76 gripe_invalid_object (
"copy");
82 gripe_invalid_object (
"make_array");
86 virtual bool is_array (
void)
const {
return false; }
96 gripe_invalid_object (
"array_value");
101 { gripe_invalid_object (
"put"); }
105 gripe_invalid_object (
"get");
110 subsref (
const std::string&,
const std::list<octave_value_list>&,
113 gripe_invalid_object (
"subsref");
118 subsasgn (
const std::string&,
const std::list<octave_value_list>&,
121 gripe_invalid_object (
"subsasgn");
127 virtual bool is_valid (
void)
const {
return false; }
132 { gripe_invalid_object (
"mark_for_construction"); }
136 gripe_invalid_object (
"is_constructed_for");
142 gripe_invalid_object (
"is_partially_constructed_for");
147 { gripe_invalid_object (
"mark_as_constructed"); }
150 { gripe_invalid_object (
"mark_as_constructed"); }
154 gripe_invalid_object (
"is_constructed");
164 if (--refcount == static_count ())
184 {
error (
"%s: invalid object", who); }
252 {
rep->
put (pname, val); }
255 {
return rep->
get (pname); }
258 subsref (
const std::string&
type,
const std::list<octave_value_list>& idx,
260 bool auto_add =
false)
261 {
return rep->
subsref (type, idx, nargout, skip, context, auto_add); }
264 subsasgn (
const std::string&
type,
const std::list<octave_value_list>& idx,
340 void register_object (
void);
342 void unregister_object (
void);
374 subsref (
const std::string&
type,
const std::list<octave_value_list>& idx,
379 subsasgn (
const std::string&
type,
const std::list<octave_value_list>& idx,
409 { map.assign (pname, val); }
413 Cell val = map.contents (pname);
415 if (val.
numel () > 0)
419 error (
"get: unknown slot: %s", pname.c_str ());
425 subsref (
const std::string&
type,
const std::list<octave_value_list>& idx,
430 subsasgn (
const std::string&
type,
const std::list<octave_value_list>& idx,
450 std::map< cdef_class, std::list<cdef_class> >
ctor_list;
536 virtual bool is_class (
void)
const {
return false; }
546 const std::list<octave_value_list>& ,
549 ::error (
"subsref: invalid meta object");
597 const std::list<octave_value_list>& idx,
int nargout)
598 {
return get_rep ()->meta_subsref (type, idx, nargout); }
603 {
return get_rep ()->meta_is_postfix_index_handled (type); }
624 object_count (0), meta (false) { }
633 {
return get (
"Name").string_value (); }
637 bool is_abstract (
void)
const {
return get (
"Abstract").bool_value (); }
639 bool is_sealed (
void)
const {
return get (
"Sealed").bool_value (); }
641 cdef_method find_method (
const std::string& nm,
bool local =
false);
645 Cell get_methods (
void);
651 Cell get_properties (
int mode);
653 std::map<std::string, cdef_property> get_property_map (
int mode);
664 meta_subsref (
const std::string&
type,
665 const std::list<octave_value_list>& idx,
int nargout);
667 void meta_release (
void);
670 {
return (type ==
'(' || type ==
'.'); }
699 property_map.clear ();
710 void load_all_methods (
void);
712 void find_names (std::set<std::string>&
names,
bool all);
714 void find_properties (std::map<std::string,cdef_property>& props,
717 void find_methods (std::map<std::string, cdef_method>& meths,
718 bool only_inherited);
764 method_map (c.method_map), property_map (c.property_map),
765 member_count (c.member_count), handle_class (c.handle_class),
766 implicit_ctor_list (c.implicit_ctor_list),
767 object_count (c.object_count), meta (c.meta) { }
776 const std::list<cdef_class>& superclasses)
788 error (
"internal error: invalid assignment from %s to meta.class object",
799 cdef_method find_method (
const std::string& nm,
bool local =
false);
802 {
get_rep ()->install_method (meth); }
809 {
get_rep ()->install_property (prop); }
812 {
return get_rep ()->get_properties (mode); }
814 std::map<std::string, cdef_property>
816 {
return get_rep ()->get_property_map (mode); }
825 {
get_rep ()->set_directory (dir); }
828 {
return get_rep ()->get_directory (); }
831 {
return get_rep ()->get_name (); }
834 {
return get_directory ().empty (); }
837 {
get_rep ()->delete_object (obj); }
840 bool is_at_folder =
false);
845 {
return get_method_function (get_name ()); }
848 {
return get_rep ()->construct (args); }
851 {
return get_rep ()->construct_object (args); }
854 {
get_rep ()->initialize_object (obj); }
857 {
get_rep ()->run_constructor (obj, args); }
860 {
get_rep ()->mark_as_handle_class (); }
863 {
return get_rep ()->is_handle_class (); }
913 {
return ! (clsa == clsb); }
938 std::string
get_name (
void)
const {
return get(
"Name").string_value (); }
942 bool is_constant (
void)
const {
return get(
"Constant").bool_value (); }
945 const std::string& who = std::string ());
948 bool do_check_access =
true,
949 const std::string& who = std::string ());
952 bool do_check_access =
true,
953 const std::string& who = std::string ());
955 bool check_get_access (
void)
const;
957 bool check_set_access (
void)
const;
963 bool is_recursive_set (
const cdef_object& obj)
const;
987 error (
"internal error: invalid assignment from %s to meta.property object",
999 const std::string& who = std::string ())
1000 {
return get_rep ()->get_value (obj, do_check_access, who); }
1003 const std::string& who = std::string ())
1004 {
return get_rep ()->get_value (do_check_access, who); }
1007 bool do_check_access =
true,
1008 const std::string& who = std::string ())
1009 {
get_rep ()->set_value (obj, val, do_check_access, who); }
1012 {
return get_rep ()->check_get_access (); }
1015 {
return get_rep ()->check_set_access (); }
1048 std::string
get_name (
void)
const {
return get(
"Name").string_value (); }
1052 bool is_static (
void)
const {
return get(
"Static").bool_value (); }
1063 { dispatch_type = dtype; }
1066 bool do_check_access =
true,
1067 const std::string& who = std::string ());
1071 bool do_check_access =
true,
1072 const std::string& who = std::string ());
1074 bool is_constructor (
void)
const;
1078 const std::list<octave_value_list>& idx,
int nargout);
1081 {
return (type ==
'(' || type ==
'.'); }
1086 dispatch_type (m.dispatch_type)
1089 void check_method (
void);
1120 error (
"internal error: invalid assignment from %s to meta.method object",
1133 bool do_check_access =
true,
1134 const std::string& who = std::string ())
1135 {
return get_rep ()->execute (args, nargout, do_check_access, who); }
1140 bool do_check_access =
true,
1141 const std::string& who = std::string ())
1142 {
return get_rep ()->execute (obj, args, nargout, do_check_access, who); }
1151 {
get_rep ()->set_function (fcn); }
1154 {
return get_rep ()->get_function (); }
1157 {
return get_rep ()->is_constructor (); }
1162 {
get_rep ()->mark_as_external (dtype); }
1266 std::string
get_name (
void)
const {
return get(
"Name").string_value (); }
1270 void install_class (
const cdef_class& cls,
const std::string& nm);
1272 void install_function (
const octave_value& fcn,
const std::string& nm);
1274 void install_package (
const cdef_package& pack,
const std::string& nm);
1276 Cell get_classes (
void)
const;
1278 Cell get_functions (
void)
const;
1280 Cell get_packages (
void)
const;
1293 package_map.clear ();
1301 const std::list<octave_value_list>& idx,
int nargout);
1306 {
return (type ==
'.'); }
1330 class_map (p.class_map), function_map (p.function_map),
1331 package_map (p.package_map), member_count (p.member_count)
1356 error (
"internal error: invalid assignment from %s to meta.package object",
1368 {
get_rep ()->install_class (cls, nm); }
1371 {
get_rep ()->install_function (fcn, nm); }
1374 {
get_rep ()->install_package (pack, nm); }
1377 {
return get_rep ()->get_classes (); }
1380 {
return get_rep ()->get_functions (); }
1383 {
return get_rep ()->get_packages (); }
1435 void print (std::ostream& os,
bool pr_as_read_syntax =
false);
1437 void print_raw (std::ostream& os,
bool pr_as_read_syntax =
false)
const;
1439 bool print_name_tag (std::ostream& os,
const std::string& name)
const;
1441 void print_with_name (std::ostream& os,
const std::string& name,
1442 bool print_padding =
true);
1444 bool is_instance_of (
const std::string& cls_name)
const;
1447 const std::list<octave_value_list>& idx,
1451 const std::list<octave_value_list>& idx)
1458 const std::list<octave_value_list>& idx,
1462 const std::list<octave_value_list>& idx,
1466 undef_subsasgn (
const std::string&
type,
1467 const std::list<octave_value_list>& idx,
1484 std::string
class_name (
void)
const {
return object.class_name (); }
1489 static void register_type (
void);
1514 return dynamic_cast<octave_classdef *> (val.
internal_rep ())->get_object ();
1517 error (
"cannot convert `%s' into `object'", val.
type_name().c_str ());
1528 return dynamic_cast<octave_classdef *> (val.
internal_rep ())->get_object_ref ();
1531 error (
"cannot convert `%s' into `object'", val.
type_name().c_str ());
1548 bool error_if_not_found =
true,
1549 bool load_if_not_found =
true)
1552 return instance->do_find_class (name, error_if_not_found,
1562 return instance->do_find_method_symbol (method_name, class_name);
1568 bool error_if_not_found =
true,
1569 bool load_if_not_found =
true)
1572 return instance->do_find_package (name, error_if_not_found,
1581 return instance->do_find_package_symbol (pack_name);
1589 instance->do_register_class (cls);
1595 instance->do_unregister_class (cls);
1601 instance->do_register_package (pkg);
1607 instance->do_unregister_package (pkg);
1620 static void create_instance (
void);
1631 ::error (
"unable to create cdef_manager!");
1646 cdef_class do_find_class (
const std::string& name,
bool error_if_not_found,
1647 bool load_if_not_found);
1649 octave_function* do_find_method_symbol (
const std::string& method_name,
1653 bool error_if_not_found,
1654 bool load_if_not_found);
1656 octave_function* do_find_package_symbol (
const std::string& pack_name);
1659 { all_classes[cls.
get_name ()] = cls; }
1662 { all_classes.erase(cls.
get_name ()); }
1665 { all_packages[pkg.
get_name ()] = pkg; }
1668 { all_packages.erase(pkg.
get_name ()); }
cdef_object get_object(void) const
std::map< std::string, cdef_package > package_map
std::map< std::string, cdef_package > all_packages
cdef_package(const std::string &nm)
void unregister_object(void)
octave_value get_value(bool do_check_access=true, const std::string &who=std::string())
bool is_abstract(void) const
void unregister_object(void)
void unregister_object(void)
bool is_value_object(void) const
void gripe_invalid_object(const char *who) const
octave_value find(const std::string &nm)
bool is_static(void) const
Cell get_properties(int mode=property_normal)
std::string get_name(void) const
octave_value get_function(void) const
void register_object(void)
void install_method(const cdef_method &meth)
dim_vector dims(void) const
bool is_constructed_for(const cdef_class &cls) const
bool is_valid(void) const
cdef_object empty_clone(void) const
std::map< std::string, cdef_class > all_classes
void do_unregister_package(const cdef_package &pkg)
cdef_object_rep * clone(void) const
cdef_method_rep(const cdef_method_rep &m)
virtual cdef_object_rep * make_array(void) const
std::string get_directory(void) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout, size_t &skip, const cdef_class &context, bool auto_add=false)
octave_idx_type member_count
virtual bool is_handle_object(void) const
std::map< std::string, octave_value >::const_iterator function_const_iterator
bool is_handle_class(void) const
octave_map map_value(void) const
octave_idx_type numel(void) const
Number of elements in the array.
cdef_object & operator=(const cdef_object &obj)
cdef_object make_array(void) const
bool check_set_access(void) const
octave_idx_type length(void) const
void set_name(const std::string &nm)
cdef_method(const cdef_method &meth)
cdef_object_rep * make_array(void) const
dim_vector dims(void) const
octave_base_value * empty_clone(void) const
void register_object(void)
void mark_for_construction(const cdef_class &cls)
cdef_property(const std::string &nm)
void put(const std::string &pname, const octave_value &val)
static const cdef_class & meta_package(void)
virtual Array< cdef_object > array_value(void) const
virtual bool is_constructed_for(const cdef_class &) const
Array< cdef_object > array
void install_package(const cdef_package &pack, const std::string &nm)
static const cdef_class & meta_property(void)
std::string get_name(void) const
void mark_as_constructed(const cdef_class &cls)
void error(const char *fmt,...)
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who=std::string())
bool is_array(void) const
octave_base_value * clone(void) const
cdef_object_array(const Array< cdef_object > &a)
virtual bool is_value_object(void) const
cdef_object & to_cdef_ref(const octave_value &val)
static string_vector names(const map_type &lst)
void set_value(cdef_object &obj, const octave_value &val, bool do_check_access=true, const std::string &who=std::string())
void register_object(void)
std::map< cdef_class, std::list< cdef_class > > ctor_list
bool meta_is_postfix_index_handled(char type) const
bool is_external(void) const
static void register_class(const cdef_class &cls)
static cdef_package find_package(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
bool is_sealed(void) const
bool is_constructed(void) const
bool is_method(void) const
cdef_object_rep * copy(void) const
bool is_constructor(void) const
cdef_object_rep * copy(void) const
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who=std::string())
virtual string_vector map_keys(void) const
void set_name(const std::string &nm)
std::map< std::string, cdef_class >::iterator class_iterator
void fill_empty_values(void)
handle_cdef_object(const handle_cdef_object &obj)
static octave_function * find_method_symbol(const std::string &method_name, const std::string &class_name)
bool is_handle_object(void) const
std::string class_name(void) const
virtual octave_value get(const std::string &) const
Array< cdef_object > array_value(void) const
std::map< std::string, cdef_property >::iterator property_iterator
octave_idx_type static_count(void) const
bool check_get_access(void) const
cdef_property_rep(const cdef_property_rep &p)
void set_name(const std::string &nm)
virtual void mark_as_constructed(void)
void initialize_object(cdef_object &obj)
std::map< std::string, cdef_property >::const_iterator property_const_iterator
bool is_handle_object(void) const
bool is_array(void) const
cdef_class & operator=(const cdef_class &cls)
octave_idx_type static_count(void) const
dim_vector dims(void) const
virtual cdef_class get_class(void) const
const cdef_class_rep * get_rep(void) const
static bool instance_ok(void)
cdef_class get_class(void) const
std::string get_name(void) const
cdef_object_rep * copy(void) const
void do_register_class(const cdef_class &cls)
bool meta_is_postfix_index_handled(char type) const
Cell get_functions(void) const
bool check_access(void) const
void install_class(const cdef_class &cls, const std::string &nm)
cdef_package_rep * get_rep(void)
cdef_object_rep * copy(void) const
std::map< std::string, cdef_package >::const_iterator package_const_iterator
octave_refcount< octave_idx_type > refcount
void set_directory(const std::string &dir)
cdef_method find_method(const std::string &nm, bool local=false)
octave_function * get_constructor_function(void)
bool is_object(void) const
OCTINTERP_API void install_classdef(void)
virtual octave_idx_type static_count(void) const
static llvm::LLVMContext & context
cdef_object_base(const cdef_object_base &obj)
cdef_object_rep * get_rep(void)
virtual octave_value subsasgn(const std::string &, const std::list< octave_value_list > &, const octave_value &)
virtual void put(const std::string &, const octave_value &)
void mark_as_external(const std::string &dtype)
void put(const std::string &pname, const octave_value &val)
static const cdef_class & meta_method(void)
bool operator<(const cdef_class &clsa, const cdef_class &clsb)
virtual void mark_for_construction(const cdef_class &)
void mark_as_handle_class(void)
cdef_object_rep * clone(void) const
static cdef_class _meta_method
std::string dispatch_type
static cdef_manager * instance
std::list< cdef_class > implicit_ctor_list
octave_value to_ov(const cdef_object &obj)
void set_name(const std::string &nm)
cdef_property(const cdef_property &prop)
cdef_method(const std::string &nm)
const cdef_method_rep * get_rep(void) const
virtual void mark_as_constructed(const cdef_class &)
virtual cdef_object_rep * clone(void) const
bool is_constant(void) const
static cdef_package _meta
static cdef_class _meta_class
bool is_meta_object(void) const
std::string get_name(void) const
static int static_type_id(void)
virtual ~cdef_object(void)
virtual dim_vector dims(void) const
Array< cdef_object > array_value(void) const
static octave_function * find_package_symbol(const std::string &pack_name)
bool is_class(void) const
virtual bool is_valid(void) const
octave_value get_function(void) const
static cdef_class _meta_package
cdef_package(const cdef_package &pack)
cdef_object_rep(const cdef_object_rep &)
octave_classdef(const cdef_object &obj)
cdef_object_rep * copy(void) const
cdef_method_rep * get_rep(void)
virtual cdef_object_rep * empty_clone(void) const
static cdef_class _meta_property
cdef_class get_class(void) const
void mark_as_meta_class(void)
octave_refcount< octave_idx_type > object_count
std::map< std::string, cdef_package >::iterator package_iterator
virtual void destroy(void)
virtual ~cdef_object_rep(void)
octave_value construct(const octave_value_list &args)
bool is_classdef_object(void) const
void install_function(const octave_value &fcn, const std::string &nm)
cdef_object_scalar(const cdef_object_scalar &obj)
bool is_value_object(void) const
cdef_property find_property(const std::string &nm)
cdef_object(const cdef_object &obj)
cdef_object & get_object_ref(void)
bool meta_is_postfix_index_handled(char type) const
const cdef_property_rep * get_rep(void) const
cdef_class(const cdef_class &cls)
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
bool is_property(void) const
cdef_object_rep * copy(void) const
std::string class_name(void) const
cdef_property find_property(const std::string &nm)
virtual void set_class(const cdef_class &)
cdef_object_rep * empty_clone(void) const
virtual octave_value_list subsref(const std::string &, const std::list< octave_value_list > &, int, size_t &, const cdef_class &, bool)
bool operator!=(const cdef_class &clsa, const cdef_class &clsb)
std::string type_name(void) const
string_vector map_keys(void) const
void make_unique(int ignore_copies)
std::map< std::string, octave_value > function_map
static cdef_class make_meta_class(const std::string &name, const cdef_class &super)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
std::string get_directory(void) const
Cell get_classes(void) const
bool is_external(void) const
bool is_constant(void) const
cdef_object to_cdef(const octave_value &val)
void mark_as_meta_class(void)
const cdef_package_rep * get_rep(void) const
void mark_as_handle_class(void)
static const std::string t_name
std::string get_name(void) const
virtual bool is_array(void) const
virtual cdef_object_rep * copy(void) const
std::map< std::string, cdef_class >::const_iterator class_const_iterator
std::map< std::string, cdef_property > property_map
void set_class(const cdef_class &cls)
void run_constructor(cdef_object &obj, const octave_value_list &args)
void mark_as_constructed(const cdef_class &cls)
std::string get_name(void) const
string_vector map_keys(void) const
static std::string static_class_name(void)
std::string get_name(void) const
cdef_object construct_object(const octave_value_list &args)
std::map< std::string, cdef_method > method_map
std::map< std::string, cdef_property > get_property_map(int mode=property_normal)
octave_classdef(const octave_classdef &obj)
bool is_meta_class(void) const
void mark_as_external(const std::string &dtype)
cdef_class_rep(const cdef_class_rep &c)
static void register_package(const cdef_package &pkg)
cdef_object(cdef_object_rep *r)
void mark_as_constructed(void)
static void unregister_package(const cdef_package &pkg)
~cdef_object_scalar(void)
octave_map map_value(void) const
static bool check_access(const cdef_class &cls, const octave_value &acc, const std::string &meth_name=std::string(), const std::string &prop_name=std::string(), bool is_prop_set=false)
cdef_class_rep * get_rep(void)
bool is_partially_constructed_for(const cdef_class &cls) const
cdef_object clone(void) const
bool is_valid(void) const
bool is_defined(void) const
std::string get_name(void) const
void do_register_package(const cdef_package &pkg)
std::map< std::string, octave_value >::iterator function_iterator
cdef_class(const cdef_object &obj)
std::map< std::string, cdef_method >::const_iterator method_const_iterator
bool is_static(void) const
void delete_object(cdef_object obj)
const cdef_object_rep * get_rep(void) const
static const cdef_class & meta_class(void)
dim_vector dims(void) const
std::map< std::string, cdef_method >::iterator method_iterator
cdef_property_rep * get_rep(void)
void mark_as_constructed(void)
cdef_class(const std::string &nm, const std::list< cdef_class > &superclasses)
cdef_object_rep * clone(void) const
value_cdef_object(const value_cdef_object &obj)
static void unregister_class(const cdef_class &cls)
octave_value_list execute(const cdef_object &obj, const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who=std::string())
cdef_object_array(const cdef_object_array &obj)
std::string class_name(void) const
cdef_method find_method(const std::string &nm, bool local=false)
bool is_meta_class(void) const
static void cleanup_instance(void)
bool operator==(const cdef_class &clsa, const cdef_class &clsb)
bool is_builtin(void) const
cdef_property(const cdef_object &obj)
static std::string static_type_name(void)
void set_function(const octave_value &fcn)
octave_idx_type member_count
std::string type_name(void) const
static const cdef_package & meta(void)
octave_base_value * internal_rep(void) const
void set_directory(const std::string &dir)
cdef_method(const cdef_object &obj)
bool is_handle_class(void) const
void set_class(const cdef_class &cls)
void install_property(const cdef_property &prop)
string_vector get_names(void)
cdef_object copy(void) const
cdef_package(const cdef_object &obj)
bool is_valid(void) const
cdef_package_rep(const cdef_package_rep &p)
virtual bool is_constructed(void) const
bool is_package(void) const
Cell get_packages(void) const
bool is_constructed(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs, int ignore_copies=0)
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
void set_function(const octave_value &fcn)
static cdef_class find_class(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
virtual bool is_partially_constructed_for(const cdef_class &) const
bool is_abstract(void) const
virtual bool is_meta_object(void) const
bool is_sealed(void) const
std::map< std::string, cdef_class > class_map
bool is(const cdef_object &obj) const
void do_unregister_class(const cdef_class &cls)