Mercurial > hg > octave-lyh
comparison libinterp/octave-value/ov-classdef.h @ 16048:10142aad4b9f classdef
Implement indirect method call: fun(obj, ...).
* libinterp/octave-value/ov-classdef.h (class cdef_manager): New class.
(cdef_method::cdef_method_rep::meta_subsref,
cdef_method::cdef_method_rep::meta_is_postfix_index_handled): New
methods.
* libinterp/octave-value/ov-classdef.cc (all_packages, all_classes):
Move static variables to class cdef_manager.
(lookup_class (std::string, bool, bool)): Move implementation to
method cdef_manager::do_find_class().
(lookup_package): Move implementation to method
cdef_manager::do_find_package().
(make_class): Use cdef_manager::register_class.
(make_package): Use cdef_manager::register_package and
cdef_manager::find_package.
(cdef_class::cdef_class_rep::meta_release): Use
cdef_manager::unregister_class.
(cdef_method::cdef_method_rep::meta_subsref): New method.
(class cdef_manager): New class.
* libinterp/interpfcn/symtab.cc
(symbol_table::fcn_info::fcn_info_rep::load_class_constructor):
Look for classdef constructor in normal m-files. Call
find_user_function() and check whether the result is a classdef
constructor. If it is, stash it as a constructor and restore the
previous value of function_on_path.
(symbol_table::fcn_info::fcn_info_rep::load_class_method): Look for
method in classdef system, using cdef_manager::find_method_symbol().
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 11 Feb 2013 15:20:00 -0500 |
parents | 14aa0b5a980c |
children | 7368654f302f |
comparison
equal
deleted
inserted
replaced
15986:14aa0b5a980c | 16048:10142aad4b9f |
---|---|
21 */ | 21 */ |
22 | 22 |
23 #if !defined (octave_classdef_h) | 23 #if !defined (octave_classdef_h) |
24 #define octave_classdef_h 1 | 24 #define octave_classdef_h 1 |
25 | 25 |
26 #include <map> | |
26 #include <set> | 27 #include <set> |
27 #include <string> | 28 #include <string> |
28 | 29 |
29 #include "oct-map.h" | 30 #include "oct-map.h" |
30 #include "oct-refcount.h" | 31 #include "oct-refcount.h" |
1037 bool do_check_access = true, | 1038 bool do_check_access = true, |
1038 const std::string& who = std::string ()); | 1039 const std::string& who = std::string ()); |
1039 | 1040 |
1040 bool is_constructor (void) const; | 1041 bool is_constructor (void) const; |
1041 | 1042 |
1043 octave_value_list | |
1044 meta_subsref (const std::string& type, | |
1045 const std::list<octave_value_list>& idx, int nargout); | |
1046 | |
1047 bool meta_is_postfix_index_handled (char type) const | |
1048 { return (type == '(' || type == '.'); } | |
1049 | |
1042 private: | 1050 private: |
1043 cdef_method_rep (const cdef_method_rep& m) | 1051 cdef_method_rep (const cdef_method_rep& m) |
1044 : cdef_meta_object_rep (m), function (m.function) { } | 1052 : cdef_meta_object_rep (m), function (m.function) { } |
1045 | 1053 |
1046 void check_method (void); | 1054 void check_method (void); |
1458 to_cdef (const cdef_object& obj) | 1466 to_cdef (const cdef_object& obj) |
1459 { return obj; } | 1467 { return obj; } |
1460 | 1468 |
1461 OCTINTERP_API void install_classdef (void); | 1469 OCTINTERP_API void install_classdef (void); |
1462 | 1470 |
1471 class | |
1472 cdef_manager | |
1473 { | |
1474 public: | |
1475 | |
1476 static cdef_class find_class (const std::string& name, | |
1477 bool error_if_not_found = true, | |
1478 bool load_if_not_found = true) | |
1479 { | |
1480 if (instance_ok ()) | |
1481 return instance->do_find_class (name, error_if_not_found, | |
1482 load_if_not_found); | |
1483 | |
1484 return cdef_class (); | |
1485 } | |
1486 | |
1487 static octave_function* find_method_symbol (const std::string& method_name, | |
1488 const std::string& class_name) | |
1489 { | |
1490 if (instance_ok ()) | |
1491 return instance->do_find_method_symbol (method_name, class_name); | |
1492 | |
1493 return 0; | |
1494 } | |
1495 | |
1496 static cdef_package find_package (const std::string& name, | |
1497 bool error_if_not_found = true) | |
1498 { | |
1499 if (instance_ok ()) | |
1500 return instance->do_find_package (name, error_if_not_found); | |
1501 | |
1502 return cdef_package (); | |
1503 } | |
1504 | |
1505 static void register_class (const cdef_class& cls) | |
1506 { | |
1507 if (instance_ok ()) | |
1508 instance->do_register_class (cls); | |
1509 } | |
1510 | |
1511 static void unregister_class (const cdef_class& cls) | |
1512 { | |
1513 if (instance_ok ()) | |
1514 instance->do_unregister_class (cls); | |
1515 } | |
1516 | |
1517 static void register_package (const cdef_package& pkg) | |
1518 { | |
1519 if (instance_ok ()) | |
1520 instance->do_register_package (pkg); | |
1521 } | |
1522 | |
1523 static void unregister_package (const cdef_package& pkg) | |
1524 { | |
1525 if (instance_ok ()) | |
1526 instance->do_unregister_package (pkg); | |
1527 } | |
1528 | |
1529 private: | |
1530 | |
1531 cdef_manager (void) { } | |
1532 | |
1533 cdef_manager (const cdef_manager&); | |
1534 | |
1535 cdef_manager& operator = (const cdef_manager&); | |
1536 | |
1537 ~cdef_manager (void) { } | |
1538 | |
1539 static void create_instance (void); | |
1540 | |
1541 static bool instance_ok (void) | |
1542 { | |
1543 bool retval = true; | |
1544 | |
1545 if (! instance) | |
1546 create_instance (); | |
1547 | |
1548 if (! instance) | |
1549 { | |
1550 ::error ("unable to create cdef_manager!"); | |
1551 | |
1552 retval = false; | |
1553 } | |
1554 | |
1555 return retval; | |
1556 } | |
1557 | |
1558 static void cleanup_instance (void) | |
1559 { | |
1560 delete instance; | |
1561 | |
1562 instance = 0; | |
1563 } | |
1564 | |
1565 cdef_class do_find_class (const std::string& name, bool error_if_not_found, | |
1566 bool load_if_not_found); | |
1567 | |
1568 octave_function* do_find_method_symbol (const std::string& method_name, | |
1569 const std::string& class_name); | |
1570 | |
1571 cdef_package do_find_package (const std::string& name, | |
1572 bool error_if_not_found); | |
1573 | |
1574 void do_register_class (const cdef_class& cls) | |
1575 { all_classes[cls.get_name ()] = cls; } | |
1576 | |
1577 void do_unregister_class (const cdef_class& cls) | |
1578 { all_classes.erase(cls.get_name ()); } | |
1579 | |
1580 void do_register_package (const cdef_package& pkg) | |
1581 { all_packages[pkg.get_name ()] = pkg; } | |
1582 | |
1583 void do_unregister_package (const cdef_package& pkg) | |
1584 { all_packages.erase(pkg.get_name ()); } | |
1585 | |
1586 private: | |
1587 | |
1588 // The single cdef_manager instance | |
1589 static cdef_manager *instance; | |
1590 | |
1591 // All registered/loaded classes | |
1592 std::map<std::string, cdef_class> all_classes; | |
1593 | |
1594 // All registered/loaded packages | |
1595 std::map<std::string, cdef_package> all_packages; | |
1596 }; | |
1597 | |
1463 #endif | 1598 #endif |
1464 | 1599 |
1465 /* | 1600 /* |
1466 ;;; Local Variables: *** | 1601 ;;; Local Variables: *** |
1467 ;;; mode: C++ *** | 1602 ;;; mode: C++ *** |