MatrixBerryCore
MapAutoKey.m
Go to the documentation of this file.
1 classdef MapAutoKey<handle
2  properties(Constant,GetAccess=private)
3  MAX_VALUE=intmax('uint64');
4  end
5  properties (Access=private)
6  curCounter=uint64(0);
7  curPrefix='';
8  directPrefix
9  autoPrefix
10  plainMap
11  end
12  properties (Dependent,SetAccess=private,GetAccess=public)
13  Count
14  end
15  methods
16  function nKeys=get.Count(self)
17  nKeys=self.plainMap.Count;
18  end
19  function fullKey=getDirectKey(self,keyStr)
20  fullKey=[self.directPrefix,keyStr];
21  end
22  function isPos=isKey(self,keyStr)
23  isPos=self.plainMap.isKey(keyStr);
24  end
25  function remove(self,keyList)
26  self.plainMap.remove(keyList);
27  end
28  function value=get(self,keyStr)
29  value=self.plainMap(keyStr);
30  end
31  function valueList=values(self)
32  valueList=self.plainMap.values;
33  end
34  function keyList=keys(self)
35  keyList=self.plainMap.keys;
36  end
37  function self=MapAutoKey(varargin)
38  [restArgList,~,self.directPrefix,self.autoPrefix]=...
39  mxberry.core.parseparext(varargin,...
40  {'directPrefix','autoPrefix';
41  '','';
42  'isstring(x)','isstring(x)'});
43  %
44  self.plainMap=containers.Map(restArgList{:});
45  end
46  function putDirect(self,keyStr,value)
47  self.plainMap(self.getDirectKey(keyStr))=value;
48  end
49  function put(self,keyStr,value)
50  self.plainMap(keyStr)=value;
51  end
52  function keyStr=putAuto(self,value)
53  if self.curCounter==self.MAX_VALUE
54  self.curPrefix=[self.curPrefix,'0'];
55  self.curCounter=0;
56  end
57  self.curCounter=self.curCounter+1;
58  keyStr=sprintf('%s%s%u',self.autoPrefix,self.curPrefix,self.curCounter);
59  self.plainMap(keyStr)=value;
60  end
61 
62  end
63 end
function parseparext(in args, in propNameValMat, in varargin)
PARSEPAREXT behaves in the same way as mxberry.core.parseparams but returns property values in a more...