Skip to content

Commit c6f940c

Browse files
committed
added stack_top(); small change to CMake msg
1 parent f7d8976 commit c6f940c

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ include(GoogleTest)
5757
# gtest_discover_tests(stack-demo)
5858

5959

60-
message("+--------------------------------------------------------------+--------------------------------------------------------------+--------------------------------------------------------------+")
61-
message("| | | |")
62-
message("| .;o, | .;o, | .;o, |")
63-
message("| __.\"iIoi,._ ;pI __-\"-xx.,_ | __.\"iIoi,._ ;pI __-\"-xx.,_ | __.\"iIoi,._ ;pI __-\"-xx.,_ |")
64-
message("| `.3\"P3PPPoie-,. .d' `;. `p; | `.3\"P3PPPoie-,. .d' `;. `p; | `.3\"P3PPPoie-,. .d' `;. `p; |")
65-
message("| `O\"dP\"````\"\"`PdEe._ .;' . ` `| GStack! | `O\"dP\"````\"\"`PdEe._ .;' . ` `| GStack! | `O\"dP\"````\"\"`PdEe._ .;' . ` `| GStack! |")
66-
message("| \"$#\"' ``\"P4rdddsP' .F. ` `` ; / | \"$#\"' ``\"P4rdddsP' .F. ` `` ; / | \"$#\"' ``\"P4rdddsP' .F. ` `` ; / |")
67-
message("| i/\"\"\" *\"Sp. .dPff. _.,;Gw' | i/\"\"\" *\"Sp. .dPff. _.,;Gw' | i/\"\"\" *\"Sp. .dPff. _.,;Gw' |")
68-
message("| ;l\"' \" `dp.. \"sWf;fe|' | ;l\"' \" `dp.. \"sWf;fe|' | ;l\"' \" `dp.. \"sWf;fe|' |")
69-
message("| `l; .rPi . . \"\" \"dW;;doe; | `l; .rPi . . \"\" \"dW;;doe; | `l; .rPi . . \"\" \"dW;;doe; |")
70-
message("| $ .;PE`' \" \"sW;.d.d; | $ .;PE`' \" \"sW;.d.d; | $ .;PE`' \" \"sW;.d.d; |")
71-
message("| $$ .$\"` `\"saed;lW;.d.d.i | $$ .$\"` `\"saed;lW;.d.d.i | $$ .$\"` `\"saed;lW;.d.d.i |")
72-
message("| .$M ; `` ' ld;.p. | .$M ; `` ' ld;.p. | .$M ; `` ' ld;.p. |")
73-
message("| __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ | __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ | __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ |")
74-
message("| | | |")
75-
message("+--------------------------------------------------------------+--------------------------------------------------------------+--------------------------------------------------------------+")
60+
message("+--------------------------------------------------------------+---------------------------------------------------------------+--------------------------------------------------------------+")
61+
message("| | | |")
62+
message("| .;o, | .;o, | .;o, |")
63+
message("| __.\"iIoi,._ ;pI __-\"-xx.,_ | __.\"iIoi,._ ;pI __-\"-xx.,_ | __.\"iIoi,._ ;pI __-\"-xx.,_ |")
64+
message("| `.3\"P3PPPoie-,. .d' `;. `p; | `.3\"P3PPPoie-,. .d' `;. `p; | `.3\"P3PPPoie-,. .d' `;. `p; |")
65+
message("| `O\"dP\"````\"\"`PdEe._ .;' . ` `| GStack! | `O\"dP\"````\"\"`PdEe._ .;' . ` ` | GStack! | `O\"dP\"````\"\"`PdEe._ .;' . ` `| GStack! |")
66+
message("| \"$#\"' ``\"P4rdddsP' .F. ` `` ; / | \"$#\"' ``\"P4rdddsP' .F. ` `` ; / | \"$#\"' ``\"P4rdddsP' .F. ` `` ; / |")
67+
message("| i/\"\"\" *\"Sp. .dPff. _.,;Gw' | i/\"\"\" *\"Sp. .dPff. _.,;Gw' | i/\"\"\" *\"Sp. .dPff. _.,;Gw' |")
68+
message("| ;l\"' \" `dp.. \"sWf;fe|' | ;l\"' \" `dp.. \"sWf;fe|' | ;l\"' \" `dp.. \"sWf;fe|' |")
69+
message("| `l; .rPi . . \"\" \"dW;;doe; | `l; .rPi . . \"\" \"dW;;doe; | `l; .rPi . . \"\" \"dW;;doe; |")
70+
message("| $ .;PE`' \" \"sW;.d.d; | $ .;PE`' \" \"sW;.d.d; | $ .;PE`' \" \"sW;.d.d; |")
71+
message("| $$ .$\"` `\"saed;lW;.d.d.i | $$ .$\"` `\"saed;lW;.d.d.i | $$ .$\"` `\"saed;lW;.d.d.i |")
72+
message("| .$M ; `` ' ld;.p. | .$M ; `` ' ld;.p. | .$M ; `` ' ld;.p. |")
73+
message("| __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ | __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ | __ _`$o,.-__ \"ei-Mu~,.__ ___ `_-dee3'o-ii~m. ____ |")
74+
message("| | | |")
75+
message("+--------------------------------------------------------------+---------------------------------------------------------------+--------------------------------------------------------------+")
7676
message("\t\t\t\t\t\t\t\t\t ----------------------------------")
7777
message("\t\t\t\t\t\t\t\t\t | Thx for checking out my code! |")
7878
message("\t\t\t\t\t\t\t\t\t ----------------------------------")

gstack-header.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,23 @@ static stack_status stack_push(stack *this_, STACK_TYPE item);
372372

373373

374374
/**
375-
* @fn static stack_status stack_pop (stack *this_, STACK_TYPE item)
375+
* @fn static stack_status stack_pop (stack *this_, STACK_TYPE *item)
376376
* @brief pops last elem from stack
377377
* @param this_ pointer to stack
378378
* @param item pointer to var to write to or NULL if value should be discarded
379379
* @return bitset of stack status
380380
*/
381-
static stack_status stack_pop (stack *this_, STACK_TYPE* item);
381+
static stack_status stack_pop (stack *this_, STACK_TYPE *item);
382+
383+
384+
/**
385+
* @fn static stack_status stack_top (stack *this_, STACK_TYPE **item)
386+
* @brief puts puts ptr to current top element
387+
* @param this_ pointer to stack
388+
* @param item pointer to pointer to top elem
389+
* @return bitset of stack status
390+
*/
391+
static stack_status stack_top (stack *this_, STACK_TYPE **item);
382392

383393

384394
/**
@@ -390,7 +400,7 @@ static stack_status stack_pop (stack *this_, STACK_TYPE* item);
390400
#ifdef STACK_USE_CAPACITY_SYS_CHECK
391401
static stack_status stack_healthCheck(stack *this_);
392402
#else
393-
static stack_status stack_healthCheck(const stack *this_);
403+
static stack_status stack_healthCheck(const stack *this_);
394404
#endif
395405

396406

gstack.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static stack_status stack_push(stack *this_, STACK_TYPE item)
281281
}
282282

283283

284-
static stack_status stack_pop(stack *this_, STACK_TYPE* item)
284+
static stack_status stack_pop(stack *this_, STACK_TYPE *item)
285285
{
286286
STACK_PTR_VALIDATE(this_);
287287

@@ -332,6 +332,24 @@ static stack_status stack_pop(stack *this_, STACK_TYPE* item)
332332
return STACK_HEALTH_CHECK(this_);
333333
}
334334

335+
static stack_status stack_top(stack *this_, STACK_TYPE **item)
336+
{
337+
STACK_PTR_VALIDATE(this_);
338+
339+
if (STACK_HEALTH_CHECK(this_))
340+
return this_->status;
341+
342+
if (this_->len == 0) {
343+
STACK_LOG_TO_STREAM(this_, this_->logStream, "WARNING: trying to pop from empty stack!");
344+
}
345+
346+
if (ptrValid(item)) {
347+
*item = &this_->data[this_->len - 1];
348+
}
349+
350+
return STACK_HEALTH_CHECK(this_);
351+
}
352+
335353

336354
static stack_status stack_reallocate(stack *this_, const size_t newCapacity)
337355
{

0 commit comments

Comments
 (0)