Mercurial > repos > public > sbplib
comparison Map.m @ 417:effd75b113ba feature/better_map
Add tests and fix a bunch of bugs.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 02 Feb 2017 20:49:06 +0100 |
parents | e97550b5c1e7 |
children | a6c5e73ff44e |
comparison
equal
deleted
inserted
replaced
416:e97550b5c1e7 | 417:effd75b113ba |
---|---|
6 % can we support multi map using varargin? | 6 % can we support multi map using varargin? |
7 % probably a bad idea. For example it complicates keys(); | 7 % probably a bad idea. For example it complicates keys(); |
8 | 8 |
9 methods | 9 methods |
10 function obj = Map() | 10 function obj = Map() |
11 obj.map = containers.Map() | 11 obj.map = containers.Map(); |
12 end | 12 end |
13 | 13 |
14 function set(obj, k, v) | 14 function set(obj, k, v) |
15 keyByteStream = getByteStreamFromArray(k); | 15 keyByteStream = getByteStreamFromArray(k); |
16 | 16 |
23 v = obj.map(char(keyByteStream)); | 23 v = obj.map(char(keyByteStream)); |
24 end | 24 end |
25 | 25 |
26 function b = isKey(obj, k) | 26 function b = isKey(obj, k) |
27 keyByteStream = getByteStreamFromArray(k); | 27 keyByteStream = getByteStreamFromArray(k); |
28 b = obj.map.isKey(keyByteStream); | 28 b = obj.map.isKey(char(keyByteStream)); |
29 end | 29 end |
30 | 30 |
31 function c = keys(obj) | 31 function c = keys(obj) |
32 keyByteStreams = obj.map.keys; | 32 keyByteStreams = obj.map.keys; |
33 | 33 |
55 function c = values(obj) | 55 function c = values(obj) |
56 c = obj.map.values; | 56 c = obj.map.values; |
57 end | 57 end |
58 | 58 |
59 function v = subsref(obj, S) | 59 function v = subsref(obj, S) |
60 switch S.type | 60 switch S(1).type |
61 case '()' | 61 case '()' |
62 k = S.subs; | 62 k = S.subs{1}; |
63 try | 63 try |
64 v = obj.get(k); | 64 v = get(obj, k); |
65 catch ME | 65 catch ME |
66 if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey') | 66 if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey') |
67 error('Reference to non-existent entry %s',toString(S.subs)); | 67 error('Reference to non-existent entry %s',toString(S.subs)); |
68 else | 68 else |
69 throw(ME); | 69 throw(ME); |
70 end | 70 end |
71 end | 71 end |
72 otherwise | 72 otherwise |
73 v = builtin('subsref', obj, S); | 73 try |
74 v = builtin('subsref', obj, S); | |
75 catch e | |
76 error('You can''t use dot notation for this because Matlab(TM). What is this piece of shit software anyway?') | |
77 end | |
74 end | 78 end |
75 end | 79 end |
76 | 80 |
77 function obj = subsasgn(obj, S, v); | 81 function obj = subsasgn(obj, S, v); |
78 switch S.type | 82 switch S(1).type |
79 case '()' | 83 case '()' |
80 k = S.subs; | 84 k = S.subs{1}; |
81 obj.set(k, v); | 85 set(obj, k, v); |
82 otherwise | 86 otherwise |
83 error('Unsupported indexing operator: %s',S.type); | 87 error('You can''t use dot notation because Matlab(TM). What is this piece of shit software anyway?') |
84 end | 88 end |
85 end | 89 end |
86 end | 90 end |
87 end | 91 end |