A small library of utilities, created for my own purposes. In some parts it's nothing more than a very simple wrapper around other libraries.
- SPK_Log
- libuuid1
- libscrypt
- Catch2 (not required if you skip the tests as described below)
$ make all
builds and runs tests.
$ make build
just builds.
# make install
, which by default uses DESTDIR=/usr
, I recommend setting DESTDIR
to install somewhere else.
The library uses 3 headers
spk_utils/error.hpp
spk_utils/hash.hpp
spk_utils/uuid.hpp
Each header defines its own namespacespk::err
spk::hash
spk::uuid
This utility just reduces boilerplate when defining exceptions in C++.
Defines a very simple class spk::err::Error
which extends std::exception
. It also defines a macro SPK_ERR(id, message)
. Calling SPK_ERR
defines a new class that extends spk::err::Error
, called id
and that returns message
from what()
.
When the generated class is instantiated, it also uses SPK_Log to write a message to your current log file (if you aren't using SPK_Log other than as a dependency to this, it will write to log.log
.
This utility is merely a simpler API around libscrypt. It can hash text and check whether a string matches an existing hash.
Two functions are defined, that work exactly as you would expect.
std::string spk::hash::hash (std::string to_hash)
- can throwspk::hash::Hash_Failed
.bool spk::hash::check_hash (std::string to_check, std::string hash)
- can throwspk::hash::Check_Hash_Failed
.
This utility is an API around libuuid1. It defines a UUID class for more easily managing your UUIDs.
The following static functions are defined:
spk::uuid::UUID spk::uuid::create ()
- creates a new, random UUID.spk::uuid::UUID spk::uuid::read (std::string text)
- creates a new UUID from a human-readable string (i.e.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
). Can throwspk::uuid::UUID_Error
.
The UUID class has two constructors:
spk::uuid::UUID()
- creates an 'empty' UUID.spk::uuid::UUID(std::string data)
- creates a UUID containingdata
, which should be a 16-byte string (i.e. not a human-readable UUID). This is useful for reading UUIDs from databases, streams, or anywhere else it makes sense to use binary data. Note that this does not check thatdata
is a valid UUID. If this is the case, an exception will only be thrown when attempting to convert it to a human-readable string.
, two getter methods:
std::string spk::uuid::UUID::get()
- returns the binary data of the UUID (16 bytes if the UUID is valid, see above). ThrowsUnset_UUID
if the UUID is empty.std::string spk::uuid::UUID::to_string()
- returns a human-readable representation of the UUID (36 bytes). ThrowsUnset_UUID
if the UUID is 'empty'.
and operators:
==
and!=
- will treat two 'empty' UUIDs as equal.bool
- UUIDs arefalse
if 'empty',true
otherwise.