Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
Queue< T > Class Template Reference

Public Member Functions

void init (T *list, uint8_t size)
error_t add (T item)
error_t pop (T &item)
bool isFull ()
bool isEmpty ()
uint8_t getLength ()
error_t peek (T &item)

Member Function Documentation

◆ add()

template<class T>
error_t Queue< T >::add ( T item)
inline
60 {
61 if (this->length == this->size) {
62 return ERROR_FAIL;
63 } else {
64 uint8_t nextTail = (this->tail + 1) % this->size;
65 this->list[this->tail] = item;
66 this->tail = nextTail;
67 this->length++;
68 return ERROR_SUCCESS;
69 }
70 }
Definition Queue.hpp:50

◆ getLength()

template<class T>
uint8_t Queue< T >::getLength ( )
inline
90 {
91 return this->length;
92 }

◆ init()

template<class T>
void Queue< T >::init ( T * list,
uint8_t size )
inline
52 {
53 this->list = list;
54 this->size = size;
55 this->head = 0;
56 this->tail = 0;
57 this->length = 0;
58 }

◆ isEmpty()

template<class T>
bool Queue< T >::isEmpty ( )
inline
86 {
87 return (this->length == 0) ? true : false;
88 }

◆ isFull()

template<class T>
bool Queue< T >::isFull ( )
inline
82 {
83 return (this->length == this->size) ? true : false;
84 }

◆ peek()

template<class T>
error_t Queue< T >::peek ( T & item)
inline
94 {
95 if (this->length > 0) {
96 item = this->list[this->head];
97 return ERROR_SUCCESS;
98 } else {
99 return ERROR_FAIL;
100 }
101 }

◆ pop()

template<class T>
error_t Queue< T >::pop ( T & item)
inline
72 {
73 error_t err = peek(item);
74 if (err == ERROR_SUCCESS) {
75 this->head = (this->head + 1) % this->size;
76 this->length--;
77 }
78
79 return err;
80 }

The documentation for this class was generated from the following file: