Zakero's C++ Header Libraries
A collection of reusable C++ libraries
Macros | Enumerations | Functions
Zakero_Base.h File Reference

Zakero Base. More...

Include dependency graph for Zakero_Base.h:

Go to the source code of this file.

Macros

#define ZAKERO_CONCAT(thing_1_, thing_2_)
 Concatenate the two things. More...
 
#define ZAKERO_MACRO_HAS_VALUE(define_)
 Check if a macro has a value. More...
 
#define ZAKERO_STEADY_TIME_NOW(unit_)
 Get the current time. More...
 
#define ZAKERO_SYSTEM_TIME_NOW(unit_)
 Get the current time. More...
 

Enumerations

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...
 

Functions

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...
 
std::string zakero::to_string (const std::error_code &error) noexcept
 Convert an std::error_code to a std::string. 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...
 

Detailed Description

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

  • The initial collection
Author
Andrew "Zakero" Moore
  • Original Author

Macro Definition Documentation

◆ 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;
ZAKERO_CONCAT(foo, bar)++; // foobar == 2
int ZAKERO_CONCAT(magic_, 42) = 123;
// int magic_42 = 123;
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
auto time_now = ZAKERO_STEADY_TIME_NOW(milliseconds);
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
auto time_now = ZAKERO_SYSTEM_TIME_NOW(milliseconds);
Parameters
unit_The time unit to get.

Enumeration Type Documentation

◆ Storage

enum zakero::Storage : uint64_t
strong

Sizes in powers of 2.

Function Documentation

◆ convert() [1/2]

double zakero::convert ( const double  size,
const zakero::Storage  from,
const zakero::Storage  to 
)
inlinenoexcept

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
double bytes = zakero::convert(double(16)
, zakero::Storage::Gigabyte
, zakero::Storage::Byte
);
double megs = zakero::convert(double(16)
, zakero::Storage::Kilobyte
, zakero::Storage::Megabyte
);
Returns
The converted value.
Parameters
sizeThe size to convert
fromThe source unit
toThe destination unit

◆ convert() [2/2]

uint64_t zakero::convert ( const uint64_t  size,
const zakero::Storage  from,
const zakero::Storage  to 
)
inlinenoexcept

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
uint64_t bytes = zakero::convert(uint64_t(16)
, zakero::Storage::Gigabyte
, zakero::Storage::Byte
);
uint64_t megs = zakero::convert(uint64_t(16)
, zakero::Storage::Kilobyte
, zakero::Storage::Megabyte
);
// megs == 0
Returns
The converted value.
Parameters
sizeThe size to convert
fromThe source unit
toThe 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
errorThe value

◆ 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 };
if(vectorContains(v, 1))
{
// Found it
}
Return values
trueThe value was found.
falseThe value was not found.
Parameters
vectorThe vector to search
valueThe 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(vectorContains(std::begin(v), std::end(v), 1)
{
// Found it
}
// Compare with the "long" form, the
// value that is searhed for gets lost
// very easily.
if(std::find(std::begin(v), std::end(v), 1) != std::end(v))
{
// Found it
}
Return values
trueThe value was found.
falseThe value was not found.
Parameters
firstStart searching here
lastStop seaching here
valueThe 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 };
// v = { 0, 1, 3 };
Return values
trueThe value was found.
falseThe value was not found.
Parameters
vectorThe vector to search
valueThe value to look for
ZAKERO_SYSTEM_TIME_NOW
#define ZAKERO_SYSTEM_TIME_NOW(unit_)
Get the current time.
Definition: Zakero_Base.h:140
zakero::convert
double convert(const double size, const zakero::Storage from, const zakero::Storage to) noexcept
Convert storage sizes.
Definition: Zakero_Base.h:234
ZAKERO_STEADY_TIME_NOW
#define ZAKERO_STEADY_TIME_NOW(unit_)
Get the current time.
Definition: Zakero_Base.h:121
zakero::vectorContains
bool vectorContains(const std::vector< Type > &vector, const Type &value) noexcept
Check the contents of a std::vector.
Definition: Zakero_Base.h:267
ZAKERO_CONCAT
#define ZAKERO_CONCAT(thing_1_, thing_2_)
Concatenate the two things.
Definition: Zakero_Base.h:84
zakero::vectorErase
auto vectorErase(std::vector< Type > &vector, const Type &value) noexcept
Erase the contents of a std::vector.
Definition: Zakero_Base.h:338