Classes | Enumerations | Functions
ime::utility Namespace Reference

Container for all utility classes and functions. More...

Classes

class  ConsoleLogger
 Utility class for logging messages to the console. More...
 
class  DiskFileLogger
 Utility class for logging messages to a file on the disk. More...
 
class  DiskFileReader
 Reads/writes data to/from the disk. More...
 
class  ILogger
 Interface for logging classes. More...
 

Enumerations

enum class  WriteMode { Overwrite , Append }
 Modes in which a file can be written to in. More...
 
enum class  MessageType { General , Status , Warning , Error }
 Type of message to be logged. More...
 

Functions

IME_API float lerp (float min, float max, float ratio)
 Get a value between two other values on a linear scale. More...
 
IME_API int generateRandomNum (int min, int max)
 Generate a random number in a range. More...
 
static auto createRandomNumGenerator (int min, int max)
 Create a callable that generates random numbers in a range. More...
 
IME_API Colour generateRandomColour ()
 Create a random colour. More...
 
template<typename Callable , typename... Args>
void setTimeoutSync (Time delay, const Callable &callback, Args &&...args)
 Execute a one time callback function after a delay. More...
 
template<typename Callable , typename... Args>
void setTimeout (Time delay, const Callable &callback, Args &&...args)
 Execute a callback function once after a delay. More...
 
template<typename Callable , typename... Args>
void setIntervalSync (Time delay, const Callable &callback, Args &&...args)
 Execute a callback function repeatedly after a delay. More...
 
template<typename Callable , typename... Args>
void setInterval (Time delay, const Callable &callback, Args &&...args)
 Execute a callback function repeatedly after a delay. More...
 

Detailed Description

Container for all utility classes and functions.

Enumeration Type Documentation

◆ MessageType

enum class ime::utility::MessageType
strong

Type of message to be logged.

Enumerator
General 

General message.

Status 

Status reporting message.

Warning 

Warning message.

Error 

Error message.

Definition at line 35 of file ILogger.h.

◆ WriteMode

enum class ime::utility::WriteMode
strong

Modes in which a file can be written to in.

Enumerator
Overwrite 

Overwrites file content with new data.

Append 

Appends (At the end of file) new data to existing data.

Definition at line 38 of file DiskFileReader.h.

Function Documentation

◆ createRandomNumGenerator()

static auto ime::utility::createRandomNumGenerator ( int  min,
int  max 
)
static

Create a callable that generates random numbers in a range.

Parameters
minThe start of the range
maxThe end of the range
Returns
A callable object, when called returns a random number in the specified range

Definition at line 103 of file Utils.h.

◆ generateRandomColour()

IME_API Colour ime::utility::generateRandomColour ( )

Create a random colour.

Returns
A random colour

◆ generateRandomNum()

IME_API int ime::utility::generateRandomNum ( int  min,
int  max 
)

Generate a random number in a range.

Parameters
minThe start of the range
maxThe end of the range
Returns
A random number in the given range

◆ lerp()

IME_API float ime::utility::lerp ( float  min,
float  max,
float  ratio 
)

Get a value between two other values on a linear scale.

Parameters
minThe value to interpolate from
maxThe value to interpolate to
ratioThe interpolation point between 0 and 1 (inclusive)
Returns
The lerp value

This function is usually used to smoothen a value over time. For example it can be used to change the colour of something gradually over time or smoothly move an object to a new position (look up "linear interpolation" for more info).

The interpolation ratio is used to determine the point to be returned on the scale. It acts like a percentage between min and max:

auto value = lerp(0, 100.0f, 0.0f); Returns the minimum value
auto value = lerp(0, 100.0f, 1.0f); Returns the maximum value
auto value = lerp(0, 100.0f, 0.5f); Returns the 50.0f
auto value = lerp(0, 100.0f, 0.85f); Returns the 85.0f
// and so on ...
IME_API float lerp(float min, float max, float ratio)
Get a value between two other values on a linear scale.

To make the interpolation frame rate independent, multiply the lerp ration by the frame time

Note
This function does not account for situations where the interpolation point is less than 0 or greater than 1 or when the minimum value is greater than the maximum value. This means that the program will continue as normal, you may experience an unexpected behavior
void update(Time deltaTime) {
// Move the sprite from its current x position to 50.0f by a ratio
// of 0.3f per update
sprite.setPosition(lerp(sprite.getX(), 50.0f, 0.3f), sprite.getY());
// Move the sprite from its current x position to 50.0f by a ratio
// of 0.3f per frame
sprite.setPosition(lerp(sprite.getX(), 50.0f, 0.3f * deltaTime.asMilliseconds()),
sprite.getY());
}
Represents a time value.
Definition: Time.h:35
Int32 asMilliseconds() const
Get the time value in milliseconds.

◆ setInterval()

template<typename Callable , typename... Args>
void ime::utility::setInterval ( Time  delay,
const Callable &  callback,
Args &&...  args 
)

Execute a callback function repeatedly after a delay.

Parameters
delayTime to wait before executing callback
callbackFunction to execute
argsArguments to pass to the callback on invocation

The callback execution is done in a separate thread, therefore this function is not blocking. It will return immediately after initiating the new thread. The callback function will execute forever every delay milliseconds. The interval can be stopped by setting the first argument of the callback to false. This argument must be taken by reference otherwise the callback will continue executing.

Note
Provided arguments will be passed to the callback after the first bool argument which is provided by this function, therefore the callback must take at least one argument of type bool&

◆ setIntervalSync()

template<typename Callable , typename... Args>
void ime::utility::setIntervalSync ( Time  delay,
const Callable &  callback,
Args &&...  args 
)

Execute a callback function repeatedly after a delay.

Parameters
delayTime to wait before executing callback
callbackFunction to execute
argsArguments passed to the callback function on invocation

This function is blocking as the current thread will wait for the callback execution to finish. The callback function will execute forever every delay milliseconds. The interval can be stopped by setting the first argument of the callback to false. This argument must be taken by reference otherwise the callback will continue executing

Note
Provided arguments will be passed to the callback after the first bool argument which is provided by this function, therefore the callback must take at least one argument of type bool&

◆ setTimeout()

template<typename Callable , typename... Args>
void ime::utility::setTimeout ( Time  delay,
const Callable &  callback,
Args &&...  args 
)

Execute a callback function once after a delay.

Parameters
delayTime to wait before executing callback
callbackFunction to execute
argsArguments passed to the callback function on invocation

The callback execution is done in a separate thread, therefore this function is not blocking. It will return immediately after initiating the new thread

◆ setTimeoutSync()

template<typename Callable , typename... Args>
void ime::utility::setTimeoutSync ( Time  delay,
const Callable &  callback,
Args &&...  args 
)

Execute a one time callback function after a delay.

Parameters
delayTime to wait before executing callback
callbackCallback function to execute
argsArguments passed to the callback function on invocation

This function is blocking as the current thread will wait for the callback execution to finish. The countdown is initiated right away