started utilities file

This commit is contained in:
frank 2021-11-01 17:33:27 -04:00
parent 2c0517b9e2
commit dd736f341f
4 changed files with 43 additions and 8 deletions

View File

@ -6,7 +6,7 @@
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+ */
+-------------*/
#include "Attributes.hpp"

View File

@ -6,6 +6,7 @@
#include "Color.hpp"
#include "Log.hpp"
#include "extension.hpp"
#include "utility.hpp"
class Sprite;

View File

@ -1,3 +1,13 @@
/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+-------------*/
#ifndef extension_h_
#define extension_h_
@ -87,13 +97,6 @@ namespace sb
return std::find(container.begin(), container.end(), member) != container.end();
}
/* Modulus that handles negative and float arguments */
template<typename N>
inline float mod(N a, N b)
{
return (b + (a % b)) % b;
}
/* Front pad passed end string with fill character until it is width characters long and return a new string */
template<typename T>
std::string pad(T end, int width, char fill = '0')

31
src/utility.hpp Normal file
View File

@ -0,0 +1,31 @@
/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+
[utility.hpp]
For lightweight utility functions that extend C++ functionality and don't depend on
any [SPACE BOX] specific functions.
*/
#ifndef SB_UTILITY_H_
#define SB_UTILITY_H_
namespace sb
{
/* Modulus that handles negative and float arguments */
template<typename Number>
Number mod(Number a, Number b)
{
return (b + (a % b)) % b;
}
}
#endif