1 | /**
|
---|
2 | * \file cf_queue.c
|
---|
3 | *
|
---|
4 | * \author myusgun <myusgun@gmail.com>
|
---|
5 | *
|
---|
6 | * \brief 큐 구현
|
---|
7 | */
|
---|
8 | #include "cf_queue.h"
|
---|
9 | #include "cf_list.h"
|
---|
10 | #include "cf_local.h"
|
---|
11 | #include "cf_error.h"
|
---|
12 |
|
---|
13 | #include <stdio.h>
|
---|
14 |
|
---|
15 | static int
|
---|
16 | CF_Queue_Local_Get (cf_ctx ctx,
|
---|
17 | void ** element,
|
---|
18 | CF_BOOL removeFlag)
|
---|
19 | {
|
---|
20 | int result = 0;
|
---|
21 | cf_ctx list = (cf_ctx) ctx;
|
---|
22 | cf_traverser trav = NULL;
|
---|
23 |
|
---|
24 | result = CF_List_Front (list, &trav);
|
---|
25 | if (result < 0)
|
---|
26 | return result;
|
---|
27 |
|
---|
28 | result = CF_List_Get (trav, element);
|
---|
29 | if (result < 0)
|
---|
30 | return result;
|
---|
31 |
|
---|
32 | result = (removeFlag == CF_TRUE)
|
---|
33 | ? CF_List_Remove (ctx, &trav)
|
---|
34 | : CF_OK;
|
---|
35 |
|
---|
36 | return result;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * 큐 컨텍스트 생성
|
---|
41 | *
|
---|
42 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
43 | *
|
---|
44 | * \param ctx 큐 컨텍스트 포인터
|
---|
45 | */
|
---|
46 | int
|
---|
47 | CF_Queue_Create (cf_ctx * ctx)
|
---|
48 | {
|
---|
49 | return CF_List_Create ((cf_ctx *) ctx);
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * 큐 컨텍스트 해제
|
---|
54 | *
|
---|
55 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
56 | *
|
---|
57 | * \param ctx 큐 컨텍스트
|
---|
58 | */
|
---|
59 | int
|
---|
60 | CF_Queue_Destroy (cf_ctx ctx)
|
---|
61 | {
|
---|
62 | return CF_List_Destroy (ctx);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * 큐에 삽입
|
---|
67 | *
|
---|
68 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
69 | *
|
---|
70 | * \param ctx 큐 컨텍스트
|
---|
71 | * \param element 데이터 주소
|
---|
72 | */
|
---|
73 | int
|
---|
74 | CF_Queue_Put (cf_ctx ctx,
|
---|
75 | const void * element)
|
---|
76 | {
|
---|
77 | cf_ctx list = (cf_ctx) ctx;
|
---|
78 |
|
---|
79 | return CF_List_AddRear (list, element);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * 큐에서 꺼내기
|
---|
84 | *
|
---|
85 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
86 | *
|
---|
87 | * \param ctx 큐 컨텍스트
|
---|
88 | * \param element 데이터 주소
|
---|
89 | */
|
---|
90 | int
|
---|
91 | CF_Queue_Get (cf_ctx ctx,
|
---|
92 | void ** element)
|
---|
93 | {
|
---|
94 | return CF_Queue_Local_Get (ctx, element, CF_TRUE);
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * 큐 처음의 데이터 조회
|
---|
99 | *
|
---|
100 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
101 | *
|
---|
102 | * \param ctx 큐 컨텍스트
|
---|
103 | * \param element 데이터 주소
|
---|
104 | */
|
---|
105 | int
|
---|
106 | CF_Queue_Front (cf_ctx ctx,
|
---|
107 | void ** element)
|
---|
108 | {
|
---|
109 | return CF_Queue_Local_Get (ctx, element, CF_FALSE);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * 큐에 등록된 항목의 수를 가져옴
|
---|
114 | *
|
---|
115 | * \return 성공 시, 항목 수; 실패 시, 오류 코드
|
---|
116 | *
|
---|
117 | * \param ctx 큐 컨텍스트
|
---|
118 | */
|
---|
119 | int
|
---|
120 | CF_Queue_GetSize (cf_ctx ctx)
|
---|
121 | {
|
---|
122 | return CF_List_GetSize ((cf_ctx) ctx);
|
---|
123 | }
|
---|