Pasha Bibko Util Library
Loading...
Searching...
No Matches
PashaBibko::Util Namespace Reference

Classes

struct  DefaultError
 Default error class for Uti::ReturnVal. More...
 
struct  FileReadError
 Error returned when PashaBibko::Util::ReadFile() fails. More...
 
struct  FunctionFail
 Class to create when a function fails. More...
 
class  ReturnVal
 Class to return a result from a function that can fail. More...
 
struct  StringLocation
 Location within a string. More...
 
struct  Vec
 Mathmatical vector class. More...
 

Enumerations

enum class  Colour : unsigned short {
  Default = 0x07 , Black = 0x00 , Blue = 0x01 , Green = 0x02 ,
  Aqua = 0x03 , Red = 0x04 , Purple = 0x05 , Yellow = 0x06 ,
  LightGray = 0x07 , LightBlue = 0x09 , LightGreen = 0x0a , LightAqua = 0x0b ,
  LightRed = 0x0c , LightPurple = 0x0d , LightYellow = 0x0e , White = 0x0f
}
 Representation of each color and its corresponding Win32 console color code. Other operating systems use a switch statement to translate the codes from Win32 to their values. More...
 

Functions

template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::AddResultT<LhsTy, RhsTy>>
requires Internal::CanAdd<LhsTy, RhsTy>
Vec< len, ResTyoperator+ (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Adds two vectors together.
 
template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::SubResultT<LhsTy, RhsTy>>
requires Internal::CanSub<LhsTy, RhsTy>
Vec< len, ResTyoperator- (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Subtracts the right vector by the left vector.
 
template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::MulResultT<LhsTy, RhsTy>>
requires Internal::CanMul<LhsTy, RhsTy>
Vec< len, ResTyoperator* (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Multiplies two vectors together.
 
template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::SubResultT<LhsTy, RhsTy>>
requires Internal::CanDiv<LhsTy, RhsTy>
Vec< len, ResTyoperator/ (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Divides the left vector by the right vector.
 
template<std::size_t len, typename LhsTy , typename RhsTy >
requires Internal::CanEqualityCheck<LhsTy, RhsTy>
bool operator== (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Checks if two vectors are equal.
 
template<std::size_t len, typename LhsTy , typename RhsTy >
requires Internal::CanEqualityCheck<LhsTy, RhsTy>
bool operator!= (const Vec< len, LhsTy > &lhs, const Vec< len, RhsTy > &rhs)
 Checks if two vectors are not equal.
 
ReturnVal< std::string, FileReadErrorReadFile (const std::filesystem::path &path)
 Reads a file to a string.
 
StringLocation GetLocationAtStringIndex (const std::string &string, uint32_t index)
 Finds the location of [colummn, line] of a given index.
 
template<Colour colour = Colour::Default, typename... Args>
requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
void Print (Args &&... args)
 Prints the message to the console.
 
template<typename... Args>
requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
void Log (Args &&... args)
 Logs the message to the log file and console.
 
void SetConsoleColor (Colour col)
 Sets the console to display text with a certain color.
 
void TriggerBreakpoint ()
 Triggers a breakpoint if there is a Debugger to attach to.
 
void EndProcess (bool breakpoint=true)
 Ends the current process.
 

Enumeration Type Documentation

◆ Colour

Representation of each color and its corresponding Win32 console color code. Other operating systems use a switch statement to translate the codes from Win32 to their values.

Enumerator
Default 

The default colour of the console.

Black 

Black

Blue 

Blue

Green 

Green

Aqua 

Aqua

Red 

Red

Purple 

Purple

Yellow 

Yellow

LightGray 

Light Gray

LightBlue 

Light Blue

LightGreen 

Light Green

LightAqua 

Light Aqua

LightRed 

Light Red

LightPurple 

Light Purple

LightYellow 

Light Yellow

White 

White

Function Documentation

◆ EndProcess()

void EndProcess ( bool  breakpoint = true)

Ends the current process.

Parameters
breakpointIf true will trigger a breakpoint before exiting (defaults to true)

◆ GetLocationAtStringIndex()

StringLocation GetLocationAtStringIndex ( const std::string &  string,
uint32_t  index 
)

Finds the location of [colummn, line] of a given index.

Parameters
stringThe string that will be searched for the index.
indexThe index that the location will be returned.
Note
If the index is outside the bounds of the string it will return { 0, 0 } instead of a valid location.

◆ Log()

template<typename... Args>
requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
void Log ( Args &&...  args)
inline

Logs the message to the log file and console.

See PashaBibko::Util::Print() for how different types can be logged. Log() also has a function overload for printing ranges. Any type that can be iterated over using begin() and end() such as std::array or std::vector. It also requires that type that is returned whilst iterating is also loggable. For example:

struct A
{
// Empty //
}
struct B
{
std::string LogStr() const
{
return "Custom Log function called";
}
}
int main()
{
// Invalid because A cannot be logged //
std::array<A, 5> array_A{};
Util::Log(array_A);
// Valid because B can be logged //
std::array<B, 5> array_B{};
Util::Log(array_B);
}
void Log(Args &&... args)
Logs the message to the log file and console.
Definition Log.h:191
Mathmatical vector class.
Definition Vec.h:216
Vec()
Default constructor which default constructs all items.
Definition Vec.h:224
  • args The message that it will log to a file.

◆ operator!=()

template<std::size_t len, typename LhsTy , typename RhsTy >
requires Internal::CanEqualityCheck<LhsTy, RhsTy>
bool operator!= ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Checks if two vectors are not equal.

Requires both the == and != operators to be available for both types.

◆ operator*()

template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::MulResultT<LhsTy, RhsTy>>
requires Internal::CanMul<LhsTy, RhsTy>
Vec< len, ResTy > operator* ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Multiplies two vectors together.

Requires the two types contained in the vector to be able to be multiplied together. The result type will also be the same type as when they are normally multiplied together.

◆ operator+()

template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::AddResultT<LhsTy, RhsTy>>
requires Internal::CanAdd<LhsTy, RhsTy>
Vec< len, ResTy > operator+ ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Adds two vectors together.

Requires the two types contained in the vector to be able to be added together. The result type will also be the same type as when they are normally added together.

◆ operator-()

template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::SubResultT<LhsTy, RhsTy>>
requires Internal::CanSub<LhsTy, RhsTy>
Vec< len, ResTy > operator- ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Subtracts the right vector by the left vector.

Requires the two types contained in the vector to be able to be subtracted from each other The result type will also be the same type as when they are normally subtracted.

◆ operator/()

template<std::size_t len, typename LhsTy , typename RhsTy , typename ResTy = Internal::SubResultT<LhsTy, RhsTy>>
requires Internal::CanDiv<LhsTy, RhsTy>
Vec< len, ResTy > operator/ ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Divides the left vector by the right vector.

Requires the two types contained in the vector to be able to be divided from each other. The result type will also be the same type as when they are normally divided together.

◆ operator==()

template<std::size_t len, typename LhsTy , typename RhsTy >
requires Internal::CanEqualityCheck<LhsTy, RhsTy>
bool operator== ( const Vec< len, LhsTy > &  lhs,
const Vec< len, RhsTy > &  rhs 
)

Checks if two vectors are equal.

Requires both the == and != operators to be available for both types.

◆ Print()

template<Colour colour = Colour::Default, typename... Args>
requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
void Print ( Args &&...  args)
inline

Prints the message to the console.

Types can be printed in 2 different ways. The first is if the type has a std::ostream& bit-shift operator overload defined. This is the operator that std::cout uses for outputting so will be used by all intergral types.

The second way is by having a LogStr() method that returns a string. Below are some examples of logging with these methods.

{
std::string LogStr() const // Function is required to be const //
{
return "Custom Log method called";
}
}
int main()
{
// Using the std::ostream& << operator //
Util::Print("Hello, World! ", 3);
// Using the LogStr() function //
LogableExample object;
Util::Print(object);
return 0;
}
void Print(Args &&... args)
Prints the message to the console.
Definition Log.h:140

Instead of adding a new line('
') character at the end of the message you can use Util::PrintLn which will automatically apend it for you.

Template Parameters
colour(Optional) the color that it will print to the console in.
  • args The arguments that will be printed to the console.

◆ ReadFile()

ReturnVal< std::string, FileReadError > ReadFile ( const std::filesystem::path &  path)

Reads a file to a string.

Will check if the file path is valid and will return a FileReadError with a relevant error if invalid.

Parameters
pathFile path to read from

◆ SetConsoleColor()

void SetConsoleColor ( Colour  col)

Sets the console to display text with a certain color.

Supported on Windows and UNIX based operating systems. If it is unable to set the color it will silently fail.

Parameters
colThe color that the console will be set to.

◆ TriggerBreakpoint()

void TriggerBreakpoint ( )

Triggers a breakpoint if there is a Debugger to attach to.

Calls DebugBreak() on Windows or std::raise(SIGTRAP) on Linux based systems. On windows will check if there is a debugger attached but will not on Linux.