Initial commit
[pftoolbox.git] / expressions / @xlinear / set.m
blobbc2afa8b60d2c1012cf58c49e1ed45ff69861539
1 function objout = set(obj,varargin)\r
2 % Sets the properties of an object.\r
3 %\r
4 % set(obj, 'propertyname', value) sets the property 'propertyname' of the object 'obj'\r
5 % to the value 'value'. \r
6 %\r
7 % An equivalent syntax is obj.propertyname = value.\r
8 %\r
9 % set(obj, 'property1', value1, 'property2', value2, ...) sets multiple property values.\r
10 % set(obj, 'property') displays legitimate values for the specified property of 'obj'.\r
11 % set(obj) displays all properties of 'obj' and their admissible values.\r
12 %\r
13 % If an output argument is specified, the modified object will be assigned to this and\r
14 % no modifications will be done to the input object.\r
15 %\r
16 % Type 'props(obj)' for more details on the properties of the object 'obj'.\r
18 % Toolbox for nonlinear filtering.\r
19 % Copyright (C) 2005  Jakob Rosén <jakob.rosen@gmail.com>\r
20 %\r
21 % This program is free software; you can redistribute it and/or\r
22 % modify it under the terms of the GNU General Public License\r
23 % as published by the Free Software Foundation; either version 2\r
24 % of the License, or (at your option) any later version.\r
25 %\r
26 % This program is distributed in the hope that it will be useful,\r
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of\r
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
29 % GNU General Public License for more details.\r
30 %\r
31 % You should have received a copy of the GNU General Public License\r
32 % along with this program; if not, write to the Free Software\r
33 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
35 if nargin==1\r
36         % Only 'obj' is supplied. Display the list of properties.\r
37         displayprops(obj);\r
38 elseif nargin==2;\r
39         % A parameter was given, but no value. Display information about the property.\r
40         prop_name = varargin{1};\r
41         [props,rprops]=pnames;\r
42         if findcstr(props,prop_name)||findcstr(rprops,prop_name)\r
43                 disp(pformat(get(obj,prop_name)));\r
44         else\r
45                 error('Unknown property');\r
46         end\r
47 else\r
48         if isempty(inputname(1))&&nargout<1\r
49                 error('The first argument must be a named variable if no output argument is given.')\r
50         elseif rem(nargin-1,2)~=0,\r
51                 error('Property/value pairs must come in even number.')\r
52         end\r
54         property_argin = varargin;\r
55         while length(property_argin) >= 2,\r
56                 prop_name = property_argin{1};\r
57                 v = property_argin{2};\r
58                 property_argin = property_argin(3:end);\r
59                 switch prop_name\r
61                 % <custom>\r
62                 % Here we handle properties that need custom treatment (or need to be \r
63                 % processed really fast)\r
65                 case {'varsize'}\r
66                         if size(v,1)~=1||size(v,2)~=4\r
67                                 error('''varsize'' must be a row vector of size 4.');\r
68                         end\r
69                         obj.varsize=v;\r
71                 case {'expression'}\r
72                         obj.expression=v;\r
73                         obj.str=expr2str(v);\r
74                 case {'str'}\r
75                         expr=str2expr(v);\r
76                         obj.expression=expr;\r
77                         obj.str=expr2str(expr);\r
79                 % </custom>\r
81                 otherwise\r
82                         [props,rprops]=pnames;\r
83                         if findcstr(props,prop_name)\r
84                                 eval(strcat('obj.',prop_name,'=v;'));\r
85                         elseif findcstr(rprops,prop_name)\r
86                                 error([prop_name,' is a read-only property'])\r
87                         else\r
88                                 error([prop_name,' is not a valid property'])\r
89                         end\r
90                 end\r
91         end\r
93         if nargout==0\r
94                 % No output variable was specified by the user.\r
95                 % We'll do the assignment manually in the caller's workspace.\r
96                 objname = inputname(1);\r
97                 assignin('caller',objname,obj)\r
98         else\r
99                 objout=obj;\r
100         end;\r
101 end\r