This repository contains a custom implementation of a ring buffer, also known as a circular queue, in C++. The implementation includes the core ring buffer functionality along with custom iterator support for easy traversal of the elements within the buffer. Exception handling for overflow and underflow conditions is also provided to ensure robust operation.
- Fixed Size: The ring buffer has a fixed capacity, defined at compile time, to store elements of any data type.
- Circular Queue Operations: Supports essential circular queue operations like
push_back(enqueue) andpop_front(dequeue). - Custom Iterator: Includes a custom iterator (
ring_it) for traversing the elements in the ring buffer. - Exception Handling: Throws exceptions (
ring_overflowandring_underflow) to handle overflow and underflow scenarios gracefully.
- A modern C++ compiler supporting C++11 or later (e.g., GCC, Clang, MSVC)
To compile the example program, use the following command:
g++ main.cpp -o ring_example
Running the Program
After compilation, you can run the program using:
sh
Copy code
./ring_example
Usage :book:
The ring class template can be instantiated with any data type and a fixed capacity. Here's a quick example:
cpp
Copy code
#include "ring.h"
int main() {
ring<int, 5> myRing;
// Add elements to the ring
myRing.push_back(1);
myRing.push_back(2);
// Iterate over the ring
for(auto it = myRing.begin(); it != myRing.end(); ++it) {
std::cout << *it << " ";
}
return 0;
}
Contributing :handshake:
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
Fork the Project
Create your Feature Branch (git checkout -b feature/AmazingFeature)
Commit your Changes (git commit -m 'Add some AmazingFeature')
Push to the Branch (git push origin feature/AmazingFeature)
Open a Pull Request
License :page_with_curl:
Distributed under the MIT License. See LICENSE for more information.
Contact :mailbox:
Your Name - lidorpa@ac.sce.ac.il
Project Link: https://github.com/Lidorpahima/Circular-Queue-array