view m-toolbox/classes/+utils/@helper/classFromStruct.m @ 44:409a22968d5e
default
Add unit tests
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Tue, 06 Dec 2011 18:42:11 +0100 (2011-12-06)
parents
f0afece42f48
children
line source
+ − % CLASSFROMSTRUCT returns a class name that matches the structure.
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ − %
+ − % DESCRIPTION: CLASSFROMSTRUCT returns a class name that matches the
+ − % structure.
+ − %
+ − % CALL: class_name = classFromStruct(struct)
+ − %
+ − % If structure does not match any of the LTPDA classes, then 'class_name'
+ − % will be empty.
+ − %
+ − % INPUTS: struct: Structure which should be checked
+ − %
+ − % OUTPUTS: class_name: Class name.
+ − %
+ − % VERSION: $Id: classFromStruct.m,v 1.2 2009/07/22 14:45:17 ingo Exp $
+ − %
+ − % HISTORY: 08-09-08 M Hewitson
+ − % Creation
+ − %
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ −
+ − function varargout = classFromStruct(varargin)
+ −
+ − if nargin < 1
+ − error('### Unknown number of inputs.%s### Please use: classFromStruct(struct)', char(10))
+ − end
+ −
+ − obj_struct = varargin{1};
+ − class_name = '';
+ − % we must determine the class from the fieldnames
+ − cls = utils.helper.ltpda_non_abstract_classes;
+ − snames = fieldnames(obj_struct);
+ − for jj=1:numel(cls)
+ − cl = cls{jj};
+ − cnames = properties(cl);
+ − if numel(cnames) == numel(snames)&& all(strcmp(snames, cnames))
+ − class_name = cl;
+ − break;
+ − end
+ − end
+ −
+ − % Set output
+ − varargout{1} = class_name;
+ −
+ − end