stack.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*############################################################################
  2. # Copyright 2016-2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. #ifndef EPID_COMMON_SRC_STACK_H_
  17. #define EPID_COMMON_SRC_STACK_H_
  18. /*!
  19. * \file
  20. * \brief Stack container interface.
  21. * \addtogroup EpidCommon
  22. * @{
  23. */
  24. #include <stddef.h>
  25. #include "epid/common/stdtypes.h"
  26. /// A stack
  27. typedef struct Stack Stack;
  28. /// Create stack
  29. /*!
  30. \param[in] element_size
  31. Size of stack element
  32. \param[out] stack
  33. Stack context to be created
  34. \returns true is operation succeed, false if stack were failed to allocate
  35. \see DeleteStack
  36. */
  37. bool CreateStack(size_t element_size, Stack** stack);
  38. /// Push multiple elements to the stack
  39. /*!
  40. \param[in,out] stack
  41. Stack context
  42. \param[in] n
  43. Number of elements to push to the stack
  44. \param[in] elements
  45. Array of elements to push to the stack. Can be NULL
  46. \returns A pointer to an array of new elements in the stack or NULL if
  47. stack is empty or push operation were failed.
  48. \see CreateStack
  49. */
  50. void* StackPushN(Stack* stack, size_t n, void* elements);
  51. /// Pop multiple elements from the stack
  52. /*!
  53. \param[in,out] stack
  54. Stack context
  55. \param[in] n
  56. Number of elements to pop from the stack
  57. \param[out] elements
  58. Pointer to a buffer to store elements removed from the stack
  59. \returns true is operation succeed, false otherwise
  60. \see CreateStack
  61. */
  62. bool StackPopN(Stack* stack, size_t n, void* elements);
  63. /// Get number of elements in the stack
  64. /*!
  65. \param[in] stack
  66. Stack context
  67. \returns Number of elements in the stack or 0 if stack is NULL
  68. \see CreateStack
  69. */
  70. size_t StackGetSize(Stack const* stack);
  71. /// Get number of elements in the stack
  72. /*!
  73. \param[in] stack
  74. Stack context
  75. \returns Pointer to the buffer, returns NULL if stack is NULL
  76. \see CreateStack
  77. */
  78. void* StackGetBuf(Stack const* stack);
  79. /// Deallocates memory used for the stack.
  80. /*!
  81. \param[in,out] stack
  82. Stack context
  83. \see CreateStack
  84. */
  85. void DeleteStack(Stack** stack);
  86. /*! @} */
  87. #endif // EPID_COMMON_SRC_STACK_H_