Browse Source

cmStack.h/c: Added cmStackTop() to return the top stack element.

master
kevin 11 years ago
parent
commit
8f09079fe0
2 changed files with 13 additions and 1 deletions
  1. 8
    0
      cmStack.c
  2. 5
    1
      cmStack.h

+ 8
- 0
cmStack.c View File

238
   return rc;
238
   return rc;
239
 }
239
 }
240
 
240
 
241
+const void* cmStackTop(     cmStackH_t h )
242
+{
243
+  unsigned n = cmStackCount(h);
244
+  if( n == 0 )
245
+    return NULL;
246
+  return cmStackGet(h,n-1);
247
+}
248
+
241
 cmStRC_t _cmStackSetGet( cmStack_t* p, unsigned index, char* data, unsigned dataEleCnt, bool setFl )
249
 cmStRC_t _cmStackSetGet( cmStack_t* p, unsigned index, char* data, unsigned dataEleCnt, bool setFl )
242
 {
250
 {
243
   cmStRC_t   rc = kOkStRC;
251
   cmStRC_t   rc = kOkStRC;

+ 5
- 1
cmStack.h View File

18
 
18
 
19
   extern cmStackH_t cmStackNullHandle;
19
   extern cmStackH_t cmStackNullHandle;
20
 
20
 
21
-  // Allocate a stack to hold fixed data elements of size 'eleByteCnt'.
21
+  // Allocate a stack to hold data elements each of size 'eleByteCnt'.
22
   // The stack will be initialized with 'initCnt' empty slots. Once these
22
   // The stack will be initialized with 'initCnt' empty slots. Once these
23
   // slots are filled 'expandCnt' additional slots will be added as necessary.
23
   // slots are filled 'expandCnt' additional slots will be added as necessary.
24
   cmStRC_t    cmStackAlloc( cmCtx_t* ctx, cmStackH_t* hp, unsigned initCnt, unsigned expandCnt, unsigned eleByteCnt );
24
   cmStRC_t    cmStackAlloc( cmCtx_t* ctx, cmStackH_t* hp, unsigned initCnt, unsigned expandCnt, unsigned eleByteCnt );
37
   // Remove 'eleCnt' elements from the stack.
37
   // Remove 'eleCnt' elements from the stack.
38
   cmStRC_t    cmStackPop(     cmStackH_t h, unsigned eleCnt );
38
   cmStRC_t    cmStackPop(     cmStackH_t h, unsigned eleCnt );
39
 
39
 
40
+  // Return a pointer to the top element on the stack. This is the one which will be
41
+  // lost with the next call to cmStackPop(h,1).
42
+  const void* cmStackTop(     cmStackH_t h );
43
+
40
   // Set the value of 'dataEleCnt' elements on the stack.
44
   // Set the value of 'dataEleCnt' elements on the stack.
41
   cmStRC_t    cmStackSet(     cmStackH_t h, unsigned index, const void* data, unsigned dataEleCnt );
45
   cmStRC_t    cmStackSet(     cmStackH_t h, unsigned index, const void* data, unsigned dataEleCnt );
42
 
46
 

Loading…
Cancel
Save