www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcfoundation/@stack/addToTop.m
function newID = addToTop( obj, newItem ) %ADDTOTOP Add a new item to the top of the stack % % ID = obj.addToTop(ITEM) adds ITEM to the top of the stack and returns % ID, a unique number that is used to remove the item later on. % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. %ID is formed from instance (2^36...2^52) plus item (0...2^36) numbers newID = obj.instanceID + (obj.nextID); if obj.nextID<(2^36) % At 2^36 the unique ID's will enter the bits that hold the object's % unique instance ID. At this point it is better to wrap back to using % 0 since this is probably old and long forgotten. obj.nextID = obj.nextID+1; else % Wrap back to using 0 obj.nextID = 0; end obj.ObjectList{obj.nItems+1} = newItem; obj.IDList(obj.nItems+1) = newID; obj.nItems = obj.nItems+1; if obj.nItems==length(obj.IDList) % need to extend stack obj.ObjectList(end+1:end+10) = cell(1,10); obj.IDList(end+1:end+10) = -1; end obj.send('TopItemChange', handle.EventData(obj, 'TopItemChange'));