Clubcos  0.0.0
Clubcos - Clubc Operating System
 모두 데이타 구조 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 매크로 페이지들
array.h
이 파일의 문서화 페이지로 가기
1 // Copyright (c) 2014, 임경현 (dlarudgus20)
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
32 #ifndef ARRAY_H_
33 #define ARRAY_H_
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 #include <stdbool.h>
38 #include "assert.h"
39 #include "string.h"
40 
44 typedef struct tagArray8
45 {
46  uint8_t *buf;
47  uint8_t *now;
48  uint8_t *end;
49 } Array8;
50 
57 static inline void ckArray8Init(Array8 *pAr, uint8_t *buf, uint8_t *end)
58 {
59  pAr->buf = pAr->now = buf;
60  pAr->end = end;
61 }
62 
68 static inline size_t ckArray8MaxSize(Array8 *pAr)
69 {
70  return pAr->end - pAr->buf;
71 }
72 
78 static inline size_t ckArray8Size(Array8 *pAr)
79 {
80  return pAr->now - pAr->buf;
81 }
82 
90 bool ckArray8Insert(Array8 *pAr, uint8_t *ptr, uint8_t data);
96 void ckArray8Erase(Array8 *pAr, uint8_t *ptr);
97 
103 void ckArray8Append(Array8 *pDest, const Array8 *pSrc);
104 
111 static inline bool ckArray8PushBack(Array8 *pAr, uint8_t data)
112 {
113  return ckArray8Insert(pAr, pAr->now, data);
114 }
115 
121 static inline uint8_t ckArray8PopBack(Array8 *pAr)
122 {
123  assert(pAr->now > pAr->buf);
124  pAr->now--;
125  uint8_t ret = *pAr->now;
126  ckArray8Erase(pAr, pAr->now);
127  return ret;
128 }
129 
135 static inline uint8_t ckArray8PopFront(Array8 *pArr)
136 {
137  uint8_t ret = *pArr->buf;
138  ckArray8Erase(pArr, pArr->buf);
139  return ret;
140 }
141 
148 static inline uint8_t *ckArray8Find(Array8 *pArr, uint8_t data)
149 {
150  return (uint8_t *)memchr(pArr->buf, data, pArr->now - pArr->buf);
151 }
152 
159 static inline uint8_t *ckArray8Remove(Array8 *pArr, uint8_t data)
160 {
161  uint8_t *pFound = ckArray8Find(pArr, data);
162  if (pFound != NULL)
163  {
164  ckArray8Erase(pArr, pFound);
165  }
166  return pFound;
167 }
168 
169 #endif /* ARRAY_H_ */
void ckArray8Append(Array8 *pDest, const Array8 *pSrc)
원본 Array8 구조체를 대상 Array8 구조체에 덧붙힙니다.
Definition: array.c:58
some os-independent functions of standard C
uint8_t * now
현재 배열의 끝점입니다.
Definition: array.h:47
uint8_t * buf
배열의 버퍼입니다.
Definition: array.h:46
void * memchr(const void *ptr, int ch, size_t count)
uint8_t data[512]
Definition: task.h:819
uint8_t * end
배열 버퍼의 끝점입니다.
Definition: array.h:48
struct tagArray8 Array8
동적 배열 구조체입니다.
#define assert(exp)
단언문을 확인합니다.
Definition: assert.h:52
동적 배열 구조체입니다.
Definition: array.h:44
void ckArray8Erase(Array8 *pAr, uint8_t *ptr)
Array8 구조체의 특정 위치에 있는 요소를 제거합니다.
Definition: array.c:50
bool ckArray8Insert(Array8 *pAr, uint8_t *ptr, uint8_t data)
Array8 구조체에 요소를 삽입합니다.
Definition: array.c:36