1 | /**
|
---|
2 | * \file cf_queue.c
|
---|
3 | * \author myusgun <myusgun@gmail.com>
|
---|
4 | *
|
---|
5 | * \brief 큐 구현
|
---|
6 | */
|
---|
7 | #include "cf_queue.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 | */
|
---|
20 | int
|
---|
21 | CF_Queue_CreateCtx (CF_Queue_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 | */
|
---|
33 | int
|
---|
34 | CF_Queue_DestroyCtx (CF_Queue_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 | */
|
---|
47 | int
|
---|
48 | CF_Queue_Put (CF_Queue_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_Rear (list, &traverser);
|
---|
56 | if (result < 0)
|
---|
57 | return result;
|
---|
58 |
|
---|
59 | return CF_List_Insert (list, traverser, CF_DIRECTION_AFTER, element);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * 큐에서 꺼내기
|
---|
64 | *
|
---|
65 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
66 | *
|
---|
67 | * \param ctx 큐 컨텍스트
|
---|
68 | * \param element 데이터 주소
|
---|
69 | */
|
---|
70 | int
|
---|
71 | CF_Queue_Get (CF_Queue_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_Queue_Front (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 | */
|
---|
97 | int
|
---|
98 | CF_Queue_Front (CF_Queue_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 | */
|
---|
119 | int
|
---|
120 | CF_Queue_GetSize (CF_Queue_Ctx ctx)
|
---|
121 | {
|
---|
122 | return CF_List_GetSize ((CF_List_Ctx) ctx);
|
---|
123 | }
|
---|