26 #if defined (HAVE_CONFIG_H)
50 if (args.
length () == 1 && args(0).type_name () ==
"object")
54 retval(0) = cls.get_properties ();
65 if (args.
length () == 1 && args(0).type_name () ==
"object")
69 retval(0) = cls.get_methods ();
80 if (args.
length () == 1 && args(0).type_name () ==
"object"
81 && args(0).class_name () ==
"meta.class")
85 Cell classes = cls.get (
"SuperClasses").cell_value ();
98 if (args.
length () == 1 && args(0).type_name () ==
"object"
99 && args(0).class_name () ==
"meta.class")
103 Cell classes = cls.get (
"InferiorClasses").cell_value ();
117 error (
"fromName: invalid number of parameters");
119 std::string name = args(0).xstring_value (
"fromName: CLASS_NAME must be a string");
129 if (args.
length () <= 1 || args(0).type_name () !=
"object")
130 error (
"fevalStatic: first argument must be a meta.class object");
134 std::string meth_name = args(1).xstring_value (
"fevalStatic: method name must be a string");
139 error (
"fevalStatic: method not found: %s", meth_name.c_str ());
142 error (
"fevalStatic: method '%s' is not static", meth_name.c_str ());
144 return meth.
execute (args.
splice (0, 2), nargout,
true,
"fevalStatic");
152 if (args.
length () != 2 || args(0).type_name () !=
"object"
153 || args(0).class_name () !=
"meta.class")
154 error (
"getConstant: first argument must be a meta.class object");
158 std::string prop_name = args(1).xstring_value (
"getConstant: property name must be a string");
163 error (
"getConstant: property not found: %s",
167 error (
"getConstant: property '%s' is not constant",
170 retval(0) = prop.
get_value (
true,
"getConstant");
175 #define META_CLASS_CMP(OP, CLSA, CLSB, FCN) \
176 static octave_value_list \
177 class_ ## OP (const octave_value_list& args, int ) \
179 octave_value_list retval; \
181 if (args.length () != 2 \
182 || args(0).type_name () != "object" \
183 || args(1).type_name () != "object" \
184 || args(0).class_name () != "meta.class" \
185 || args(1).class_name () != "meta.class") \
186 error (#OP ": invalid arguments"); \
188 cdef_class clsa = to_cdef (args(0)); \
190 cdef_class clsb = to_cdef (args(1)); \
192 retval(0) = FCN (CLSA, CLSB); \
209 if (args.length () == 1 && args(0).type_name () ==
"object")
213 retval(0) = prop.
get (
"DefaultValue");
215 if (! retval(0).is_defined ())
217 "no default value for property '%s'",
239 if (args.
length () == 1 && args(0).type_name () ==
"object"
240 && args(0).class_name () ==
"meta.package")
244 retval(0) = pack.get_classes ();
255 if (args.
length () == 0 && args(0).type_name () ==
"object"
256 && args(0).class_name () ==
"meta.package")
260 retval(0) = pack.get_functions ();
271 if (args.
length () == 0 && args(0).type_name () ==
"object"
272 && args(0).class_name () ==
"meta.package")
276 retval(0) = pack.get_packages ();
287 std::map<std::string, cdef_package> toplevel_packages;
295 toplevel_packages[
"meta"] = cdm.
find_package (
"meta",
false,
false);
297 for (
const auto& nm : names)
298 toplevel_packages[nm] = cdm.
find_package (nm,
false,
true);
300 Cell c (toplevel_packages.size (), 1);
304 for (
const auto& nm_pkg : toplevel_packages)
305 c(i++, 0) =
to_ov (nm_pkg.second);
316 error (
"fromName: invalid number of parameters");
318 std::string name = args(0).xstring_value (
"fromName: PACKAGE_NAME must be a string");
326 : m_interpreter (interp), m_all_classes (), m_all_packages (),
327 m_meta_class (), m_meta_property (), m_meta_method (),
328 m_meta_package (), m_meta ()
382 make_fcn_handle (class_get_inferiorclasses,
383 "meta.class>get.InferiorClasses"),
384 "public",
Matrix (),
"private"));
388 make_fcn_handle (class_get_methods,
389 "meta.class>get.Methods"),
390 "public",
Matrix (),
"private"));
394 make_fcn_handle (class_get_methods,
395 "meta.class>get.MethodList"),
396 "public",
Matrix (),
"private"));
402 make_fcn_handle (class_get_properties,
403 "meta.class>get.Properties"),
404 "public",
Matrix (),
"private"));
408 make_fcn_handle (class_get_properties,
409 "meta.class>get.PropertyList"),
410 "public",
Matrix (),
"private"));
416 make_fcn_handle (class_get_superclasses,
417 "meta.class>get.SuperClasses"),
418 "public",
Matrix (),
"private"));
422 make_fcn_handle (class_get_superclasses,
423 "meta.class>get.SuperclassList"),
424 "public",
Matrix (),
"private"));
431 make_fcn_handle (class_get_superclasses,
432 "meta.class>get.SuperclassList"),
433 "public",
Matrix (),
"private"));
437 (
make_method (m_meta_class,
"fromName", class_fromName,
"public",
true));
440 (
make_method (m_meta_class,
"fevalStatic", class_fevalStatic,
"public",
444 (
make_method (m_meta_class,
"getConstant", class_getConstant,
"public",
530 make_fcn_handle (property_get_defaultvalue,
531 "meta.property>get.DefaultValue"),
532 "public",
Matrix (),
"private"));
543 (
make_method (tmp_handle,
"delete", handle_delete));
555 make_fcn_handle (package_get_classes,
556 "meta.package>get.ClassList"),
557 "public",
Matrix (),
"private"));
561 make_fcn_handle (package_get_classes,
562 "meta.package>get.Classes"),
563 "public",
Matrix (),
"private"));
567 make_fcn_handle (package_get_functions,
568 "meta.package>get.FunctionList"),
569 "public",
Matrix (),
"private"));
573 make_fcn_handle (package_get_functions,
574 "meta.package>get.Functions"),
575 "public",
Matrix (),
"private"));
579 make_fcn_handle (package_get_packages,
580 "meta.package>get.PackageList"),
581 "public",
Matrix (),
"private"));
585 make_fcn_handle (package_get_packages,
586 "meta.package>get.Packages"),
587 "public",
Matrix (),
"private"));
590 (
make_method (m_meta_package,
"fromName", package_fromName,
594 (
make_method (m_meta_package,
"getAllPackages", package_getAllPackages,
607 package_meta.
install_class (tmp_meta_dynproperty,
"dynproperty");
636 bool load_if_not_found)
638 auto it = m_all_classes.find (name);
640 if (it == m_all_classes.end ())
642 if (load_if_not_found)
646 std::size_t pos = name.rfind (
'.');
648 if (pos == std::string::npos)
649 ov_cls = m_interpreter.
find (name);
652 std::string pack_name = name.substr (0, pos);
657 ov_cls = pack.
find (name.substr (pos+1));
661 it = m_all_classes.find (name);
665 if (it == m_all_classes.end ())
667 if (error_if_not_found)
668 error (
"class not found: %s", name.c_str ());
680 m_all_classes.erase (it);
688 const std::string& class_name)
705 bool load_if_not_found)
709 std::map<std::string, cdef_package>::const_iterator it
710 = m_all_packages.find (name);
712 if (it != m_all_packages.end ())
717 error (
"invalid package '%s'", name.c_str ());
725 std::size_t pos = name.rfind (
'.');
727 if (pos == std::string::npos)
731 std::string parent_name = name.substr (0, pos);
736 else if (error_if_not_found)
737 error (
"unknown package '%s'", name.c_str ());
756 const std::list<cdef_class>& super_list)
762 cls.
put (
"Abstract",
false);
763 cls.
put (
"ConstructOnLoad",
false);
764 cls.
put (
"ContainingPackage",
Matrix ());
765 cls.
put (
"Description",
"");
766 cls.
put (
"DetailedDescription",
"");
768 cls.
put (
"Hidden",
false);
769 cls.
put (
"InferiorClasses",
Cell ());
771 cls.
put (
"Properties",
Cell ());
772 cls.
put (
"Sealed",
false);
774 if (name ==
"handle")
776 cls.
put (
"HandleCompatible",
true);
779 else if (super_list.empty ())
781 cls.
put (
"HandleCompatible",
false);
785 bool all_handle_compatible =
true;
786 bool has_handle_class =
false;
788 for (
const auto& cl : super_list)
790 all_handle_compatible = all_handle_compatible
791 && cl.get (
"HandleCompatible").bool_value ();
793 has_handle_class = has_handle_class || cl.is_handle_class ();
796 if (has_handle_class && ! all_handle_compatible)
797 error (
"%s: cannot mix handle and non-HandleCompatible classes",
800 cls.
put (
"HandleCompatible", all_handle_compatible);
801 if (has_handle_class)
815 return make_class (name, std::list<cdef_class> (1, super));
824 cls.
put (
"Sealed",
true);
833 const std::string& get_access,
835 const std::string& set_access)
841 prop.
put (
"Description",
"");
842 prop.
put (
"DetailedDescription",
"");
843 prop.
put (
"Abstract",
false);
844 prop.
put (
"Constant",
false);
845 prop.
put (
"GetAccess", get_access);
846 prop.
put (
"SetAccess", set_access);
847 prop.
put (
"Dependent",
false);
848 prop.
put (
"Transient",
false);
849 prop.
put (
"Hidden",
false);
850 prop.
put (
"GetObservable",
false);
851 prop.
put (
"SetObservable",
false);
852 prop.
put (
"GetMethod", get_method);
853 prop.
put (
"SetMethod", set_method);
854 prop.
put (
"DefiningClass",
to_ov (cls));
856 prop.
put (
"HasDefault",
false);
858 std::string class_name = cls.
get_name ();
877 const std::string& m_access,
bool is_static)
883 meth.
put (
"Abstract",
false);
884 meth.
put (
"Access", m_access);
885 meth.
put (
"DefiningClass",
to_ov (cls));
886 meth.
put (
"Description",
"");
887 meth.
put (
"DetailedDescription",
"");
888 meth.
put (
"Hidden",
false);
889 meth.
put (
"Sealed",
true);
890 meth.
put (
"Static", is_static);
906 const std::string& m_access,
bool is_static)
910 return make_method (cls, name, fcn, m_access, is_static);
916 const std::string& m_access,
bool is_static)
920 return make_method (cls, name, fcn, m_access, is_static);
931 pack.
put (
"ContainingPackage",
Matrix ());
943 const std::string& name)
const
950 OCTAVE_END_NAMESPACE(
octave)
#define META_CLASS_CMP(OP, CLSA, CLSB, FCN)
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)
bool is_dummy_method(const octave_value &fcn)
cdef_object to_cdef(const octave_value &val)
std::list< cdef_class > lookup_classes(const Cell &cls_list)
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)
void make_function_of_class(const std::string &class_name, const octave_value &fcn)
cdef_method find_method(const std::string &nm, bool local=false)
void mark_as_meta_class()
void install_property(const cdef_property &prop)
void mark_as_handle_class()
void install_method(const cdef_method &meth)
octave_value get_method(const std::string &nm) const
octave_value get_constructor_function()
std::string get_name() const
cdef_property find_property(const std::string &nm)
const cdef_class & meta_method() const
cdef_class make_class(const std::string &name, const std::list< cdef_class > &super_list=std::list< cdef_class >())
cdef_property make_property(const cdef_class &cls, const std::string &name, const octave_value &get_method=Matrix(), const std::string &get_access="public", const octave_value &set_method=Matrix(), const std::string &set_access="public")
const cdef_class & meta_property() const
octave_value find_method(const std::string &class_name, const std::string &name) const
cdef_package make_package(const std::string &nm, const std::string &parent="")
octave_value find_method_symbol(const std::string &method_name, const std::string &class_name)
cdef_package find_package(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
octave_value find_package_symbol(const std::string &pack_name)
void register_package(const cdef_package &pkg)
const cdef_class & meta_class() const
cdef_class find_class(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
cdef_manager(interpreter &interp)
void register_class(const cdef_class &cls)
cdef_class make_meta_class(const std::string &name, const cdef_class &super)
cdef_method make_method(const cdef_class &cls, const std::string &name, const octave_value &fcn, const std::string &m_access="public", bool is_static=false)
const cdef_class & meta_package() const
cdef_property make_attribute(const cdef_class &cls, const std::string &name)
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
void set_function(const octave_value &fcn)
void mark_as_external(const std::string &dtype)
void put(const std::string &pname, const octave_value &val)
void set_class(const cdef_class &cls)
octave_value get(const std::string &pname) const
void install_class(const cdef_class &cls, const std::string &nm)
octave_value find(const std::string &nm)
std::string get_name() const
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
octave_value find(const std::string &name)
cdef_manager & get_cdef_manager()
type_info & get_type_info()
symbol_table & get_symbol_table()
load_path & get_load_path()
bool find_package(const std::string &package_name) const
std::list< std::string > get_all_package_names(bool only_top_level=true) const
static void register_type()
octave_value_list(* fcn)(const octave_value_list &, int)
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
octave_value_list splice(octave_idx_type offset, octave_idx_type len, const octave_value_list &lst=octave_value_list()) const
octave_idx_type length() const
void install_built_in_function(const std::string &name, const octave_value &fcn)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error_with_id(const char *id, const char *fmt,...)
void() error(const char *fmt,...)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))