From: <hi...@us...> - 2009-09-23 12:05:08
|
Revision: 6263 http://octave.svn.sourceforge.net/octave/?rev=6263&view=rev Author: highegg Date: 2009-09-23 12:04:58 +0000 (Wed, 23 Sep 2009) Log Message: ----------- make general/@dict compatible with 3.2.x Modified Paths: -------------- trunk/octave-forge/main/general/inst/@dict/get.m trunk/octave-forge/main/general/inst/@dict/has.m trunk/octave-forge/main/general/inst/@dict/subsasgn.m trunk/octave-forge/main/general/inst/@dict/subsref.m Added Paths: ----------- trunk/octave-forge/main/general/inst/__lookup_compat__.m Modified: trunk/octave-forge/main/general/inst/@dict/get.m =================================================================== --- trunk/octave-forge/main/general/inst/@dict/get.m 2009-09-23 11:14:21 UTC (rev 6262) +++ trunk/octave-forge/main/general/inst/@dict/get.m 2009-09-23 12:04:58 UTC (rev 6263) @@ -30,6 +30,8 @@ print_usage (); endif + lookup = __lookup_compat__; # FIXME: remove when 3.3.x is required. + if (ischar (key)) i = lookup (d.keys, key, "m"); if (i) Modified: trunk/octave-forge/main/general/inst/@dict/has.m =================================================================== --- trunk/octave-forge/main/general/inst/@dict/has.m 2009-09-23 11:14:21 UTC (rev 6262) +++ trunk/octave-forge/main/general/inst/@dict/has.m 2009-09-23 12:04:58 UTC (rev 6263) @@ -29,6 +29,8 @@ print_usage (); endif + lookup = __lookup_compat__; # FIXME: remove when 3.3.x is required. + if (ischar (key) || iscellstr (key)) b = lookup (d.keys, key, "b"); else Modified: trunk/octave-forge/main/general/inst/@dict/subsasgn.m =================================================================== --- trunk/octave-forge/main/general/inst/@dict/subsasgn.m 2009-09-23 11:14:21 UTC (rev 6262) +++ trunk/octave-forge/main/general/inst/@dict/subsasgn.m 2009-09-23 12:04:58 UTC (rev 6263) @@ -24,6 +24,9 @@ if (isempty (s)) error ("dict: missing index"); endif + + lookup = __lookup_compat__; # FIXME: remove when 3.3.x is required. + switch (s(1).type) case "()" ind = s(1).subs; Modified: trunk/octave-forge/main/general/inst/@dict/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@dict/subsref.m 2009-09-23 11:14:21 UTC (rev 6262) +++ trunk/octave-forge/main/general/inst/@dict/subsref.m 2009-09-23 12:04:58 UTC (rev 6263) @@ -25,6 +25,8 @@ error ("dict: missing index"); endif + lookup = __lookup_compat__; # FIXME: remove when 3.3.x is required. + switch (s(1).type) case "()" ind = s(1).subs; Added: trunk/octave-forge/main/general/inst/__lookup_compat__.m =================================================================== --- trunk/octave-forge/main/general/inst/__lookup_compat__.m (rev 0) +++ trunk/octave-forge/main/general/inst/__lookup_compat__.m 2009-09-23 12:04:58 UTC (rev 6263) @@ -0,0 +1,57 @@ +## Copyright (C) 2009 VZLU Prague, a.s., Czech Republic +## +## Author: Jaroslav Hajek <hi...@gm...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## This replaces the missing functionality of "lookup" if on Octave 3.2. + +function lookup_func = __lookup_compat__ () + persistent octave32 = issorted ({version, "3.3.x"}); + if (octave32) + lookup_func = @__my_lookup__; + else + lookup_func = @lookup; + endif +endfunction + +function ind = __my_lookup__ (table, y, opt = "") + + mopt = any (opt == 'm'); + bopt = any (opt == 'b'); + + opt(opt == 'm' | opt == 'b') = []; + + ind = lookup (table, y, opt); + if (numel (table) > 0) + if (ischar (table) || iscellstr (table)) + match = strcmp (table(max (1, ind)), y); + else + match = table(max (1, ind)) == y; + endif + else + match = false (size (y)); + endif + + if (mopt) + ind(! match) = 0; + elseif (bopt) + ind = match; + endif +endfunction + + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |