mathworks / libmexclass

libmexclass is a MATLAB framework which enables users to implement the functionality of MATLAB classes in terms of equivalent C++ classes using MEX.
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Create a class to represent proxy ids #64

Closed sgilmore10 closed 1 year ago

sgilmore10 commented 1 year ago

libmexclass represents proxy IDs as uint64 values. It would be better if we created a class to represent proxy IDs. Doing so would facilitate creating MATLAB objects from existing proxies.

For example, suppose you have a proxy UInt64Array class that accepts a uint64 vector on construction:

classdef UInt64Array
    properties(Access = private)
         Proxy
    end
    methods
         function obj = UInt64Array(data)
             arguments
                 data(1, :) uint64
              end
              obj.Proxy = libmexclass.proxy.Proxy(Name="UInt64ArrayProxy", ConstructorArguments={data});
         end
    end
end

Right now, what data represents is ambigous. It could be a proxy ID, or it could be a uint64 array from which the user wants to create a proxy. If we represent proxy IDs with a class, this ambiguity goes away:

classdef UInt64Array
    properties(Access = private)
         Proxy
    end
    methods
         function obj = UInt64Array(data)
             arguments
                 data
              end
              if isa(data, "ProxyID")
                  obj.Proxy = libmexclass.proxy.Proxy(Name="UInt64ArrayProxy", ID=data);
             else
                 obj.Proxy = libmexclass.proxy.Proxy(Name="UInt64ArrayProxy", ConstructorArguments={data});
            end
         end
    end
end