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

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

#1 add bitwise util from ARIA of chevalier

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