diff m-toolbox/classes/+utils/@prog/obj2binary.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/@prog/obj2binary.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,36 @@
+% OBJ2BINARY Converts an object to binary representation
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: Converts an object to binary representation.
+%
+% CALL:        bin = utils.prog.obj2binary(obj)
+%
+% INPUTS:      obj - the object to be converted
+%
+% OUTPUTS:     bin - the converted object
+%
+% VERSION: $Id: obj2binary.m,v 1.2 2010/05/18 18:27:35 nicolodi Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function bin = obj2binary(objs)
+  
+  % get tmp filename
+  fname = [tempname '.mat'];
+  
+  % Convert the objects into a struct if the MATLAB version is less than
+  % R2008b because MATLAB have a internal bug with saving user defined
+  % objects.
+  v = ver('MATLAB');
+  if utils.helper.ver2num(v.Version) < utils.helper.ver2num('7.7')
+    warning('off', 'all')
+    objs  = utils.prog.rstruct(objs);
+    warning('on', 'all')
+  end
+  save(fname, 'objs');
+  
+  fd = fopen(fname, 'r');
+  bin = fread(fd, inf, 'int8=>int8');
+  fclose(fd);
+  delete(fname);  
+end