Mercurial > hg > ltpda
diff m-toolbox/classes/@unit/fromDom.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/@unit/fromDom.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,56 @@ + +function obj = fromDom(obj, node, inhists) + + % There exist two possibilities. + % + % first (only one unit object): + % <parent exps="1" shape="1x1" strs="{'Hz'}" vals="1"/> + % + % second: + % <parent> + % <unit exps="1" shape="1x2" strs="{'Hz'}" vals="1"/> + % <unit exps="1" shape="1x2" strs="{'m'}" vals="1000"/> + % </parent> + + + if node.hasAttribute('shape') + + %%%% first possibility + % Get shape + objShape = utils.xml.getShape(node); + + if any(objShape==0) + + obj = unit.initObjectWithSize(objShape(1), objShape(2)); + + else + + %%%%%%%%%% Call super-class + + fromDom@ltpda_nuo(obj, node, inhists); + + %%%%%%%%%% Get properties from the node attributes + + % Add strs + obj.strs = eval(utils.xml.mchar(node.getAttribute('strs'))); + + % Add exps + obj.exps = eval(utils.xml.mchar(node.getAttribute('exps'))); + + % Add vals + obj.vals = eval(utils.xml.mchar(node.getAttribute('vals'))); + + end + + else + + %%%% second possibility + % If the parent don't have the attribute 'shape' then are the unit + % objects in the child nodes. + + %%%%%%%%%% Get units from child nodes + obj = utils.xml.getObject(node, inhists); + + end + +end