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
67%> Is the last condition ``~isempty(properties(objnew.(key)))`` in the implementation of
this procedure necessary?<br>
68%> Its presence contradicts the function behavior at the zeroth level of iteration and subsequent iterations.<br>
69%> This issue must be addressed as soon as the correction is
verified to not change the behavior of other
70%> functions calling
this function.<br>
75%> \JoshuaOsborne, May 21 2024, 10:47 PM, University of Texas at Arlington<br>
76%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
77%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
78function objnew =
hash2comp(hashmap,
object, insensitive, extensible, recursive)
80 hashmapLen = length(hashmap);
81 if rem(hashmapLen, 2) ~= 0
82 help(
"pm.matlab.hashmap.hash2comp");
83 disp(
"length(hashmap)");
84 disp( length(hashmap) );
86 +
"The input argument ``hashmap`` must be a cell array of even length." + newline ...
87 +
"For more information, see the documentation displayed above." + newline ...
92 fieldList = properties(objnew);
93 fieldListLen = length(fieldList);
95 fieldList = fieldnames(objnew);
96 fieldListLen = length(fieldList);
107 if isempty(recursive)
110 if isempty(extensible)
113 if isempty(insensitive)
116 for i = 1 : 2 : hashmapLen
118 key = string(hashmap{i});
119 for ip = 1 : fieldListLen
121 keyfound = strcmp(key,
string(fieldList(ip)));
123 keyfound = strcmpi(key,
string(fieldList(ip)));
133 +
"The requested ``object`` property:" + newline ...
135 + pm.io.tab() +
"""" +
string(hashmap{i}) +
"""" + newline ...
137 +
"does not exist in the specified input ``object``." + newline ...
140 elseif ~isstruct(objnew)
145 % Is the last condition ``~isempty(properties(objnew.(key)))`` necessary?
146 % Its presence contradicts the function behavior at the zeroth level of iteration and subsequent iterations.
147 % This issue must be addressed as soon as it is clear the correction does not change the behavior of other
148 % functions calling
this function.
149 if recursive && isa(hashmap{i + 1},
"cell") && (isa(objnew.(key),
"struct") || isa(objnew.(key),
"handle") || ~isempty(properties(objnew.(key))))
150 objnew.(key) = pm.matlab.hashmap.hash2comp(hashmap{i + 1}, objnew.(key), insensitive, extensible, recursive);
152 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 verified(in varval, in vartype, in maxlen)
Return true if and only if the input varval conforms with the specified input type vartype and maximu...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...