Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@helper/classFromStruct.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@helper/classFromStruct.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,46 @@ +% 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 \ No newline at end of file