create stack object [USAGE] [obj] = vb_stack_new([stack_size][,stack_type]); [IN] stack_size : stack buffer size.(default: unlimit) stack_type : 'M', 'm' : stack buffers on memory.(default) 'F', 'f' : stack buffers on MATLAB-tempfile. MATLAB-tempfile is created by MATLAB command 'temp_name' [OUT] obj : stack object Examples: data = 'test_data'; % create stack(stack size=10, Memory stack) stk = vb_stack_new(10, 'M'); % push stk = vb_stack_push(stk, data); % pop [stk, pop_data] = vb_stack_pop(stk); % destroy stack(Don't forget) vb_stack_delete(stk); Caution: When you push data exceeding the stack_size, the oldest data is deleted. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [obj] = vb_stack_new(stack_size, stack_type) 0002 % create stack object 0003 % [USAGE] 0004 % [obj] = vb_stack_new([stack_size][,stack_type]); 0005 % [IN] 0006 % stack_size : stack buffer size.(default: unlimit) 0007 % stack_type : 'M', 'm' : stack buffers on memory.(default) 0008 % 'F', 'f' : stack buffers on MATLAB-tempfile. 0009 % MATLAB-tempfile is created by 0010 % MATLAB command 'temp_name' 0011 % 0012 % [OUT] 0013 % obj : stack object 0014 % 0015 % Examples: 0016 % 0017 % data = 'test_data'; 0018 % 0019 % % create stack(stack size=10, Memory stack) 0020 % stk = vb_stack_new(10, 'M'); 0021 % 0022 % % push 0023 % stk = vb_stack_push(stk, data); 0024 % 0025 % % pop 0026 % [stk, pop_data] = vb_stack_pop(stk); 0027 % 0028 % % destroy stack(Don't forget) 0029 % vb_stack_delete(stk); 0030 % 0031 % Caution: 0032 % When you push data exceeding the stack_size, 0033 % the oldest data is deleted. 0034 % 0035 % Copyright (C) 2011, ATR All Rights Reserved. 0036 % License : New BSD License(see VBMEG_LICENSE.txt) 0037 0038 0039 % 0040 % --- Previous check 0041 % 0042 if ~exist('stack_size', 'var') 0043 stack_size = inf; 0044 end 0045 if ~exist('stack_type', 'var') 0046 stack_type = 'm'; 0047 end 0048 0049 % 0050 % --- Main Procedure 0051 % 0052 obj = struct; 0053 obj.class_type = 'stack'; 0054 obj.stack_size = stack_size; 0055 0056 % create concrete object 0057 switch(lower(stack_type)) 0058 case 'm' 0059 obj = vb_m_stack_new(obj); 0060 case 'f' 0061 obj = vb_f_stack_new(obj); 0062 otherwise 0063 error('Specified stack_type is invalid.'); 0064 end 0065 0066 % 0067 % --- After check 0068 % 0069 if nargout ~= 1 0070 error('function caller should receive obj.'); 0071 end