MatrixBerryCore
HashMapMatXML.m
Go to the documentation of this file.
1 classdef HashMapMatXML<mxberry.core.cont.ondisk.AHashMap
2 
3  properties (Constant,GetAccess=protected)
4  MAT_EXTENSION='mat';
5  XML_EXTENSION='xml';
6  IGNORE_EXTENSIONS={'asv','xml~'};
7  ALLOWED_EXTENSIONS={'mat','xml'};
8  end
9  methods
10  function self=HashMapMatXML(varargin)
12  import mxberry.core.throwerror;
13  import mxberry.xml.*;
14  import mxberry.core.parseparext;
15  %
16  self=self@mxberry.core.cont.ondisk.AHashMap(varargin{:});
17  %
18  [~,~,self.storageFormat]=parseparext(varargin,...
19  {'storageFormat';self.storageFormat;'isstring(x)'});
20  %
21  switch lower(self.storageFormat)
22  case 'mat'
23  self.saveFunc=@save;
24  self.loadKeyFunc=@(x)load(x,'keyStr');
25  self.loadValueFunc=@(x)load(x,'valueObj');
26  self.fileExtension=self.MAT_EXTENSION;
27  self.isMissingKeyBlamed=true;
28  case 'xml'
29  self.saveFunc=@(x,y,z)xmlsave(x,...
30  struct(...
31  'valueObj',{evalin('caller',y)},...
32  'keyStr',{evalin('caller',z)}),...
33  'on');
34  self.loadKeyFunc=@xmlload;
35  self.loadValueFunc=@xmlload;
36  self.fileExtension=self.XML_EXTENSION;
37  self.isMissingKeyBlamed=true;
38  case 'none'
39  otherwise
40  throwerror('wrongInput','unknown storage format');
41  end
42  end
43  %
44  end
45  methods (Access=protected)
46  function valueObj=getOne(self,keyStr)
47  import mxberry.core.throwerror;
48  WARN_TO_CATCH='badMatFile:wrongState';
49  lastwarn('');
50  valueObj=getOne@mxberry.core.cont.ondisk.AHashMap(self,keyStr);
51  [lastWarnMsg,lastWarnId]=lastwarn();
52  nChars=length(WARN_TO_CATCH);
53  nWarnChars=length(lastWarnId);
54  indStart=max(1,nWarnChars-nChars)+1;
55  if strcmp(lastWarnId(indStart:end),WARN_TO_CATCH)
56  throwerror('wrongState',lastWarnMsg);
57  end
58  end
59  function [isPositive,keyStr]=checkKey(self,fileName)
60  isPositive=mxberry.io.isfile(fileName);
61  if ~((strcmp(self.fileExtension,self.XML_EXTENSION))&&...
62  (nargout<2))
63  if isPositive
64  [isPositive,keyStr]=...
65  checkKey@mxberry.core.cont.ondisk.AHashMap(...
66  self,fileName);
67  end
68  end
69  end
70  end
71 end
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 xmlload(in fileName)
XMLLOAD loads XML file and converts it into Matlab structure or variable.
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...
DISKBASEDHASHMAP represents a hash map for the arbitrary objects on disk with a high level of persist...
Definition: AHashMap.m:6
function xmlsave(in fileName, in SData, in varargin)
XMLSAVE saves structure or variable(s) to a file using XML format.
function isfile(in fileName, in isJavaBased)
ISFILE returns true if a specified name corresponds to an existing file.