Zakero Base.
More...
Go to the source code of this file.
|
enum | zakero::Storage : uint64_t {
zakero::Storage::Byte,
zakero::Storage::Kilobyte,
zakero::Storage::Megabyte,
zakero::Storage::Gigabyte,
zakero::Storage::Terabyte,
zakero::Storage::Petabyte,
zakero::Storage::Exabyte
} |
| Conversion Type. More...
|
|
Nothing complicated here, just a collection of helper functions, macros, and templates that may be useful in your projects.
Include this header in your source code to use these features.
- Version
0.9.1
0.9.0
- Copyright
- Mozilla Public License v2
- Author
- Andrew "Zakero" Moore
◆ ZAKERO_CONCAT
#define ZAKERO_CONCAT |
( |
|
thing_1_, |
|
|
|
thing_2_ |
|
) |
| |
Use the C/C++ Preprocessor to create a new symbol name. For example the symbol abcxyz could be created using ZAKERO_CONCAT(abc, xyz).
- Example
- Parameters
-
thing_1_ | Symbol left side |
thing_2_ | Symbol right side |
◆ ZAKERO_MACRO_HAS_VALUE
#define ZAKERO_MACRO_HAS_VALUE |
( |
|
define_ | ) |
|
Use this macro function to determine if a macro has a value and is not just defined.
- Example
#define BEER
#if ZAKERO_MACRO_HAS_VALUE(BEER)
#warning I can has beer!
#else
#error No beer! // <-- This happens
#endif
- Parameters
-
define_ | The defined macro to check. |
◆ ZAKERO_STEADY_TIME_NOW
#define ZAKERO_STEADY_TIME_NOW |
( |
|
unit_ | ) |
|
This macro will get the current time count of the std::chrono::steady_clock
.
- Note
- The
std::chrono
is automatically applied to the unit_
.
- Example
- Parameters
-
unit_ | The time unit to get. |
◆ ZAKERO_SYSTEM_TIME_NOW
#define ZAKERO_SYSTEM_TIME_NOW |
( |
|
unit_ | ) |
|
This macro will get the current time count of the std::chrono::system_clock
.
- Note
- The
std::chrono
is automatically applied to the unit_
.
- Example
- Parameters
-
unit_ | The time unit to get. |
◆ Storage
◆ convert() [1/2]
Conversion from one storage unit to another is handled by this method. These storage units are in powers of 2.
The difference between this method and zakero::convert(const uint64_t, const zakero::Storage, const zakero::Storage) is that conversions to a larger unit will be a fraction.
- Example
, zakero::Storage::Gigabyte
, zakero::Storage::Byte
);
, zakero::Storage::Kilobyte
, zakero::Storage::Megabyte
);
- Returns
- The converted value.
- Parameters
-
size | The size to convert |
from | The source unit |
to | The destination unit |
◆ convert() [2/2]
Conversion from one storage unit to another is handled by this method. These storage units are in powers of 2.
Converting to a larger size is rounded down and may result in 0
if the from size
is not large enough.
- Example
, zakero::Storage::Gigabyte
, zakero::Storage::Byte
);
, zakero::Storage::Kilobyte
, zakero::Storage::Megabyte
);
- Returns
- The converted value.
- Parameters
-
size | The size to convert |
from | The source unit |
to | The destination unit |
◆ to_string()
std::string zakero::to_string |
( |
const std::error_code & |
error | ) |
|
|
noexcept |
The provided error
will be converted to a string.
- Returns
- A string
- Parameters
-
◆ vectorContains() [1/2]
template<class Type >
bool zakero::vectorContains |
( |
const std::vector< Type > & |
vector, |
|
|
const Type & |
value |
|
) |
| |
|
inlinenoexcept |
A convience method to make searching a vector easier, like std::map::contains().
- Example
std::vector<int> v = { 0, 1, 2, 3 };
{
}
- Return values
-
true | The value was found. |
false | The value was not found. |
- Parameters
-
vector | The vector to search |
value | The value to look for |
◆ vectorContains() [2/2]
template<class InputIter , class Type >
bool zakero::vectorContains |
( |
InputIter |
first, |
|
|
InputIter |
last, |
|
|
const Type & |
value |
|
) |
| |
|
inlinenoexcept |
A convience method to make searching a vector easier. While this method does not save that many keystrokes, it does lead to more readable code.
- Example
std::vector<int> v = { 0, 1, 2, 3 };
{
}
if(std::find(std::begin(v), std::end(v), 1) != std::end(v))
{
}
- Return values
-
true | The value was found. |
false | The value was not found. |
- Parameters
-
first | Start searching here |
last | Stop seaching here |
value | The value to look for |
◆ vectorErase()
template<class Type >
auto zakero::vectorErase |
( |
std::vector< Type > & |
vector, |
|
|
const Type & |
value |
|
) |
| |
|
inlinenoexcept |
A convience method to make removing content from a vector easier.
- Example
std::vector<int> v = { 0, 1, 2, 3 };
- Return values
-
true | The value was found. |
false | The value was not found. |
- Parameters
-
vector | The vector to search |
value | The value to look for |
double convert(const double size, const zakero::Storage from, const zakero::Storage to) noexcept
Convert storage sizes.
Definition: Zakero_Base.h:234
bool vectorContains(const std::vector< Type > &vector, const Type &value) noexcept
Check the contents of a std::vector.
Definition: Zakero_Base.h:267
#define ZAKERO_CONCAT(thing_1_, thing_2_)
Concatenate the two things.
Definition: Zakero_Base.h:84
auto vectorErase(std::vector< Type > &vector, const Type &value) noexcept
Erase the contents of a std::vector.
Definition: Zakero_Base.h:338