c_stack.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  2. * This file is part of clib library
  3. * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
  23. #include "c_lib.h"
  24. struct clib_stack *
  25. new_clib_stack( int default_size, clib_destroy fn_d) {
  26. struct clib_stack *pStack = ( struct clib_stack*)malloc(sizeof ( struct clib_stack));
  27. pStack->pStackArr = new_clib_array ( default_size, NULL, fn_d);
  28. return pStack;
  29. }
  30. void
  31. delete_clib_stack(struct clib_stack *pStack){
  32. if ( pStack ){
  33. delete_clib_array ( pStack->pStackArr );
  34. }
  35. free ( pStack );
  36. }
  37. void
  38. push_clib_stack(struct clib_stack *pStack, void *elem, size_t elem_size) {
  39. push_back_clib_array( pStack->pStackArr, elem, elem_size);
  40. }
  41. void
  42. pop_clib_stack(struct clib_stack *pStack, void **elem) {
  43. back_clib_array( pStack->pStackArr, elem );
  44. remove_clib_array( pStack->pStackArr, size_clib_array( pStack->pStackArr) - 1);
  45. }
  46. clib_bool
  47. empty_clib_stack ( struct clib_stack *pStack) {
  48. return empty_clib_array( pStack->pStackArr);
  49. }