Robochameleon  v1.0
createRoboUnit.m
Go to the documentation of this file.
1 
2 function createRoboUnit(className, version, varargin)
3  if nargin < 1 robolog('A class name must be specified.', 'ERR'); end
4  if nargin < 2 robolog('A class version must be specified.', 'ERR'); end
5  if nargin > 2
6  roboRoot = varargin{1};
7  else
8  roboRoot = getpref('robochameleon','roboRootFolder','NULL');
9  if strcmp(roboRoot,'NULL')
10  robolog('A folder must be specified or "robochameleon" must be run before', 'ERR');
11  end
12  end
13  if ~isnumeric(version)
14  try
15  % If the command is called as 'createRoboUnit MyClassName 1' the version is passed as string
16  version = str2double(version);
17  catch
18  end
19  end
20  if ~isnumeric(version) || version<0 || version/round(version) ~= 1
21  robolog('The version must be an integer positive number', 'ERR');
22  end
23  isOk = regexp(className, '^[a-zA-Z0-9]+$' ,'start');
24  if isempty(isOk)
25  robolog('The class name can only contain the following characters [a-z] [A-Z] [0-9]', 'ERR');
26  end
27  fullClassName = sprintf('%s_v%d', className, version);
28  fullClassName(1) = upper(fullClassName(1));
29  srcFile = sprintf('%s/library/demo/ClassTemplate_v1.m', roboRoot);
30  dstFile = sprintf('./%s.m', fullClassName);
31 
32  s = fileread(srcFile);
33  s = strrep(s, 'ClassTemplate_v1', fullClassName);
34  s = strrep(s, '%', '%%'); %Escape percentage symbol
35  s = strrep(s, '\', '\\'); %Escape escape symbol
36  fid = fopen(dstFile, 'w');
37  fprintf(fid, s);
38  fclose(fid);
39 end
function robolog(in msg, in varargin)
This function allows the user to print log messages in a standard way.
A short description of the class.
function robochameleon(in varargin)
Add robochameleon related directories to the MATLAB path.
function createRoboUnit(in className, in version, in varargin)
Creates a new unit with the given name and version.