view m-toolbox/classes/+utils/@prog/struct2obj.m @ 22:b11e88004fca
database-connection-manager
Update collection.fromRepository
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Mon, 05 Dec 2011 16:20:06 +0100 (2011-12-05)
parents
f0afece42f48
children
line source
+ − % STRUCT2OBJ converts the input structure into the given object.
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ − %
+ − % DESCRIPTION: STRUCT2OBJ converts the input structure into the given object.
+ − %
+ − % CALL: obj = struct2obj(s, class)
+ − %
+ − % INPUTS: s - the structure to convert
+ − % class - the class of the object to convert to
+ − %
+ − %
+ − % OUTPUTS: obj - the converted object
+ − %
+ − % VERSION: $Id: struct2obj.m,v 1.2 2008/07/03 18:20:25 ingo Exp $
+ − %
+ − % HISTORY: 09-05-07 M Hewitson
+ − % Creation
+ − %
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ −
+ − function varargout = struct2obj(varargin)
+ −
+ − % Get inputs
+ − if isstruct(varargin{1})
+ − s = varargin{1};
+ − else
+ − error('### Incorrect usage. The first argument should be a structure.');
+ − end
+ − if ischar(varargin{2})
+ − cl = varargin{2};
+ − else
+ − error('### Incorrect usage. The second argument should be a class name (string).');
+ − end
+ −
+ − % Make an empty object
+ − eobj = eval(cl);
+ − % Get the specification of the required type
+ − fnames = fieldnames(eobj);
+ −
+ − % Loop over fields and try to set them from the structure
+ −
+ −
+ − % Set output
+ − varargout{1} = [];