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,6 +238,14 @@ cmStRC_t cmStackPop(   cmStackH_t h, unsigned eleCnt )
238 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 249
 cmStRC_t _cmStackSetGet( cmStack_t* p, unsigned index, char* data, unsigned dataEleCnt, bool setFl )
242 250
 {
243 251
   cmStRC_t   rc = kOkStRC;

+ 5
- 1
cmStack.h View File

@@ -18,7 +18,7 @@ extern "C" {
18 18
 
19 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 22
   // The stack will be initialized with 'initCnt' empty slots. Once these
23 23
   // slots are filled 'expandCnt' additional slots will be added as necessary.
24 24
   cmStRC_t    cmStackAlloc( cmCtx_t* ctx, cmStackH_t* hp, unsigned initCnt, unsigned expandCnt, unsigned eleByteCnt );
@@ -37,6 +37,10 @@ extern "C" {
37 37
   // Remove 'eleCnt' elements from the stack.
38 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 44
   // Set the value of 'dataEleCnt' elements on the stack.
41 45
   cmStRC_t    cmStackSet(     cmStackH_t h, unsigned index, const void* data, unsigned dataEleCnt );
42 46
 

Loading…
Cancel
Save