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 27 /// A stack 28 typedef struct Stack Stack; 29 30 /// Create stack 31 /*! 32 \param[in] element_size 33 Size of stack element 34 \param[out] stack 35 Stack context to be created 36 37 \returns true is operation succeed, false if stack were failed to allocate 38 39 \see DeleteStack 40 */ 41 bool CreateStack(size_t element_size, Stack** stack); 42 43 /// Push multiple elements to the stack 44 /*! 45 \param[in,out] stack 46 Stack context 47 \param[in] n 48 Number of elements to push to the stack 49 \param[in] elements 50 Array of elements to push to the stack. Can be NULL 51 52 \returns A pointer to an array of new elements in the stack or NULL if 53 stack is empty or push operation were failed. 54 55 \see CreateStack 56 */ 57 void* StackPushN(Stack* stack, size_t n, void* elements); 58 59 /// Pop multiple elements from the stack 60 /*! 61 \param[in,out] stack 62 Stack context 63 \param[in] n 64 Number of elements to pop from the stack 65 \param[out] elements 66 Pointer to a buffer to store elements removed from the stack 67 68 \returns true is operation succeed, false otherwise 69 70 \see CreateStack 71 */ 72 bool StackPopN(Stack* stack, size_t n, void* elements); 73 74 /// Get number of elements in the stack 75 /*! 76 \param[in] stack 77 Stack context 78 79 \returns Number of elements in the stack or 0 if stack is NULL 80 81 \see CreateStack 82 */ 83 size_t StackGetSize(Stack const* stack); 84 85 /// Get number of elements in the stack 86 /*! 87 \param[in] stack 88 Stack context 89 90 \returns Pointer to the buffer, returns NULL if stack is NULL 91 92 \see CreateStack 93 */ 94 void* StackGetBuf(Stack const* stack); 95 96 /// Deallocates memory used for the stack. 97 /*! 98 \param[in,out] stack 99 Stack context 100 101 \see CreateStack 102 */ 103 void DeleteStack(Stack** stack); 104 105 /*! @} */ 106 #endif // EPID_COMMON_SRC_STACK_H_ 107