PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Member Functions | List of all members
PropWare::CharQueue Class Referenceabstract

Provide a communication buffer for character data between cogs. More...

#include <PropWare/utility/collection/charqueue.h>

+ Inheritance diagram for PropWare::CharQueue:
+ Collaboration diagram for PropWare::CharQueue:

Public Member Functions

template<size_t N>
 CharQueue (char(&array)[N], const int lockNumber=locknew())
 
 CharQueue (char *array, const size_t length, const int lockNumber)
 
virtual char get_char ()
 Read and return a single character. Whether the method is blocking or not depends entirely on the implementation.
 
virtual void put_char (const char c)
 Print a single character. More...
 
virtual void puts (const char *string)
 
size_t size () const
 Obtain the number of elements in the queue. More...
 
bool is_empty () const
 Determine if any elements exist. More...
 
bool is_full () const
 Determine if inserting another element would overwrite data. More...
 
void clear ()
 Remove all data from the queue.
 
virtual Queueenqueue (const char &value)
 Insert an element to the buffer. More...
 
Queueinsert (const char &value)
 
virtual char dequeue ()
 Return and remove the oldest value in the buffer. More...
 
char peek () const
 Return the oldest value in the buffer without removing it from the buffer. More...
 
bool check (const char &value) const
 Determine if a value is valid. More...
 
virtual void puts (const char string[])=0
 Send a null-terminated character array. Though this method could be created using put_char, some objects (such as PropWare::UART), have optimized methods for sending a string and PrintCapable::puts can utilize them. More...
 

Detailed Description

Provide a communication buffer for character data between cogs.

Typically used for buffered UART implementations. Note that the put_char and get_char methods are blocking to ensure that put_char does not attempt to write to a full buffer and get_char does not attempt to read from an empty buffer. For this reason, you should be careful about using the enqueue and dequeue methods directly when using a CharQueue object because they will allow you to write to a full queue and read from an empty one.

Examples
BufferedUART_Demo.cpp.

Definition at line 46 of file charqueue.h.

Member Function Documentation

◆ check()

bool PropWare::Queue< char >::check ( const char value) const
inherited

Determine if a value is valid.

If the queue is read (deque or peek) when the size is 0 then a value at address 0 is returned. A better implementation would throw an exception when this occurs, but that isn't feasible on the Propeller. Use this method if you want to ensure values are valid prior to using them

Parameters
[in]valueA value returned by PropWare::Queue::peek() or PropWare::Queue::dequeue()
Returns
Whether or not the value is valid

Definition at line 234 of file queue.h.

◆ dequeue()

virtual char PropWare::Queue< char >::dequeue
virtualinherited

Return and remove the oldest value in the buffer.

Precondition
Buffer must not be empty - no checks are performed to ensure the buffer contains data
Returns
Oldest value in the buffer

Definition at line 181 of file queue.h.

◆ enqueue()

virtual Queue& PropWare::Queue< char >::enqueue ( const char value)
virtualinherited

Insert an element to the buffer.

Parameters
[in]valueValue to be inserted at the end of the buffer
Postcondition
If the buffer is already full, the oldest value will be overwritten with the value parameter
Returns
In order to allow chained calls to PropWare::Queue::enqueue, the Queue instance is returned

Definition at line 129 of file queue.h.

◆ insert()

Queue& PropWare::Queue< char >::insert ( const char value)
inherited
See also
PropWare::CircularQueue::enqueue(const T &value)

Definition at line 170 of file queue.h.

◆ is_empty()

bool PropWare::Queue< char >::is_empty
inherited

Determine if any elements exist.

Returns
True if there is one or more elements, false otherwise

Definition at line 100 of file queue.h.

◆ is_full()

bool PropWare::Queue< char >::is_full
inherited

Determine if inserting another element would overwrite data.

Returns
True if the queue can not fit any more data without loosing old data, false otherwise

Definition at line 109 of file queue.h.

◆ peek()

char PropWare::Queue< char >::peek
inherited

Return the oldest value in the buffer without removing it from the buffer.

Precondition
Buffer must not be empty - no checks are performed to ensure the buffer contains data
Returns
Oldest value in the buffer

Definition at line 219 of file queue.h.

◆ put_char()

virtual void PropWare::CharQueue::put_char ( const char  c)
virtual

Print a single character.

Parameters
[in]cIndividual char to be printed

Implements PropWare::PrintCapable.

Definition at line 64 of file charqueue.h.

+ Here is the call graph for this function:

◆ puts()

virtual void PropWare::PrintCapable::puts ( const char  string[])
pure virtualinherited

Send a null-terminated character array. Though this method could be created using put_char, some objects (such as PropWare::UART), have optimized methods for sending a string and PrintCapable::puts can utilize them.

Precondition
string[] must be terminated with a null terminator
Parameters
[in]string[]Array of data words with the final word being 0 - the null terminator

Implemented in PropWare::SPI, PropWare::HD44780, PropWare::UARTTX, PropWare::FullDuplexSerial, PropWare::FileWriter, PropWare::StringBuilder, PropWare::StaticStringBuilder, and SimplePrinter.

+ Here is the caller graph for this function:

◆ size()

size_t PropWare::Queue< char >::size
inherited

Obtain the number of elements in the queue.

Returns
Number of elements in the queue

Definition at line 91 of file queue.h.


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