|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Private functions and user objectsHi,
I played a little with Octave 3.1.50, investigating the new user objects features (Windows built) and was wondering a little bit: If a object function is private, i.e. it is stored in an subdirectory named 'private' of the class definition directory (@dirname), octave does not find this function anymore. Example: Directory '@testObj' contains the constructor 'testObj.m' and a function 'fun.m' A subdirectory of '@testObj', named 'private' contains the function 'privFun.m'. 'fun.m' calls only 'privFun.m' in the 'private' subdirectory Test: Create an object: >>x=testObj(<some arguments>) Now, call the private function via fun.m: >>fun(x) Result: Error: privFun.m was not found. Is this only a bug or are private functions not yet provided by octave? Best, Wolfgang |
|
|
Private functions and user objectsOn 22-Jul-2008, WMennerich wrote:
| I played a little with Octave 3.1.50, investigating the new user objects | features | (Windows built) and was wondering a little bit: | If a object function is private, i.e. it is stored in an subdirectory named | 'private' of the class definition directory (@dirname), octave does not find | this function anymore. | | Example: | | Directory '@testObj' contains the constructor 'testObj.m' and a function | 'fun.m' | | | A subdirectory of '@testObj', named 'private' contains the function | 'privFun.m'. | | 'fun.m' calls only 'privFun.m' in the 'private' subdirectory | | Test: | Create an object: | | >>x=testObj(<some arguments>) | | | Now, call the private function via fun.m: | | >>fun(x) | | Result: Error: privFun.m was not found. | | Is this only a bug or are private functions not yet provided by octave? I guess it is a missing feature. I think if you look at load-path.{h,cc} and the symbol_table::fcn_info::fcn_info_rep::find function in symtab.cc, you'll see that private directories that are themselves subdirectories of @ directories aren't considered. This isn't an intentional omission, it's just that this case didn't occur to me when I implemented the new load path and symbol table code. jwe |
|
|
Private functions and user objectsOn 22-Jul-2008, John W. Eaton wrote:
| On 22-Jul-2008, WMennerich wrote: | | | I played a little with Octave 3.1.50, investigating the new user objects | | features | | (Windows built) and was wondering a little bit: | | If a object function is private, i.e. it is stored in an subdirectory named | | 'private' of the class definition directory (@dirname), octave does not find | | this function anymore. | | | | Example: | | | | Directory '@testObj' contains the constructor 'testObj.m' and a function | | 'fun.m' | | | | | | A subdirectory of '@testObj', named 'private' contains the function | | 'privFun.m'. | | | | 'fun.m' calls only 'privFun.m' in the 'private' subdirectory | | | | Test: | | Create an object: | | | | >>x=testObj(<some arguments>) | | | | | | Now, call the private function via fun.m: | | | | >>fun(x) | | | | Result: Error: privFun.m was not found. | | | | Is this only a bug or are private functions not yet provided by octave? | | I guess it is a missing feature. I think if you look at | load-path.{h,cc} and the symbol_table::fcn_info::fcn_info_rep::find | function in symtab.cc, you'll see that private directories that are | themselves subdirectories of @ directories aren't considered. This | isn't an intentional omission, it's just that this case didn't occur | to me when I implemented the new load path and symbol table code. OK, this was not too hard to fix. Please try the attached patch. Thanks, jwe # HG changeset patch # User John W. Eaton <jwe@...> # Date 1216928560 14400 # Node ID dd5cc5016487f81a49b0f17a8127cdabc61a4c6c # Parent b6d4c644b4b61ada8f5f7ede36072a9b64005389 handle private functions in class directories diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,12 @@ 2008-07-24 John W. Eaton <jwe@...> + + * load-path.h (load_path::dir_info::class_info): New struct. + (load_path::dir_info::method_file_map_type): Now a map from + class name to a to a class_info object. Change all uses. + * load-path.cc (load_path::dir_info::get_method_file_map): + Also look for private functions in the class directory. + (load_path::add_to_method_map): Also add private functions from + class directories to private_fcn_map. * dirfns.cc (Fmkdir): If directory already exists, return status = true, but also set error message. diff --git a/src/load-path.cc b/src/load-path.cc --- a/src/load-path.cc +++ b/src/load-path.cc @@ -218,7 +218,14 @@ load_path::dir_info::get_method_file_map (const std::string& d, const std::string& class_name) { - method_file_map[class_name] = get_fcn_files (d); + method_file_map[class_name].method_file_map = get_fcn_files (d); + + std::string pd = file_ops::concat (d, "private"); + + file_stat fs (pd); + + if (fs && fs.is_dir ()) + method_file_map[class_name].private_file_map = get_fcn_files (pd); } bool @@ -1346,7 +1353,9 @@ os << "\n*** methods in " << i->dir_name << "/@" << p->first << ":\n\n"; - string_vector method_files = get_file_list (p->second); + const dir_info::class_info& ci = p->second; + + string_vector method_files = get_file_list (ci.method_file_map); method_files.list_in_columns (os); } @@ -1494,7 +1503,7 @@ { std::string dir_name = di.dir_name; - // <CLASS_NAME, <FCN_NAME, TYPES>> + // <CLASS_NAME, CLASS_INFO> dir_info::method_file_map_type method_file_map = di.method_file_map; for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); @@ -1508,8 +1517,10 @@ std::string full_dir_name = file_ops::concat (dir_name, "@" + class_name); + const dir_info::class_info& ci = q->second; + // <FCN_NAME, TYPES> - const dir_info::fcn_file_map_type& m = q->second; + const dir_info::fcn_file_map_type& m = ci.method_file_map; for (dir_info::const_fcn_file_map_iterator p = m.begin (); p != m.end (); @@ -1549,6 +1560,12 @@ fi.types = types; } } + + // <FCN_NAME, TYPES> + dir_info::fcn_file_map_type private_file_map = ci.private_file_map; + + if (! private_file_map.empty ()) + private_fcn_map[full_dir_name] = private_file_map; } } diff --git a/src/load-path.h b/src/load-path.h --- a/src/load-path.h +++ b/src/load-path.h @@ -233,8 +233,14 @@ typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator; typedef fcn_file_map_type::iterator fcn_file_map_iterator; - // <CLASS_NAME, <FCN_NAME, TYPE>> - typedef std::map<std::string, fcn_file_map_type> method_file_map_type; + struct class_info + { + fcn_file_map_type method_file_map; + fcn_file_map_type private_file_map; + }; + + // <CLASS_NAME, CLASS_INFO> + typedef std::map<std::string, class_info> method_file_map_type; typedef method_file_map_type::const_iterator const_method_file_map_iterator; typedef method_file_map_type::iterator method_file_map_iterator; |
|
|
Re: Private functions and user objectsJohn W. Eaton wrote: > > On 22-Jul-2008, John W. Eaton wrote: > OK, this was not too hard to fix. Please try the attached patch. > I can 'try to try' it: Because Im neigher familiar with git nore with patching sources, this is a bigger thing for me. Also my experience with compiling sources is strong limited. If there is a ready compiled snapshot with this patch available, I would test it and I would also make some other tests since I wrote a Matlab programm using a lot of the objects stuff. I also thought about making this available under the GPL-License, but first, it has to be more completed, bugfixed and documentated. I must also discuss this first with the responsibles. Its not a must for me to use Octave instead of Matlab, but I like the open source idea and offer my help where I can. Best, Wolfgang -- View this message in context: http://www.nabble.com/Private-functions-and-user-objects-tp18587747p18649180.html Sent from the Octave - Maintainers mailing list archive at Nabble.com. |
| Free Forum Powered by Nabble | Forum Help |