2 %
class which wraps an object pointer to an object that is stored somewhere
3 % on the hdd (in a cache)
5 % As the wrapped
object is already stored somewhere, it is not stored
if the
6 %
CacheableObject is stored. Instead only the filename and some consistency
7 % hash are stored on the hdd, from which the wrapped
object can be reliably
8 % restored. (with a consistency check on the data)
12 % the file name where the wrapped
object is stored
15 % a hash computed from the cache file
18 % the pointer to the wrapped
object
21 % the full path to the file where the wrapped
object is stored
30 % At construction time, the #obj attribute is tried to be filled with the
31 % obj stored in
'matfile'.
34 % matfile: a
string specifying the full path or only the file name of
35 % the mat-file where the
object is stored.
36 % fieldname: a
string specifying a fieldname that shall be passed as
37 % second argument to the load method. (@
default = [])
40 matfile = evalin(
'base',
'matfile');
42 if exist(matfile,
'file') || exist([matfile,
'.mat'],
'file')
44 [dummy, matfile, ext] = fileparts(matfile);
46 matp = fullfile(rbmatlabresult, matfile);
48 if ~exist(matp, 'file') && ~exist([matp, '.mat'], 'file')
49 matp = fullfile(rbmatlabresult, '..', matfile);
50 if ~exist(matp, 'file') && ~exist([matp, '.mat'], 'file')
51 [st, matp] = system(['find ', fullfile(rbmatlabresult, '..', '..'), ' -iname ''', matfile, '*'' | head -1']);
52 if ~exist(matp, 'file')
53 error(['could not load file: ', matfile]);
57 if ~exist(matp, 'file')
58 matfile = [matfile, '.mat'];
59 matp = [matp, '.mat'];
62 co.matfile_path = matp;
64 if nargin >= 2 && ~isempty(fieldname)
65 co.obj = load(matp, fieldname);
72 function obj = saveobj(this)
73 % function obj = saveobj(this)
74 % saves all fields except for the
#obj handle
77 % obj:
struct to be stored in file
78 obj.matfile_path = this.matfile_path;
85 methods(Static =
true)
86 function this = loadobj(obj)
87 % function this = loadobj(obj)
91 if ~isequal(obj.md5,
this.md5)
93 error('RBMatlab:
CacheableObject:Consistency', 'Consistency check failed! The stored
object has changed!');
98 methods(Static=true, Access=private)
99 function md5 = compute_hash(matpath)
100 fid=fopen(matpath, 'r');
104 md5 = hash([tmp; uint8(md5)'], 'md5');
matfile
the file name where the wrapped object is stored
class which wraps an object pointer to an object that is stored somewhere on the hdd (in a cache) ...