Skip to content

About

C++ FIFO Integer Queue

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

cpp-intqueue

C++ Integer Queue - a small, dependency-free fixed-capacity FIFO queue of int, implemented as a ring buffer.

Tested In: C++17 / C++20
License: License: MIT

⚙️ Features

  • Clean, minimal codebase
  • Documented
  • RAII
  • Cross platform
  • Dependecy free

🛠️ Prerequisites

  • Cmake 3.19+
  • A compiler that supports C++17/C++20 (g++ | clang++ | msvc)

🚀 Quick Start

Click to expand
#include "IntQueue.hpp"
#include <iostream>

void log(IntQueue &q) {
  bool empty ; // Logging
  std::cout << "Capacity: " << q.getQueueStoredSize() << std::endl ;
  std::cout << "First Item: " << q.getFirstQueueItem(empty) << std::endl ;
  if (empty) {
      std::cout << "Container is empty" << std::endl ;
  }
  std::cout << "Last Item: " << q.getLastQueueItem(empty) << std::endl ;
  if (empty) {
      std::cout << "Container is empty" << std::endl ;
  }
}

int main(int argc, const char** argv) {
  IntQueue q(5) ;
  std::cout << q.getQueueSize() << std::endl ;
  // Initializing Container and checking for errors
  if (!q.init()) {
      std::cout << "Error: " << q.getError() << std::endl ;
      return 1 ;
  }
  
  std::cout << "Queue Minimum Size Limit: " << q.getMinQueueSize() << std::endl ;
  std::cout << "Queue Maximum Size Limit: " << q.getMaxQueueSize() << std::endl ;
  
  for (int i = 10; !q.isFull(); i *= 2) {
      // Adding Item to Container
      if (!q.addQ(i)) {
          std::cout << "Error: " << q.getError() << std::endl ;
      }
      
      log(q) ;
  }
  
  // Trying to add another item
  if (!q.addQ(200)) {
      std::cout << "Error: " << q.getError() << std::endl ;
  }
  
  // Removing Stored Integers
  while (!q.isEmpty()) {
      int item ;
      if (!q.removeQ(item)) {
          std::cout << "Error: " << q.getError() << std::endl ;
      }
      std::cout << "Removed Item: " << item << std::endl ;
  }
  
  // Trying to Remove another item
  if (!q.removeQ()) {
      std::cout << "Error: " << q.getError() << std::endl ;
  }
  
  // Resizing the Container
  if (!q.setQueueSize(100)) {
      std::cout << "Error: 1" << q.getError() << std::endl ;
  }
  std::cout << q.getQueueSize() << std::endl ;
  
  return 0 ;
}

🧩 API

Function Name Description
bool init() Initializes necessary variable including Queue container and heap allocation, returns true on success or failure on false
bool addQ(int item) Adds Integer variable to the container, returns true in success or false if it the container is full
bool removeQ(int &item) Remove the first item in the container and returns the removed item, returns true in success or false if the container is empty
bool removeQ() same as bool removeQ(int &item) but it won't return the removed item
bool setQueueSize(int size) Set how much the container can hold before it gets full, IntQueue::init() should be called after for initializing container capacity, returns true on success or false on failure
bool isFull() const A function to check whether the container is full or not, returns true if it's full or false if there's still room
bool isEmpty() const A function to check whether the container is Empty or not, returns true if it's empty or false if there's still room
void getError(const char *&info) const Points to a fixed buffer size in the container for debugging why previous call failed
const char *getError() const Same as void getError(const char *&info) const but instead it returns a pointer to the error buffer
int getMaxQueueSize() const Returns the Maximum allowed size in the container
int getMinQueueSize() const Returns the Minimum allowed size in the container

⚒️ How to Build

  1. first make sure you have Prerequisites
  2. Clone or download the source project
  3. Open terminal and type this (root project directory) :
  4. cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
  5. cmake --build build
  6. if you wish to have static library, add -DBUILD_SHARED_LIBS=OFF
  7. install it using cmake --install build or also add --prefix="C:/Your/path"

✨How to use

Download or Build the library
in your cmakelists.txt:

find_package(iqueue 1.0.0 CONFIG REQUIRED)

# Linking to your program
target_link_libraries(your_program PRIVATE iqueue::iqueue)

⭕ Limitations

IntQueue container have fixed size capacity, which makes you call initialization after you change the capacity

🌐 Download

alternatively you can download the compiled library and use it :
Windows 7+ SP1 64 Bit: Latest Release

Note

Pre-Compiled versions of library in the release are not Code-Signed, which the library might be Flagged by Anti Virus, if that happen, exclude the folder or file in the settings

About

C++ FIFO Integer Queue

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages