From be49470a7250484d8be895b158ccb46d812b1b01 Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 6 May 2023 03:05:17 -0700 Subject: [PATCH] Initial Commit --- source/CMakeLists.txt | 4 ++++ source/Progress.cpp | 32 ++++++++++++++++++++++++++++++++ source/Progress.h | 26 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 source/CMakeLists.txt create mode 100644 source/Progress.cpp create mode 100644 source/Progress.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..b617588 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,4 @@ + +project(aria) + +add_library(aria SHARED Progress.cpp Progress.h) \ No newline at end of file diff --git a/source/Progress.cpp b/source/Progress.cpp new file mode 100644 index 0000000..7c74157 --- /dev/null +++ b/source/Progress.cpp @@ -0,0 +1,32 @@ +// +// Created by tara on 5/6/23. +// + +#include +#include +#include +#include +#include "Progress.h" + +namespace libac { + int Progress::getPercentOf(int cur, int max) { + return (cur*100/max); + } + void Progress::increment() { + this->current++; + + if(this->current >= this->max) this->current=this->max; + } + int Progress::getPercent() { + return (this->current*100/this->max); + } + + std::string Progress::getProgressStr() { + auto *str = new std::stringstream(); + auto buf = new char[128]; + auto count = sprintf(buf, "%d%", getPercent()); + + str->write(buf, count); + return str->str(); + } +} // libac \ No newline at end of file diff --git a/source/Progress.h b/source/Progress.h new file mode 100644 index 0000000..8d973b3 --- /dev/null +++ b/source/Progress.h @@ -0,0 +1,26 @@ +// +// Created by tara on 5/6/23. +// + +#ifndef LIBAC_CPP_PROGRESS_H +#define LIBAC_CPP_PROGRESS_H +#include +#include + +namespace libac { + + class Progress { + private: + int ticks = 0; + int current = 0; + int max = 100; + public: + static int getPercentOf(int cur, int max); + int getPercent(); + void increment(); + std::string getProgressStr(); + }; + +} // libac + +#endif //LIBAC_CPP_PROGRESS_H