Skip to content

Commit 2b2717e

Browse files
committed
added stack_clear()
1 parent 98b9064 commit 2b2717e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

gstack-header.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ static stack_status GENERIC(stack_healthCheck)(const GENERIC(stack) *this_);
436436
static stack_status GENERIC(stack_dump)(const GENERIC(stack) *this_);
437437

438438

439+
/**
440+
* @fn static stack_status stack_clear(const stack *this_)
441+
* @brief destroys stack and creates a new one
442+
* @param this_ pointer to stack
443+
* @return bitset of stack status
444+
*/
445+
static stack_status GENERIC(stack_clear)(const GENERIC(stack) *this_);
446+
447+
439448
/**
440449
* @fn static stack_status stack_dumpToStream(const stack *this_, FILE *out)
441450
* @brief dumps stack structure and data into `out`

gstack.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ static stack_status GENERIC(stack_reallocate)(GENERIC(stack) *this_, const size_
417417
}
418418

419419

420+
static stack_status GENERIC(stack_clear)(GENERIC(stack) *this_)
421+
{
422+
stack_status status = GENERIC(stack_dtor)(this_);
423+
if (status != 0)
424+
return status;
425+
status = GENERIC(stack_ctor)(this_);
426+
return status;
427+
}
428+
429+
420430
static stack_status GENERIC(stack_dumpToStream)(const GENERIC(stack) *this_, FILE *out)
421431
{
422432
STACK_PTR_VALIDATE(this_);

stack-test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ TEST(PushGet, Random)
236236
}
237237
}
238238
EXPECT_EQ(S.len, STD.size());
239+
GENERIC(stack_clear)(&S);
240+
EXPECT_EQ(S.len, 0);
239241
GENERIC(stack_dtor)(&S);
240242

241243
}

0 commit comments

Comments
 (0)