001package jmri.jmrit.logixng; 002 003/** 004 * A table that is a stack 005 * 006 * @author Daniel Bergqvist 2020 007 */ 008public interface Stack { 009 010 /** 011 * Pushes a value on the top of the stack so the stack grow. 012 * @param value the value to push to the stack 013 */ 014 void push(ValueAndType value); 015 016 /** 017 * Pops the topmost value off the top of the stack so the stack shrinks. 018 * @return the value that is on the top of the stack 019 */ 020 Object pop(); 021 022 /** 023 * Get the value at an index 024 * @param index the index from bottom of the table 025 * @return value the new value 026 */ 027 Object getValueAtIndex(int index); 028 029 /** 030 * Set the value at an index 031 * @param index the index from bottom of the table 032 * @param value the new value 033 */ 034 void setValueAtIndex(int index, Object value); 035 036 /** 037 * Get the value and type at an index 038 * @param index the index from bottom of the table 039 * @return value and type the new value 040 */ 041 ValueAndType getValueAndTypeAtIndex(int index); 042 043 /** 044 * Set the value at an index 045 * @param index the index from bottom of the table 046 * @param valueAndType the new value and type 047 */ 048 void setValueAndTypeAtIndex(int index, ValueAndType valueAndType); 049 050 /** 051 * Get the number of items on the stack 052 * @return the number of items 053 */ 054 int getCount(); 055 056 /** 057 * Reset the number of items on the stack. 058 * This is used when parameters are put on the stack before a call to a 059 * module and those parameters needs to be removed when the module returns. 060 * The new count must be less than or equal to the current number of items. 061 * @param newCount the new number of items 062 */ 063 void setCount(int newCount); 064 065 066 public static class ValueAndType { 067 068 public Object _value; 069 public SymbolTable.InitialValueType _type; 070 071 public ValueAndType(SymbolTable.InitialValueType type, Object value) { 072 _value = value; 073 _type = type; 074 } 075 076 } 077 078}