3 properties (Constant,Abstract,GetAccess=
protected)
8 properties (Access=protected,Hidden)
11 isPutErrorIgnored=false
12 isBrokenStoredValuesIgnored=false
20 isMissingKeyBlamed=false
21 isStorageContentChecked=true;
25 function isHashedPath=getIsHashedPath(self)
26 isHashedPath=self.isHashedPath;
28 function isHashedKeys=getIsHashedKeys(self)
29 isHashedKeys=self.isHashedKeys;
35 [~,~,isStorageBranchKeySkipped,storageLocationRoot,...
36 storageBranchKey,self.isPutErrorIgnored,...
37 self.isBrokenStoredValuesIgnored,self.storageFormat,...
38 self.isHashedPath,self.isHashedKeys,...
39 self.isStorageContentChecked,...
40 ~,isStorageLocSpec,isStorageBranchKeySpec]=...
42 {
'skipStorageBranchKey',
'storageLocationRoot',...
43 'storagebranchkey',
'ignoreputerrors',...
44 'ignorebrokenstoredvalues',
'storageformat',...
45 'usehashedpath',
'usehashedkeys',...
46 'checkstoragecontent';...
47 false,char(1,0),
'default',
self.isPutErrorIgnored,...
48 self.isBrokenStoredValuesIgnored,
self.storageFormat,...
49 self.isHashedPath,
self.isHashedKeys,...
50 self.isStorageContentChecked;...
51 'islogscalar(x)',
'isstring(x)',...
52 'isstring(x)',
'islogscalar(x)',...
53 'islogscalar(x)',
'isstring(x)',...
54 'islogscalar(x)',
'islogscalar(x)',...
55 'islogscalar(x)'},[0 1]);
57 if ~isStorageBranchKeySpec
58 storageBranchKey=
'default';
62 storageBranchKey=
mxberry.
core.hash(storageBranchKey);
66 metaClass=metaclass(
self);
67 storageLocationRoot=fileparts(which(metaClass.Name));
71 if isStorageBranchKeySkipped
72 self.storageLocation=storageLocationRoot;
75 self.storageLocation=[storageLocationRoot,
filesep,...
79 self.storageLocationRoot=storageLocationRoot;
81 self.storageBranchKey=storageBranchKey;
83 if ~strcmpi(
self.storageFormat,
'none')
85 %check that a directory if exists, containts only mat files
88 self.checkStorageDir(self.storageLocation);
94 function fullFileName=getFileNameByKey(self,keyStr,varargin)
98 {
'checkForPresence';
true;
'islogical(x)&&isscalar(x)'},0);
99 fullFileName=
self.genfullfilename(keyStr);
100 if isPresenceChecked&&...
101 (~self.isKey(keyStr)&&
self.isMissingKeyBlamed)
103 [
'The specified key %s is not present ',...
104 'in this container, dirName: %s'],keyStr,...
105 fileparts(fullFileName));
109 function [isKeyVec,fullFileNameCVec]=isKey(
self,keyList)
111 if isa(keyList,
'char')
114 fullFileNameCVec=cellfun(@
self.genfullfilename,keyList,...
115 'UniformOutput',
false);
116 isKeyVec=
false(1,length(fullFileNameCVec));
117 nKeys=length(isKeyVec);
120 isKeyVec(iKey)=
self.checkKey(fullFileNameCVec{iKey});
122 if self.isBrokenStoredValuesIgnored
123 throwarn(
'brokenKeyValue',...
124 'a value stored for a specified is broken: %s',...
134 function branchKey=getStorageBranchKey(
self)
135 branchKey=self.storageBranchKey;
138 function storageLocationRoot=getStorageLocationRoot(self)
140 storageLocationRoot=self.storageLocationRoot;
143 function storageLocation=getStorageLocation(self)
145 storageLocation=self.storageLocation;
147 function put(self,keyList,valueObjList,varargin)
149 if ~iscell(valueObjList)
150 valueObjList={valueObjList};
156 isnCellVec=~cellfun(@iscell,varargin);
157 varargin(isnCellVec)=cellfun(@(x){x},varargin(isnCellVec),...
158 'UniformOutput',
false);
160 if ~
mxberry.
core.checksize(keyList,size(valueObjList))
162 'keyList and valueObjList should be of the same size');
165 cellfun(@
self.putOne,keyList,valueObjList,varargin{:});
167 function [valueList,varargout]=
get(
self,keyList,varargin)
170 {
'uniformOutput';
true;@(x)islogical(x)&&isscalar(x)},0);
176 varargout=cell(1,nargout-1);
178 if isUniformOutput&&length(keyList)==1
179 [valueList,varargout{:}]=
self.getOne(keyList{1});
181 [valueList,varargout{:}]=cellfun(...
182 @
self.getOne,keyList,...
183 'UniformOutput',isUniformOutput);
186 function keyList=getKeyList(
self)
187 SFileProp=dir([self.storageLocation,
filesep,...
188 ['*.',self.fileExtension]]);
189 isDirVec=[SFileProp.
isdir];
190 fileNameList={SFileProp(~isDirVec).name};
191 fileNameList=cellfun(@(x)([
self.storageLocation,
filesep,x]),...
192 fileNameList,
'UniformOutput',
false);
194 [~,keyList]=cellfun(@(x)
self.checkKey(x),fileNameList,...
195 'UniformOutput',
false);
197 function remove(
self,keyList)
201 cellfun(@
self.removeOne,keyList,
'UniformOutput',
false);
203 function removeAll(
self)
204 storageLocation=self.getStorageLocation(); %
#ok<*PROP> 205 delete([storageLocation,
filesep,[
'*.',
self.fileExtension]]);
209 methods (Access=
protected)
210 function [isPositive,keyStr]=checkKey(self,fileName)
215 warnState=warning('off','MATLAB:load:variableNotFound');
217 S=self.loadKeyFunc(fileName);
220 'failed to load file %s',fileName);
221 meObj=meObj.addCause(meCauseObj);
224 warning(warnState.state,'MATLAB:load:variableNotFound');
225 isPositive=isfield(S,'keyStr');
231 'key value file is invalid and will be updated');
234 [~,actualFileName]=fileparts(fileName);
235 if ~strcmp(supposedFileName,actualFileName)
237 ['key %s assumes the key value file name to be %s ',...
238 'while the actual file name is %s'],...
239 keyStr,supposedFileName,fileName);
243 function removeOne(self,keyStr)
244 fullFileName=self.genfullfilename(keyStr);
246 delete(fullFileName);
249 function fullFileName=genfullfilename(self,keyStr)
253 'keyStr is expected to be a row-
string');
255 fullFileName=[self.storageLocation,
filesep,...
256 self.
genfilename(keyStr),['.',self.fileExtension]];
258 function putOne(self,keyStr,valueObj)
260 fullFileName=self.genfullfilename(keyStr);
262 self.saveFunc(fullFileName,'valueObj','keyStr');
265 delete(fullFileName);
268 if self.isPutErrorIgnored
270 'cannot save the key value: %s',...
279 function valueObj=getOne(self,keyStr)
281 [isKey,fullFileNameCVec]=self.isKey(keyStr);
284 'The specified key is not present in this container');
286 valueObj=getfield(self.loadValueFunc(fullFileNameCVec{1}),...
287 'valueObj'); %#ok<GFLD>
289 function isPositive=isStorageDir(
self,dirName)
290 SFileList=dir(dirName);
291 isDirVec=[SFileList.isdir];
292 isIgnoredOrAllowedExtVec=
self.isFileExt({SFileList.name},...
293 [
self.IGNORE_EXTENSIONS,
self.ALLOWED_EXTENSIONS]);
294 isPositive=all(isDirVec|isIgnoredOrAllowedExtVec|...
295 ~
self.isStorageContentChecked);
297 function checkStorageDir(
self,dirName)
300 if ~self.isStorageDir(dirName)
302 [
'cannot create a storage at the specified location %s ',...
303 'as it contains some foreign files'],dirName);
307 methods (Access=
protected,Static)
308 function isPositiveVec=isFileExt(fileNameList,extList)
309 regExpStr=strcat(extList,
'|');
310 regExpStr=[regExpStr{:}];
311 regExpStr=[
'\.(',regExpStr(1:end-1),
')$'];
312 isPositiveVec=cellfun(@(x)~isempty(x),regexp(fileNameList,regExpStr));
315 methods (Access=
protected)
322 nChars=length(inpStr);
323 nBlocks=fix(nChars/namelengthmax);
324 blockSizeVec=[
repmat(namelengthmax,1,nBlocks),rem(nChars,namelengthmax)];
325 inpCutStrCVec=mat2cell(inpStr,1,blockSizeVec);
327 inpCutStrCVec=cellfun(@genvarname,inpCutStrCVec,'UniformOutput',false);
328 fileName=[inpCutStrCVec{:}];
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function mkdir(in dirName)
MKDIR creates a directory recursively.
function hash(in inpArr, in methodName)
OBJECTHASH counts the hash of input object/array.
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...
function repmat(in inpArray, in varargin)
function throwwarn(in msgTag, in varargin)
THROWWARN works similarly to built-in WARNING function in case when there is no output arguments but ...
function isdir(in dirName, in isJavaBased)
ISDIR returns true if a specified name corresponds to an existing directory.
DISKBASEDHASHMAP represents a hash map for the arbitrary objects on disk with a high level of persist...
function isfile(in fileName, in isJavaBased)
ISFILE returns true if a specified name corresponds to an existing file.
function genfilename(in inpStr)
GENFILENAME generates a valid file name based on a given string.
function isrow(in inpArray)