Common Utilities - simple-entertainment/simplicity GitHub Wiki

Useful stuff that isn't really specific to one area or another.

Categories

Many of the APIs in simplicity use categories as a means of grouping objects. The standard categories are defined in common/Category.h.

Checking for Address Equality

The AddressEquals class is a predicate that can be used to check for address equality. The main use case I have found for this is when trying to find an object with a particular address in a vector of smart pointers. Here is an example of it's use:

std::vector<std::shared_ptr<Entity>> entities;
// Add entities to the vector...
Entity* entity = /* Some entity */
find_if(entities.begin(), entities.end(), AddressEquals<Entity>(*entity));

Non-Copyable

If you don't want your class to be copyable then just extend NonCopyable:

class MyClass : private NonCopyable
{
    ...
};

MyClass a;
MyClass b = a; // Compile-time error! Copy constructor is private.
MyClass c;
c = a; // Compile-time error! Copy assignment operator is private.

Timing

The Timer class provides a simple but high precision timer.

Timer timer;
// Do stuff...
float elapsedTime = timer.getElapsedTime() // Retrieve the amount of time it took to do stuff (in seconds)

You can even pause and reset the timer:

timer.pause();
// Do stuff you don't want to time...
timer.resume();

// Finished timing something, reset the timer for re-use.
timer.reset();
⚠️ **GitHub.com Fallback** ⚠️