...is a lightweight command queueing system written in C++. Functions are "bound" to an instance of the QueueBall class to later be paired with arguments and queued for execution via a command ID.
Usage
- Create an instance of the QueueBall class:
QueueBall qb;. - Create an
unsigned intto hold your function's "command ID". - Bind the command to its ID with
qb.BindCommand(commandID, PtrToMyFunction). If your function has arguments, use this syntax:qb.BindCommand(commandID, (qbFnPtr)PtrToMyFunction, argumentCount). - To add your command to the queue, call
qb.RecordCommand(commandID). If your function has arguments, use this syntax:qb.RecordCommand(commandID, (qbArgPtr)(&MyArgument))ORqb.RecordCommand(commandID, (qbArgPtr)(&StructContainingMyArguments)). - Execute all recorded commands with
qb.ExecuteCommands(). - To unbind a command, call
qb.UnbindCommand(commandID).
Created by: Kade Samson
Github repo: github.com/kadealicious/QueueBall
- Portfolio: kadesamson.com
- Linkedin: @kadesamson
- Github: @kadealicious
- Instagram: @kadesamson
Technical Notes
- Each command that is bound is stored in a vector of
QbCommandstructs. When commands are queued, the pointer to each recordedQbCommandis stored in a vector which also stores the newly specified arguments for the command record. When the commands are executed, their functions and arguments are then executed sequentially from the queue (implemented as a deque to allow for binary search inRecordCommand()). BindCommand()&UnbindCommand()are executed in average O(1) time,RecordCommand()in average O(log N), andExecuteCommands()in average O(N).- Because
ExecuteCommands()must by nature traverse through each executed command in order, it executes in O(N) time. RecordCommand()uses a binary search, so I was able to get the search time down to O(log N).