1 /*****************************************************************************/
5 /* Integer+ptr stack used for program settings */
9 /* (C) 2017, Mega Cat Studios */
12 /* This software is provided 'as-is', without any expressed or implied */
13 /* warranty. In no event will the authors be held liable for any damages */
14 /* arising from the use of this software. */
16 /* Permission is granted to anyone to use this software for any purpose, */
17 /* including commercial applications, and to alter it and redistribute it */
18 /* freely, subject to the following restrictions: */
20 /* 1. The origin of this software must not be misrepresented; you must not */
21 /* claim that you wrote the original software. If you use this software */
22 /* in a product, an acknowledgment in the product documentation would be */
23 /* appreciated but is not required. */
24 /* 2. Altered source versions must be plainly marked as such, and must not */
25 /* be misrepresented as being the original software. */
26 /* 3. This notice may not be removed or altered from any source */
29 /*****************************************************************************/
35 #include "intptrstack.h"
39 /*****************************************************************************/
41 /*****************************************************************************/
45 void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr)
46 /* Get the value on top of an int stack */
48 PRECONDITION (S->Count > 0);
49 if (Val) *Val = S->Stack[S->Count-1].val;
50 if (Ptr) *Ptr = S->Stack[S->Count-1].ptr;
55 void IPS_Set (IntPtrStack* S, long Val, void *Ptr)
56 /* Set the value on top of an int stack */
58 PRECONDITION (S->Count > 0);
59 S->Stack[S->Count-1].val = Val;
60 S->Stack[S->Count-1].ptr = Ptr;
65 void IPS_Drop (IntPtrStack* S)
66 /* Drop a value from an int stack */
68 PRECONDITION (S->Count > 0);
74 void IPS_Push (IntPtrStack* S, long Val, void *Ptr)
75 /* Push a value onto an int stack */
77 PRECONDITION (S->Count < sizeof (S->Stack) / sizeof (S->Stack[0]));
78 S->Stack[S->Count].val = Val;
79 S->Stack[S->Count++].ptr = Ptr;
84 void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr)
85 /* Pop a value from an int stack */
87 PRECONDITION (S->Count > 0);
88 if (Val) *Val = S->Stack[--S->Count].val;
89 if (Ptr) *Ptr = S->Stack[S->Count].ptr;