source: libcf/trunk/src/cf_stack.c@ 117

Last change on this file since 117 was 117, checked in by cheese, 11 years ago

#1 more fix and arrange doxygen comments

File size: 2.3 KB
Line 
1/**
2 * @file cf_stack.c
3 * @author myusgun <myusgun@gmail.com>
4 *
5 * @brief 스택 구현
6 */
7#include "cf_stack.h"
8#include "cf_list.h"
9#include "cf_error.h"
10
11#include <stdio.h>
12
13/**
14 * 스택 컨텍스트 생성
15 *
16 * @return 성공 시, CF_OK; 실패 시, 오류 코드
17 *
18 * @param ctx 스택 컨텍스트 포인터
19 */
20int
21CF_Stack_CreateCtx (CF_Stack_Ctx * ctx)
22{
23 return CF_List_CreateCtx ((CF_List_Ctx *) ctx);
24}
25
26/**
27 * 스택 컨텍스트 해제
28 *
29 * @return 성공 시, CF_OK; 실패 시, 오류 코드
30 *
31 * @param ctx 스택 컨텍스트
32 */
33int
34CF_Stack_DestroyCtx (CF_Stack_Ctx ctx)
35{
36 return CF_List_DestroyCtx (ctx);
37}
38
39/**
40 * 스택에 삽입
41 *
42 * @return 성공 시, CF_OK; 실패 시, 오류 코드
43 *
44 * @param ctx 스택 컨텍스트
45 * @param element 데이터 주소
46 */
47int
48CF_Stack_Push (CF_Stack_Ctx ctx,
49 const void * element)
50{
51 int result = 0;
52 CF_List_Ctx list = (CF_List_Ctx) ctx;
53 CF_Traverser traverser = NULL;
54
55 result = CF_List_Front (list, &traverser);
56 if (result < 0)
57 return result;
58
59 return CF_List_Insert (list, traverser, CF_DIRECTION_BEFORE, element);
60}
61
62/**
63 * 스택에서 꺼내기
64 *
65 * @return 성공 시, CF_OK; 실패 시, 오류 코드
66 *
67 * @param ctx 스택 컨텍스트
68 * @param element 데이터 주소
69 */
70int
71CF_Stack_Pop (CF_Stack_Ctx ctx,
72 void ** element)
73{
74 int result = 0;
75 CF_List_Ctx list = (CF_List_Ctx) ctx;
76 CF_Traverser traverser = NULL;
77
78 result = CF_Stack_Top (ctx, element);
79 if (result < 0)
80 return result;
81
82 result = CF_List_Front (list, &traverser);
83 if (result < 0)
84 return result;
85
86 return CF_List_Remove (ctx, &traverser);
87}
88
89/**
90 * 스택 최상위의 데이터 조회
91 *
92 * @return 성공 시, CF_OK; 실패 시, 오류 코드
93 *
94 * @param ctx 스택 컨텍스트
95 * @param element 데이터 주소
96 */
97int
98CF_Stack_Top (CF_Stack_Ctx ctx,
99 void ** element)
100{
101 int result = 0;
102 CF_List_Ctx list = (CF_List_Ctx) ctx;
103 CF_Traverser traverser = NULL;
104
105 result = CF_List_Front (list, &traverser);
106 if (result < 0)
107 return result;
108
109 return CF_List_GetElement (traverser, element);
110}
111
112/**
113 * 스택에 등록된 항목의 수를 가져옴
114 *
115 * @return 성공 시, 항목 수; 실패 시, 오류 코드
116 *
117 * @param ctx 스택 컨텍스트
118 */
119int
120CF_Stack_GetSize (CF_Stack_Ctx ctx)
121{
122 return CF_List_GetSize ((CF_List_Ctx) ctx);
123}
Note: See TracBrowser for help on using the repository browser.