2%> Return a
copy of the input ``
object``
3%> whose property (or field) values are overwritten
4%> with the corresponding ``(key, val)`` pairs in the
5%> input ``hashmap`` cell array.
8%> This functionality is useful
for converting
9%> the variadic arguments of functions to the
10%> corresponding property values of objects
13%> \param[in] hashmap : The input cell array of even number of elements
14%> containing the field names and values of the input ``
object``
15%> as ``(key, val)`` pairs stored sequentially as the cell elements.<br>
16%> All keys in the input ``hashmap`` must already exist as
17%> fields/properties of the input
object.<br>
18%> \param[in] object : The input scalar MATLAB
struct
19%> or
object whose
property/field values
20%> are to be overwritten with the corresponding
21%> values from the input ``hashmap`` cell.<br>
22%> \param[in] insensitive : The input scalar MATLAB logical.
23%> If ``
false``, then keys within the input ``hashmap`` will be matched
24%> against the input ``
object`` properties(or fields)
case-sensitively.<br>
25%> (**optional**,
default = ``
false``)
26%> \param[in] extensible : The input scalar MATLAB logical.<br>
27%> If ``
true``, then keys in the input ``hashmap`` that are missing in the
28%> input ``
object`` properties(or fields) will be added to output ``objnew``.<br>
29%> This functionality
requires the input ``
object`` to be either a MATLAB ``
struct``
30%> or an
object whose ultimate superclass is the MATLAB ``handle``
class,
31%>
which allows adding
new properties via ``addprop()`` method.<br>
32%> (**optional**,
default = ``
false``)
33%> \param[in] recursive : The input scalar MATLAB logical.<br>
34%> If ``
true``, then key-val pairs in the input ``hashmap`` that match
struct-cell
35%> or match
object-cell pattern will be also converted recursively like the parent
36%> input ``
object`` until all sub-components are obtained recursively.<br>
37%> (**optional**,
default = ``
false``)
40%> objnew : The output
copy of the input
object whose
41%>
property/field values are overwritten with the
42%> corresponding values from the input ``hashmap`` cell.<br>
47%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object)
48%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [])
49%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [], [])
50%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [], [], [])
51%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [], [], recursive)
52%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [], extensible, [])
53%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, insensitive, [], [])
54%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, [], extensible, recursive)
55%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, insensitive, [], recursive)
56%> objnew = pm.matlab.hashmap.hash2comp(hashmap,
object, insensitive, extensible, recursive)
61%> \include{lineno} example/matlab/hashmap/
hash2comp/main.m
63%> \include{lineno} example/matlab/hashmap/
hash2comp/main.out.m
68%> \JoshuaOsborne, May 21 2024, 10:47 PM, University of Texas at Arlington<br>
69%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
70%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
71function objnew =
hash2comp(hashmap,
object, insensitive, extensible, recursive)
73 hashmapLen = length(hashmap);
74 if rem(hashmapLen, 2) ~= 0
75 help(
"pm.matlab.hashmap.hash2comp");
76 disp(
"length(hashmap)");
77 disp( length(hashmap) );
79 +
"The input argument ``hashmap`` must be a cell array of even length." + newline ...
80 +
"For more information, see the documentation displayed above." + newline ...
85 fieldList = properties(objnew);
86 fieldListLen = length(fieldList);
88 fieldList = fieldnames(objnew);
89 fieldListLen = length(fieldList);
100 if isempty(recursive)
103 if isempty(extensible)
106 if isempty(insensitive)
109 for i = 1 : 2 : hashmapLen
111 key = string(hashmap{i});
112 for ip = 1 : fieldListLen
114 keyfound = strcmp(key,
string(fieldList(ip)));
116 keyfound = strcmpi(key,
string(fieldList(ip)));
126 +
"The requested ``object`` property:" + newline ...
128 + pm.io.tab +
"""" +
string(hashmap{i}) +
"""" + newline ...
130 +
"does not exist in the specified input ``object``." + newline ...
133 elseif ~isstruct(objnew)
137 if recursive && isa(hashmap{i + 1},
"cell") && (isa(objnew.(key),
"struct") || isa(objnew.(key),
"handle") || ~isempty(properties(objnew.(key))))
138 objnew.(key) = pm.matlab.hashmap.hash2comp(hashmap{i + 1}, objnew.(key), insensitive, extensible, recursive);
140 objnew.(key) = hashmap{i + 1};
function copy(in from, in to, in field, in exclude)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function hash2comp(in hashmap, in object, in insensitive, in extensible, in recursive)
Return a copy of the input object whose property (or field) values are overwritten with the correspon...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...