49 template<
typename K,
typename CMP,
class ALLO>
52 template<
typename IT,
typename V>
53 IT find (IT, IT, V
const&);
54 template<
typename IT,
typename V>
55 IT
remove (IT, IT, V
const&);
59 const char*
cStr (std::string
const&);
66 using CStr =
const char*;
73 return (n==0)? 0 :((n<0)? -1:+1 );
76 template <
class N1,
class N2>
80 return n2 < n1? N1(n2) : n1;
83 template <
class N1,
class N2>
87 return n1 < n2? N1(n2) : n1;
91 template <
typename NUM>
95 return (0<val? val : 0);
99 template <
typename NUM,
typename NB>
101 limited (NB lowerBound, NUM val, NB upperBound)
103 return min ( max (val, lowerBound)
107 template <
typename NUM,
typename NB>
108 inline bool constexpr
109 isLimited (NB lowerBound, NUM val, NB upperBound)
111 return lowerBound <= val
112 and val <= upperBound;
121 if (!charPtr)
return 0;
122 int parsedNumber (std::atoi (charPtr));
123 return limited (0, parsedNumber, LUMIERA_MAX_ORDINAL_NUMBER);
129 if (!charPtr)
return 0;
130 int parsedNumber (std::atoi (charPtr));
131 return limited (-LUMIERA_MAX_ORDINAL_NUMBER, parsedNumber, LUMIERA_MAX_ORDINAL_NUMBER);
136 uNum (OBJ
const& spec)
143 sNum (OBJ
const& spec)
145 return sNum (
cStr(spec));
154 template <
class CONT>
156 isnil (
const CONT& container)
158 return container.empty();
161 template <
class CONT>
163 isnil (
const CONT* pContainer)
165 return !pContainer or pContainer->empty();
168 template <
class CONT>
170 isnil (CONT* pContainer)
172 return !pContainer or pContainer->empty();
178 return !charPtr or !(*charPtr);
187 return 0 == str.rfind (prefix, 0);
193 return 0 == str.rfind (prefix, 0);
200 size_t l = suffix.length();
201 if (l > str.length())
return false;
202 size_t pos = str.length() - l;
203 return pos == str.find (suffix, pos);
207 endsWith (
string const& str, CStr suffix)
209 return endsWith (str,
string(suffix));
213 removePrefix (
string& str,
string const& prefix)
216 str = str.substr (prefix.length());
220 removeSuffix (
string& str,
string const& suffix)
222 if (not
endsWith (str,suffix))
return;
223 str.resize(str.length() - suffix.length());
228 template <
typename MAP>
230 contains (MAP& map,
typename MAP::key_type
const& key)
232 return map.find(key) != map.end();
236 template <
typename T,
class CMP,
class ALO>
238 contains (std::set<T,CMP,ALO>
const&
set, T
const& val)
240 return set.end() !=
set.find (val);
244 template <
typename T>
248 return str.find (val) != std::string::npos;
253 template <
typename SEQ>
255 contains (SEQ
const& cont,
typename SEQ::const_reference val)
257 typename SEQ::const_iterator begin = cont.begin();
258 typename SEQ::const_iterator end = cont.end();
260 return end != std::find(begin,end, val);
269 return end != std::find (std::move (iter), end, val);
273 template <
typename MAP>
274 inline typename MAP::mapped_type
276 ,
typename MAP::mapped_type defaultVal)
278 typename MAP::const_iterator pos = map.find (key);
279 if (pos != map.end())
290 template <
typename MAP>
291 inline typename MAP::mapped_type
const &
293 ,
typename MAP::mapped_type
const& refDefault)
295 typename MAP::const_iterator pos = map.find (key);
296 if (pos != map.end())
304 template <
typename SEQ>
305 inline typename SEQ::iterator
306 removeall (SEQ& coll,
typename SEQ::value_type
const& val)
308 typename SEQ::iterator collEnd = coll.end();
309 return coll.erase (std::remove (coll.begin(), collEnd, val),
318 template<
class SET,
typename FUN>
321 typedef typename SET::iterator Itor;
323 Itor end =
set.end();
324 Itor begin =
set.begin();
336 pos = begin =
set.begin();
356 return const_cast<OBJ*
> (o);
363 return const_cast<OBJ&
> (ro);
370 template<
class A,
class B>
374 return static_cast<const void*
> (std::addressof(a))
375 == static_cast<const void*> (std::addressof(b));
383 return static_cast<const void*
> (std::addressof(x));
389 return static_cast<const void*
> (x);
397 return reinterpret_cast<size_t> (std::addressof(x)) /
sizeof(
size_t);
403 return reinterpret_cast<size_t> (x) /
sizeof(
size_t);;
411 template<
typename A,
typename B>
415 size_t loc1 =
slotNr (std::forward<A> (a));
416 size_t loc2 =
slotNr (std::forward<B> (b));
417 size_t dist = loc2 > loc1? loc2-loc1:loc1-loc2;
418 return dist < consideredNearby;
443 string sanitise (
string const& org);
449 string trim (
string const& org);
466 bool isYes (
string const&) noexcept;
472 bool isNo (
string const&) noexcept;
483 #define SIDEEFFECT __attribute__ ((unused)); 486 #define STRINGIFY(TOKEN) __STRNGFY(TOKEN) 487 #define __STRNGFY(TOKEN) #TOKEN 492 #define INSTANCEOF(CLASS, EXPR) (dynamic_cast<const CLASS*> (EXPR)) 495 #ifndef MAX // this is present to make this definition play nice with GLib 496 #define MAX(A,B) ((A < B) ? (B) : (A))
const char * cStr(std::string const &)
convenience shortcut: forced conversion to c-String via string.
bool isYes(string const &textForm) noexcept
check the given text if it can be interpreted as affirmative answer (bool true).
const void * getAddr(X &x)
extract address but strip any type info
bool startsWith(string const &str, string const &prefix)
check if string starts with a given prefix
bool isCloseBy(A &&a, B &&b, size_t consideredNearby=50)
determine heuristically if two objects are located „close to each other“ in memory.
std::string sanitise(std::string const &)
produce an identifier based on the given string.
hard wired safety limits.
bool boolVal(string const &textForm)
interpret text representation of a boolean value.
NUM constexpr noneg(NUM val)
cut a numeric value to be >=0
bool linearSearch(IT iter, typename IT::value_type const &val)
use (and exhaust) a »Lumiera Forward Iterator« for linear search
size_t slotNr(X const &x)
the addressable memory »slot« — platform dependent
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
uint uNum(CStr charPtr)
positive integral number from textual representation
OBJ * unConst(const OBJ *o)
shortcut to save some typing when having to define const and non-const variants of member functions ...
bool isNo(string const &textForm) noexcept
check if the given text is empty or can be interpreted as rejection (bool false)- ...
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
Helper to use a single extension point for specialised hash functions.
bool remove_if(SET &set, FUN test)
remove all elements fulfilling a given predicate from a (sorted) set.
string trim(string const &org)
remove leading and trailing whitespace
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
NUM constexpr limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively
bool endsWith(string const &str, string const &suffix)
check if string ends with the given suffix
SEQ::iterator removeall(SEQ &coll, typename SEQ::value_type const &val)
shortcut for removing all copies of an Element in any sequential collection
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.