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 /*****************************************************************************/
42 /*****************************************************************************/
44 /*****************************************************************************/
48 typedef struct IntPtrStack IntPtrStack;
55 struct IntPtrInner Stack[8];
58 /* An initializer for an empty int stack */
59 #define STATIC_INTPTRSTACK_INITIALIZER { 0, { 0, 0 }, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }
61 /* Declare an int stack with the given value as first element */
62 #define INTPTRSTACK(Val, Ptr) { 1, { {Val, Ptr}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }
66 /*****************************************************************************/
68 /*****************************************************************************/
72 #if defined(HAVE_INLINE)
73 INLINE int IPS_IsFull (const IntPtrStack* S)
74 /* Return true if there is no space left on the given int stack */
76 return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0]));
79 # define IPS_IsFull(S) ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0]))
82 #if defined(HAVE_INLINE)
83 INLINE int IPS_IsEmpty (const IntPtrStack* S)
84 /* Return true if there are no values on the given int stack */
86 return (S->Count == 0);
89 # define IPS_IsEmpty(S) ((S)->Count == 0)
92 #if defined(HAVE_INLINE)
93 INLINE unsigned IPS_GetCount (const IntPtrStack* S)
94 /* Return the number of elements on the given int stack */
99 # define IPS_GetCount(S) (S)->Count
102 void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr);
103 /* Get the value on top of an int stack */
105 void IPS_Set (IntPtrStack* S, long Val, void *Ptr);
106 /* Set the value on top of an int stack */
108 void IPS_Drop (IntPtrStack* S);
109 /* Drop a value from an int stack */
111 void IPS_Push (IntPtrStack* S, long Val, void *Ptr);
112 /* Push a value onto an int stack */
114 void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr);
115 /* Pop a value from an int stack */
119 /* End of IntPtrStack.h */