]> git.sur5r.net Git - cc65/blob - src/common/intptrstack.h
remove TABs
[cc65] / src / common / intptrstack.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                intptrstack.h                              */
4 /*                                                                           */
5 /*                  Integer+ptr stack used for program settings              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2017, Mega Cat Studios                                                */
10 /*                                                                           */
11 /*                                                                           */
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.                                    */
15 /*                                                                           */
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:                            */
19 /*                                                                           */
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              */
27 /*    distribution.                                                          */
28 /*                                                                           */
29 /*****************************************************************************/
30
31
32
33 #ifndef INTPTRSTACK_H
34 #define INTPTRSTACK_H
35
36
37
38 #include "inline.h"
39
40
41
42 /*****************************************************************************/
43 /*                                   Data                                    */
44 /*****************************************************************************/
45
46
47
48 typedef struct IntPtrStack IntPtrStack;
49 struct IntPtrInner {
50         long val;
51         void *ptr;
52 };
53 struct IntPtrStack {
54     unsigned    Count;
55     struct IntPtrInner Stack[8];
56 };
57
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} } }
60
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} } }
63
64
65
66 /*****************************************************************************/
67 /*                                   Code                                    */
68 /*****************************************************************************/
69
70
71
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 */
75 {
76     return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0]));
77 }
78 #else
79 #  define IPS_IsFull(S)  ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0]))
80 #endif
81
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 */
85 {
86     return (S->Count == 0);
87 }
88 #else
89 #  define IPS_IsEmpty(S)  ((S)->Count == 0)
90 #endif
91
92 #if defined(HAVE_INLINE)
93 INLINE unsigned IPS_GetCount (const IntPtrStack* S)
94 /* Return the number of elements on the given int stack */
95 {
96     return S->Count;
97 }
98 #else
99 #  define IPS_GetCount(S)        (S)->Count
100 #endif
101
102 void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr);
103 /* Get the value on top of an int stack */
104
105 void IPS_Set (IntPtrStack* S, long Val, void *Ptr);
106 /* Set the value on top of an int stack */
107
108 void IPS_Drop (IntPtrStack* S);
109 /* Drop a value from an int stack */
110
111 void IPS_Push (IntPtrStack* S, long Val, void *Ptr);
112 /* Push a value onto an int stack */
113
114 void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr);
115 /* Pop a value from an int stack */
116
117
118
119 /* End of IntPtrStack.h */
120
121 #endif