Skip to content
Snippets Groups Projects
subsasgn.m 1.28 KiB
Newer Older
function self = subsasgn(self, s, val)
% Subscripted assignment for object Hashtable
% -------------------------------------------

% see help for subsasgn
% ---------------------
switch (length(s))
  case 3
    switch s(3).type
      case '.'
        h = get(self.dynaload, s(1).subs);
        t = get(h, s(2).subs);
        t.(s(3).subs) = val;
        h = put(h, s(2).subs, t);
        self = put(self, s(1).subs, h);
      otherwise
        error('Invalid type.')
    end
  case 2
    switch s(1).type
      case '.'
        if isstruct(val)
          h = get(self.dynaload, s(1).subs);
          h = put(h, s(2).subs, val);
          self = put(self, s(1).subs, h);
        else
          error('value must be a structure');
        end
      otherwise
        error('Invalid type.')
    end
  case 1
    switch s.type
      case '()'
        if (length(s.subs) ~= 1)
          error('Only single indexing is supported.');
        end
        self = put(self, s.subs{1}, val);
      case '.'
        switch s.subs
          case {'autonan', 'autoscale'  }       
            builtin('subsasgn', self, s, val);
          otherwise
            self = put(self, s.subs, val);
        end
      otherwise
        error('Invalid type.')
    end
end