Skip to content

Commit

Permalink
Merge pull request #89 from mpsonntag/fixSecVal
Browse files Browse the repository at this point in the history
enablePropertiesMap
  • Loading branch information
asobolev committed Jun 19, 2015
2 parents 7d5be24 + 5bc00b2 commit b4e0e45
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
31 changes: 16 additions & 15 deletions +nix/Section.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

properties(Dependent)
allProperties
%allPropertiesMap
allPropertiesMap
end;

methods
Expand Down Expand Up @@ -122,25 +122,26 @@
end;

function props = get.allProperties(obj)
%-- if a value in a property is updated, this will not
%-- update the lastUpdate of the propertyCache of
%-- a loaded section. Therefore caching of the properties
%-- of a section is disabled by always resetting the lastUpdate
obj.propsCache.lastUpdate = 0;

[obj.propsCache, props] = nix.Utils.fetchPropList(obj.updatedAt, ...
'Section::properties', obj.nix_handle, obj.propsCache);
end

%-- values has been removed from section.properties due to
%-- stale entries in the section.properties cache when the acutal
%-- properties values are updated. therefore the current mapping
%-- function cannot be used at the moment.
%-- could be refactored at a later moment in time
%function p_map = get.allPropertiesMap(obj)
% p_map = containers.Map();
% props = obj.allProperties;

% for i=1:length(props)
% p_map(props{i}.name) = cell2mat(props{i}.values);
% end
%end
function p_map = get.allPropertiesMap(obj)
p_map = containers.Map();
props = obj.allProperties;

for i=1:length(props)
p_map(props{i}.name) = cell2mat(props{i}.values);
end
end

end

end

6 changes: 5 additions & 1 deletion src/nixsection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ void properties(const extractor &input, infusor &output)
for (size_t i = 0; i < properties.size(); i++) {

nix::Property pr = properties[i];
std::vector<nix::Value> values = pr.values();

mxArray *mx_values = make_mx_array(values);

struct_builder sb({ 1 }, {
"name", "id", "definition", "mapping", "unit"
"name", "id", "definition", "mapping", "unit", "values"
});

sb.set(pr.name());
sb.set(pr.id());
sb.set(pr.definition());
sb.set(pr.mapping());
sb.set(pr.unit());
sb.set(mx_values);

mxSetCell(lst, i, sb.array());
}
Expand Down
7 changes: 7 additions & 0 deletions tests/TestSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@

tmp = s.create_property_with_value('doubleProperty1', [5, 6, 7, 8]);
assert(strcmp(s.allProperties{end}.name, 'doubleProperty1'));
assert(s.allProperties{end}.values{1} == 5);
assert(size(s.allProperties{end}.values, 2) == 4);
assert(s.open_property(s.allProperties{end}.id).values{1}.value == 5);
assert(size(s.open_property(s.allProperties{end}.id).values, 1) == 4);
assert(strcmpi(tmp.datatype,'double'));
Expand All @@ -176,12 +178,17 @@

tmp = s.create_property_with_value('stringProperty2', {'this', 'has', 'strings'});
assert(strcmp(s.allProperties{end}.name, 'stringProperty2'));
assert(strcmp(s.allProperties{end}.values{1}, 'this'));
assert(size(s.allProperties{end}.values, 2) == 3);
assert(strcmp(s.open_property(s.allProperties{end}.id).values{1}.value, 'this'));
assert(size(s.open_property(s.allProperties{end}.id).values, 1) == 3);
assert(strcmpi(tmp.datatype, 'char'));

tmp = s.create_property_with_value('booleanProperty1', [true, false, true]);
assert(strcmp(s.allProperties{end}.name, 'booleanProperty1'));
assert(s.allProperties{end}.values{1});
assert(~s.allProperties{end}.values{2});
assert(size(s.allProperties{end}.values, 2) == 3);
assert(s.open_property(s.allProperties{end}.id).values{1}.value);
assert(~s.open_property(s.allProperties{end}.id).values{2}.value);
assert(size(s.open_property(s.allProperties{end}.id).values, 1) == 3);
Expand Down

0 comments on commit b4e0e45

Please sign in to comment.