Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively included in almost every translation unit.
Definition in file util.hpp.
#include "include/limits.h"
#include "lib/hash-standard.hpp"
#include <set>
#include <string>
#include <algorithm>
Macros | |
#define | __STRNGFY(TOKEN) #TOKEN |
#define | INSTANCEOF(CLASS, EXPR) (dynamic_cast<const CLASS*> (EXPR)) |
shortcut for subclass test, intended for assertions only. More... | |
#define | MAX(A, B) ((A < B) ? (B) : (A)) |
the inevitable MAX macro, sometimes still necessary in template code | |
#define | SIDEEFFECT __attribute__ ((unused)); |
suppress "warning: unused variable" on vars, which are introduced into a scope because of some sideeffect, i.e. More... | |
#define | STRINGIFY(TOKEN) __STRNGFY(TOKEN) |
this macro wraps its parameter into a cstring literal | |
Functions | |
template<typename MAP > | |
MAP::mapped_type const & | access_or_default (MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type const &refDefault) |
expose a reference to a map entry, with fall-back to some default object More... | |
bool | boolVal (string const &) |
interpret text representation of a boolean value. More... | |
template<typename MAP > | |
bool | contains (MAP &map, typename MAP::key_type const &key) |
shortcut for containment test on a map | |
template<typename T > | |
bool | contains (std::set< T > const &set, T const &val) |
shortcut for set value containment test | |
template<typename T > | |
bool | contains (std::string const &str, const T &val) |
shortcut for string value containment test | |
template<typename SEQ > | |
bool | contains (SEQ const &cont, typename SEQ::const_reference val) |
shortcut for brute-force containment test in any sequential container | |
const char * | cStr (string const &org) |
convenience shortcut: conversion to c-String via string. More... | |
bool | endsWith (string const &str, string const &suffix) |
check if string ends with the given suffix | |
bool | endsWith (string const &str, const char *suffix) |
template<class X > | |
const void * | getAddr (X &x) |
extract address but strip any type info | |
template<class X > | |
const void * | getAddr (X *x) |
template<typename MAP > | |
MAP::mapped_type | getValue_or_default (MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type defaultVal) |
fetch value from a Map, or return a default if not found | |
template<class CONT > | |
bool | isnil (const CONT &container) |
a family of util functions providing a "no value whatsoever" test. More... | |
template<class CONT > | |
bool | isnil (const CONT *pContainer) |
template<class CONT > | |
bool | isnil (CONT *pContainer) |
bool | isnil (const char *pCStr) |
template<class A , class B > | |
bool | isSameObject (A const &a, B const &b) |
compare plain object identity, bypassing any custom comparison operators. | |
bool | isYes (string const &) noexcept |
check the given text if it can be interpreted as affirmative answer (bool true ). More... | |
template<typename NUM , typename NB > | |
NUM | limited (NB lowerBound, NUM val, NB upperBound) |
force a numeric to be within bounds, inclusively | |
template<class IT > | |
bool | linearSearch (IT iter, typename IT::value_type const &val) |
use (and exhaust) a »Lumiera Forward Iterator« for linear search | |
template<class N1 , class N2 > | |
N1 | max (N1 n1, N2 n2) |
template<class N1 , class N2 > | |
N1 | min (N1 n1, N2 n2) |
template<typename NUM > | |
NUM | noneg (NUM val) |
cut a numeric value to be >=0 | |
template<class SET , typename FUN > | |
bool | remove_if (SET &set, FUN test) |
remove all elements fulfilling a given predicate from a (sorted) set. More... | |
template<typename SEQ > | |
SEQ::iterator | removeall (SEQ &coll, typename SEQ::value_type const &val) |
shortcut for removing all copies of an Element in any sequential collection | |
void | removePrefix (string &str, string const &prefix) |
void | removeSuffix (string &str, string const &suffix) |
std::string | sanitise (string const &org) |
produce an identifier based on the given string. More... | |
template<class NUM > | |
int | sgn (NUM n) |
int | sNum (const char *pCStr) |
int | sNum (string const &spec) |
bool | startsWith (string const &str, string const &prefix) |
check if string starts with a given prefix | |
bool | startsWith (string const &str, const char *prefix) |
string | trim (string const &org) |
remove leading and trailing whitespace More... | |
template<class OBJ > | |
OBJ * | unConst (const OBJ *o) |
shortcut to save some typing when having to define const and non-const variants of member functions | |
template<class OBJ > | |
OBJ & | unConst (OBJ const &ro) |
uint | uNum (const char *pCStr) |
positive integral number from textual representation More... | |
uint | uNum (string const &spec) |
#define SIDEEFFECT __attribute__ ((unused)); |
#define INSTANCEOF | ( | CLASS, | |
EXPR | |||
) | (dynamic_cast<const CLASS*> (EXPR)) |
shortcut for subclass test, intended for assertions only.
Definition at line 447 of file util.hpp.
Referenced by VerbPack< REC, RET, arg_storage >::accessArg(), stage::timeline::anonymous_namespace{clip-widget.cpp}::buildDelegateFor(), Dispatcher< TAR, TOOL >::callTrampoline(), CustomSharedPtr_test::check_type_relations(), ClonedContext::downcast(), PlacementIndexQueryResolver::resolutionFunction(), MockSupport_test::verify_MockJobTicket(), and ElementAccess_test::verify_simpleAccess().
|
inline |
|
inline |
|
inline |
expose a reference to a map entry, with fall-back to some default object
Definition at line 267 of file util.hpp.
References util::access_or_default().
Referenced by util::access_or_default().
bool util::remove_if | ( | SET & | set, |
FUN | test | ||
) |
remove all elements fulfilling a given predicate from a (sorted) set.
Definition at line 294 of file util.hpp.
References util::remove_if().
Referenced by util::remove_if(), and RemoveFromSet_test::test_remove().
string sanitise | ( | string const & | org | ) |
produce an identifier based on the given string.
remove non-standard-chars, reduce sequences of punctuation and whitespace to single underscores. The sanitised string will start with an alphanumeric character.
"Word" --> "Word" "a Sentence" --> "a_Sentence" "trailing Withespace \t \n" --> "trailing_Withespace" "with a lot \nof Whitespace" --> "with_a_lot_of_Whitespace" "@with\".\'much ($punctuation)[]!" --> "@with.much_($punctuation)" "§&Ω%€ leading garbage" --> "leading_garbage" "mixed Ω garbage" --> "mixed_garbage" "Bääääh!!" --> "Bh"
Definition at line 65 of file util.cpp.
References util::isValid(), and util::sanitise().
Referenced by util::sanitise().
string trim | ( | string const & | org | ) |
remove leading and trailing whitespace
Definition at line 93 of file util.cpp.
References util::trim().
Referenced by util::trim().
bool boolVal | ( | string const & | ) |
interpret text representation of a boolean value.
true
for the tokens "true", "True", "TRUE", "yes", "Yes", "YES", "1", "+"false
for the tokens "false", "False", "FALSE", "no", "No, "NO", "0", "-"lumiera::error::Invalid | for any other text content |
Definition at line 107 of file util.cpp.
References util::boolVal().
Referenced by util::boolVal().
|
noexcept |
check the given text if it can be interpreted as affirmative answer (bool true
).
true
tokens and interprets all other content as false
, including empty strings. Never throws. Definition at line 116 of file util.cpp.
References util::isYes().
Referenced by util::isYes().
|
inline |
convenience shortcut: conversion to c-String via string.
usable for printf with objects providing to-string conversion.
Definition at line 423 of file util.hpp.
References util::cStr().
Referenced by util::cStr().