Contents
Miscellaneous utilities

Introduction

This chapter documents small, miscellaneous types and utilities that are provided in Balau.

Assert

#include <Balau/Dev/Assert.hpp>

The Assert namespace class contains a set of runtime assertions used for development purposes. The assertions use the standard assert() call.

Enums

#include <Balau/Util/Enums.hpp>

The Enums namespace class currently contains a single static method:

			///
			/// Convert the strongly typed enum to its underlying integer.
			///
			template <typename E>
			static auto toUnderlying(E e) noexcept -> typename std::underlying_type<E>::type {
				return static_cast<typename std::underlying_type<E>::type>(e);
			}
		

The toUnderlying method provides a clear indication in source code that the underlying integer value of the enum class is being obtained.

Hashing

#include <Balau/Util/Hashing.hpp>

The Hashing class is a namespace class used to hold hashing functions. There are three versions of each function, one accepting a File, another accepting a string, and a third accepting an istream.

The following hash algorithms are supported:

Macros

#include <Balau/Util/Macros.hpp>

The Macros.hpp header file contains some low level macros used in Balau.

OnScopeExit

#include <Balau/Type/OnScropeExit.hpp>
#include <Balau/Type/MoveableOnScropeExit.hpp>

The two classes OnScopeExit and MovableOnScopeExit provide RAII style management containers. The MovableOnScopeExit version is movable out of a scope without triggering the stored function.

An instance of OnScopeExit is created by supplying a function or lambda expression to the constructor. This function will be run from the destructor of the stack based object when the enclosing scope exits.

			// Example usage of OnScopeExit class.

			{
				Balau::OnScopeExit cleanUp([this] () { runCleanup(); })

				// ... more code ...

			} // runCleanup() will be run here.
		

One interesting property of the MovableOnScopeExit implementation is that instances may be moved out of the scope via the move constructor. This allows a MovableOnScopeExit instance to be created inside a function and then returned to the caller on the stack, ready for destruction when the caller's scope exits.

The OnScopeExit and MovableOnScopeExit implementations are small classes, each class consisting of approximately 20 lines of code. Internally, the OnScopeExit implementation is based on a std::function stack based internal object and the MovableOnScopeExit implementation is based on a heap based internal object, managed inside a std::unique_ptr.

UUID

#include <Balau/Type/UUID.hpp>

The UUID class provides a convenient API for generating and manipulating UUIDs.

User

#include <Balau/Util/User.hpp>

The User class is a namespace class destined for functions that provide information on operating system users.

Currently, the User class contains a single getHomeDirectory function that makes a best effort attempt at returning the user's home directory for each supported platform.

App

#include <Balau/Util/App.hpp>

The App class is a namespace class destined for functions that provide general information for a running application.

The following functions are currently defined.

			struct App {
				static File getUserApplicationDataDirectory(const std::string & appGroup, const std::string & appName);
				static File getGlobalApplicationDataDirectory(const std::string & appGroup, const std::string & appName);
				static File getUserApplicationConfigDirectory(const std::string & appGroup, const std::string & appName);
				static File getGlobalApplicationConfigDirectory(const std::string & appGroup, const std::string & appName);
				static File getApplicationRuntimeDataDirectory(const std::string & appGroup, const std::string & appName);
			};
		

The appGroup and appName strings provide the application's group name and identification name. These are used in the construction of the directory paths. The paths returned from these functions depend on the platform. Depending on the platform, the returned paths depend on the program binary's location, the user's identification, ${XDG_DATA_HOME}, ${HOME}, ${XDG_CONFIG_HOME}, and/or ${XDG_RUNTIME_DIR} environment variables, %USERPROFILE%, %HOMEDRIVE%, %HOMEPATH%, and/or GetTempPath() on Windows. See the API documentation for more details.

Note that these functions are not yet implemented for platforms other than Unix like platforms. Pull requests for other platforms are welcome.