view Map.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents effd75b113ba
children a6c5e73ff44e
line wrap: on
line source

classdef Map < handle
    properties
        map
    end

    % can we support multi map using varargin?
    % probably a bad idea. For example it complicates keys();

    methods
        function obj = Map()
            obj.map = containers.Map();
        end

        function set(obj, k, v)
            keyByteStream = getByteStreamFromArray(k);

            obj.map(char(keyByteStream)) = v;
        end

        function v = get(obj, k)
            keyByteStream = getByteStreamFromArray(k);

            v = obj.map(char(keyByteStream));
        end

        function b = isKey(obj, k)
            keyByteStream = getByteStreamFromArray(k);
            b = obj.map.isKey(char(keyByteStream));
        end

        function c = keys(obj)
            keyByteStreams = obj.map.keys;

            n = length(keyByteStreams);

            c = cell(1, n);
            for i = 1:n
                c{i} = getArrayFromByteStream(uint8(keyByteStreams{i}));
            end
        end

        function l = length(obj)
            l = obj.map.length;
        end

        function remove(obj, k)
            keyByteStream = getByteStreamFromArray(k);
            obj.map.remove(char(keyByteStream));
        end

        function s = size(obj)
            s = obj.map.size;
        end

        function c = values(obj)
            c = obj.map.values;
        end

        function v = subsref(obj, S)
            switch S(1).type
                case '()'
                    k = S.subs{1};
                    try
                        v = get(obj, k);
                    catch ME
                        if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey')
                            error('Reference to non-existent entry %s',toString(S.subs));
                        else
                            throw(ME);
                        end
                    end
                otherwise
                    try
                        v = builtin('subsref', obj, S);
                    catch e
                        error('You can''t use dot notation for this because Matlab(TM). What is this piece of shit software anyway?')
                    end
            end
        end

        function obj = subsasgn(obj, S, v);
            switch S(1).type
                case '()'
                    k = S.subs{1};
                    set(obj, k, v);
                otherwise
                    error('You can''t use dot notation because Matlab(TM). What is this piece of shit software anyway?')
            end
        end
    end
end