KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Dictionary.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
18  :public handle {
68  private:
69 
70  List;
78  public: /* ( Dependent ) */
79 
119  public: /* ( Dependent ) */
120 
122  this.List= struct(" Key ",[]," Value ",[]);
123  }
130  function set(char key,any value) {
131  this.set_(key, value);
132  }
143  function value = get(char key) {
144  value = this.get_(key);
145  }
156  function clear(key) {
157  if nargin == 2
158  cidx = [];
159  for i=1:length(this.List)
160  if strcmp(this.List(i).Key,key)
161  cidx = i;
162  end
163  end
164  if ~isempty(cidx)
165  this.List(cidx) = [];
166  end
167  else
168  this.List= struct(" Key ",[]," Value ",[]);
169  end
170  }
182  function bool = containsKey(char key) {
183  if ~isa(key," char ")
184  error(" Key must be a string. ");
185  end
186  bool = false;
187  for i=1:length(this.List)
188  if strcmp(this.List(i).Key,key)
189  bool = true;
190  return;
191  end
192  end
193  }
203  function varargout = subsref(key) {
204  if (isequal(key(1).type," () "))
205  varargout[1] = this.get_(key(1).subs[1]);
206  if length(key) > 1
207  [varargout[1:nargout]] = builtin(" subsref ", varargout, key(2:end));
208  end
209  else
210  [varargout[1:nargout]] = builtin(" subsref ", this, key);
211  end
212  }
223  function this = subsasgn(key,value) {
224  if (isequal(key(1).type," () "))
225  if length(key) > 1
226  value = builtin(" subsasgn ", this.get_(key(1).subs[1]), key(2:end), value);
227  end
228  this.set_(key(1).subs[1], value);
229  else
230  builtin(" subsasgn ", this, key, value);
231  end
232  }
244 #if 0 //mtoc++: 'get.Count'
245 function c = Count() {
246  c = length(this.List);
247  }
248 
249 #endif
250 
251 
252 
253 #if 0 //mtoc++: 'get.Keys'
254 function k = Keys() {
255  k = [this.List(:).Key];
256  }
257 
258 #endif
259 
260 
261 
262 #if 0 //mtoc++: 'get.Values'
263 function k = Values() {
264  k = [this.List(:).Value];
265  }
266 
267 #endif
268 
269 
270  function display() {
271  fprintf(" Dictionary with %d elements.\n ",this.Count);
272  arrayfun(@(kv)(disp([" Key: " kv.Key " Value: " kv.Value])),this.List);
273  }
281  private: /* ( Dependent ) */
282 
283  function value = get_(key) {
284  value = [];
285  if isempty(key)
286  return;
287  end
288  if isa(key, " char ")
289  for i=1:length(this.List)
290  if isequal(this.List(i).Key,key)
291  /* Return found value */
292  value = this.List(i).Value;
293  break;
294  end
295  end
296  return;
297  elseif isposintscalar(key)
298  if key < 1 || key > this.Count
299  error(" Key index exceeds dictionary. ");
300  end
301  value = this.List(key).Value;
302  return;
303  end
304  error(" The key must be a string or integer ");
305  }
314  function set_(key,value) {
315  if isa(key, " char ")
316  for i=1:length(this.List)
317  if isequal(this.List(i).Key,key)
318  /* Set value if already in list */
319  this.List(i).Value = value;
320  return;
321  end
322  end
323  /* Otherwise: Extend! */
324  this.List(end+1).Key = key;
325  this.List(end).Value = value;
326  elseif isposintscalar(key)
327  if key < 1 || key > this.Count
328  error(" Setting per numerical index only allowed within existing items; use a char key for automatic insertions. ");
329  end
330  this.List(key).Value = value;
331  return;
332  end
333  }
358 };
359 
360 
361 
function this = subsasgn(key, value)
Implements subscripted assignment.
Definition: Dictionary.m:223
function set(char key,any value)
Sets the dictionary entry for key key to value value The keys are unique, so if a key already exists ...
Definition: Dictionary.m:130
cell Keys
The keys used in the dictionary. Readonly.
Definition: Dictionary.m:80
function clear(key)
Clears the dictionary or the contents for a specific key, if given.
Definition: Dictionary.m:156
A MatLab cell array or matrix.
Dictionary()
Creates a new empty dictionary.
Definition: Dictionary.m:121
integer Count
The size of the dictionary. Readonly.
Definition: Dictionary.m:106
An integer value.
Matlab's base handle class (documentation generation substitute)
A basic dictionary of key/value pairs for small to medium amounts of data.
Definition: Dictionary.m:17
disp
Handle object disp method which is called by the display method. See the MATLAB disp function...
cell Values
The values used in the dictionary. Readonly.
Definition: Dictionary.m:93
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
function display()
Overrides the default display method in MatLab and prints a list of keys and values inside the dictio...
Definition: Dictionary.m:270
function varargout = subsref(key)
Implements subscripted value retrieval.
Definition: Dictionary.m:203
A MatLab character array.
function bool = containsKey(char key)
Checks if the dictionary contains the key key.
Definition: Dictionary.m:182
A variable number of output arguments.