Zakero Base.
More...
Go to the source code of this file.
|
double | zakero::convert (const double size, const zakero::Storage from, const zakero::Storage to) noexcept |
| Convert storage sizes. More...
|
|
uint64_t | zakero::convert (const uint64_t size, const zakero::Storage from, const zakero::Storage to) noexcept |
| Convert storage sizes. More...
|
|
bool | zakero::equalish (const float a, const float b, const float delta) noexcept |
| Compare two floats. More...
|
|
std::ostream & | operator<< (std::ostream &stream, const std::error_code &error) noexcept |
| Insert std::error_code into an output stream. More...
|
|
bool | zakero::stob (const std::string_view str) noexcept |
| Convert a string into a boolean value. More...
|
|
std::string | zakero::to_string (const bool value) noexcept |
| Convert a bool into a string. More...
|
|
std::string | zakero::to_string (const std::error_code &error) noexcept |
| Convert an std::error_code to a std::string. More...
|
|
std::string | zakero::to_string (std::chrono::nanoseconds nanoseconds) noexcept |
| Convert nanoseconds into a string. More...
|
|
std::string | zakero::tolower (std::string str) noexcept |
| Convert a string to lower case. More...
|
|
template<class Type > |
bool | zakero::vectorContains (const std::vector< Type > &vector, const Type &value) noexcept |
| Check the contents of a std::vector. More...
|
|
template<class InputIter , class Type > |
bool | zakero::vectorContains (InputIter first, InputIter last, const Type &value) noexcept |
| Check the contents of a std::vector. More...
|
|
template<class Type > |
auto | zakero::vectorErase (std::vector< Type > &vector, const Type &value) noexcept |
| Erase the contents of a std::vector. 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
v0.9.4
v0.9.3
- Added stob()
- Added tolower()
- Added to_string(const bool)
- Added to_string(std::chrono::nanoseconds nanoseconds)
v0.9.2
v0.9.1
v0.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
int foobar = 1;
#define ZAKERO_CONCAT(thing_1_, thing_2_)
Concatenate the two things.
Definition: Zakero_Base.h:107
- Parameters
-
thing_1_ | Symbol left side |
thing_2_ | Symbol right side |
◆ ZAKERO_DELETE
#define ZAKERO_DELETE |
( |
|
ptr_ | ) |
|
Using this macro will help catch instances of using a pointer after delete'ing the new'ed memory. It does this by setting the value of ptr_
to nullptr
after calling delete
.
- Parameters
-
- Note
- The
++p
and p++
syntax should work:
ZAKERO_DELETE(p++); ZAKERO_DELETE(p++);
◆ ZAKERO_DISABLE_IMPLICIT_CASTS
#define ZAKERO_DISABLE_IMPLICIT_CASTS |
( |
|
func_name_ | ) |
|
When passing a value to a function's parameter which does not have a matching type, the compiler will try to inject code to convert the value into the function's expected type. Usually, this is fine. But in some instances can lead to very subtle bugs not to mention the possible minor hit in performance. Placing the function name in this macro will prevent the compiler from doing this automatic type conversion.
- Parameters
-
func_name_ | The name of the function. |
◆ ZAKERO_FREE
#define ZAKERO_FREE |
( |
|
ptr_ | ) |
|
Using this macro will help catch instances of using a pointer after free'ing the memory. It does this by setting the value of ptr_
to nullptr
after calling free().
- Parameters
-
- Note
- The
++p
and p++
syntax should work:
ZAKERO_FREE(p++); ZAKERO_FREE(p++);
◆ 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!
#endif
- Parameters
-
define_ | The defined macro to check. |
◆ ZAKERO_PID
Get the ID of the current process.
- Example
std::cout <<
"My PID is " << std::to_string(
ZAKERO_PID) <<
'\n';
#define ZAKERO_PID
Get the Process Id.
Definition: Zakero_Base.h:212
- Returns
- The Process Id (
pid_t
)
- Note
- POSIX.1-2008
◆ 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
namespace is automatically prepended to the unit_
.
- Example
#define ZAKERO_STEADY_TIME_NOW(unit_)
Get the current time.
Definition: Zakero_Base.h:231
- 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
namespace is automatically prepended to the unit_
.
- Example
#define ZAKERO_SYSTEM_TIME_NOW(unit_)
Get the current time.
Definition: Zakero_Base.h:252
- Parameters
-
unit_ | The time unit to get. |
◆ ZAKERO_UNUSED
#define ZAKERO_UNUSED |
( |
|
var_ | ) |
|
- Parameters
-
var_ | The "unused variable". |
◆ Storage
Sizes in powers of 2.
Enumerator |
---|
Byte | 1 byte
|
Kilobyte | 1024 bytes
|
Megabyte | 1024 kilobytes
|
Gigabyte | 1024 megabytes
|
Terabyte | 1024 gigabytes
|
Petabyte | 1024 terabytes
|
Exabyte | 1024 petabytes
|
◆ 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
);
uint64_t convert(const uint64_t size, const zakero::Storage from, const zakero::Storage to) noexcept
Convert storage sizes.
Definition: Zakero_Base.h:319
- 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 |
◆ equalish()
bool zakero::equalish |
( |
const float |
a, |
|
|
const float |
b, |
|
|
const float |
delta |
|
) |
| |
|
inlinenoexcept |
Compare two floats for some degree of equality. For the float values to be considered "equal", the difference between the values must be less than the specified delta
.
- Return values
-
true | The values are equal |
false | The values are not equal |
- Parameters
-
a | The first value |
b | The second value |
delta | The maximum difference |
◆ operator<<()
std::ostream& operator<< |
( |
std::ostream & |
stream, |
|
|
const std::error_code & |
error |
|
) |
| |
|
inlinenoexcept |
- Returns
- The
stream
.
- Parameters
-
stream | The stream to use |
error | The value in insert into the stream |
◆ stob()
bool zakero::stob |
( |
const std::string_view |
str | ) |
|
|
inlinenoexcept |
- Todo:
- Make the list of "true" string values convertible.
(Compile-Time or Run-Time?)
This is intended to be a complement to the std::stod() and std::stoi() family of functions. However, the main restriction is this method only accepts certain string values to represent a boolean true
value:
- "enable"
- "enabled"
- "true"
- "t"
- "yes"
- "y"
- "1" If the provided
str
is not one of the above strings, false
will be returned.
- Note
- The string comparison is not case-sensitive.
- Returns
- The string converted to a boolean value.
- Parameters
-
◆ to_string() [1/3]
std::string zakero::to_string |
( |
const bool |
value | ) |
|
|
inlinenoexcept |
Converts a bool value in to either "true" or "false".
- Returns
- A string
- Parameters
-
◆ to_string() [2/3]
std::string zakero::to_string |
( |
const std::error_code & |
error | ) |
|
|
inlinenoexcept |
The provided error
will be converted to a string.
- Returns
- A string
- Parameters
-
◆ to_string() [3/3]
std::string zakero::to_string |
( |
std::chrono::nanoseconds |
nanoseconds | ) |
|
|
inlinenoexcept |
The nanoseconds value will be converted into a string that contains "days", "hours", "minutes", "seconds", and (of course) "nanoseconds".
- Returns
- A string
- Parameters
-
◆ tolower()
std::string zakero::tolower |
( |
std::string |
str | ) |
|
|
inlinenoexcept |
The provided string, str
, will be converted to lower-case using the default locale.
- Returns
- The lower-case 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 };
{
}
bool vectorContains(const std::vector< Type > &vector, const Type &value) noexcept
Check the contents of a std::vector.
Definition: Zakero_Base.h:431
- 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 convenience 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 searching here |
value | The value to look for |
◆ vectorErase()
template<class Type >
auto zakero::vectorErase |
( |
std::vector< Type > & |
vector, |
|
|
const Type & |
value |
|
) |
| |
|
inlinenoexcept |
A convenience method to make removing content from a vector easier.
Uses the "Erase/Remove Idiom".
- Example
std::vector<int> v = { 0, 1, 2, 3 };
auto vectorErase(std::vector< Type > &vector, const Type &value) noexcept
Erase the contents of a std::vector.
Definition: Zakero_Base.h:503
- 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 |