comparison Map.m @ 415:16907bf31e67 feature/better_map

Overload indexing operations.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 02 Feb 2017 16:22:47 +0100
parents 50fd7e88aa74
children e97550b5c1e7
comparison
equal deleted inserted replaced
414:50fd7e88aa74 415:16907bf31e67
52 end 52 end
53 53
54 function c = values(obj) 54 function c = values(obj)
55 c = obj.map.values; 55 c = obj.map.values;
56 end 56 end
57
58 function v = subsref(obj, S)
59 switch S.type
60 case '()'
61 k = S.subs;
62 try
63 v = obj.get(k);
64 catch ME
65 if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey')
66 error('Reference to non-existent entry %s',toString(S.subs));
67 else
68 throw(ME);
69 end
70 end
71 otherwise
72 v = builtin('subsref', obj, S);
73 end
74 end
75
76 function obj = subsasgn(obj, S, v);
77 switch S.type
78 case '()'
79 k = S.subs;
80 obj.set(k, v);
81 otherwise
82 error('Unsupported indexing operator: %s',S.type);
83 end
84 end
57 end 85 end
58 end 86 end