39 template<
typename K,
typename CMP,
class ALLO>
42 template<
typename IT,
typename V>
43 IT find (IT, IT, V
const&);
44 template<
typename IT,
typename V>
45 IT
remove (IT, IT, V
const&);
49 const char*
cStr (std::string
const&);
56 using CStr =
const char*;
63 return (n==0)? 0 :((n<0)? -1:+1 );
66 template <
class N1,
class N2>
70 return n2 < n1? N1(n2) : n1;
73 template <
class N1,
class N2>
77 return n1 < n2? N1(n2) : n1;
81 template <
typename NUM>
85 return (0<val? val : 0);
89 template <
typename NUM,
typename NB>
91 limited (NB lowerBound, NUM val, NB upperBound)
93 return min ( max (val, lowerBound)
97 template <
typename NUM,
typename NB>
99 isLimited (NB lowerBound, NUM val, NB upperBound)
101 return lowerBound <= val
102 and val <= upperBound;
105 template <
typename UN,
typename N2>
107 positiveDiff (N2 newVal, UN refVal)
109 return UN(newVal) > refVal? UN(newVal) - refVal
119 if (!charPtr)
return 0;
120 int parsedNumber (std::atoi (charPtr));
121 return limited (0, parsedNumber, LUMIERA_MAX_ORDINAL_NUMBER);
127 if (!charPtr)
return 0;
128 int parsedNumber (std::atoi (charPtr));
129 return limited (-LUMIERA_MAX_ORDINAL_NUMBER, parsedNumber, LUMIERA_MAX_ORDINAL_NUMBER);
134 uNum (OBJ
const& spec)
141 sNum (OBJ
const& spec)
143 return sNum (
cStr(spec));
152 template <
class CONT>
154 isnil (
const CONT& container)
156 return container.empty();
159 template <
class CONT>
161 isnil (
const CONT* pContainer)
163 return !pContainer or pContainer->empty();
166 template <
class CONT>
168 isnil (CONT* pContainer)
170 return !pContainer or pContainer->empty();
176 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();
360 return const_cast<OBJ*
> (o);
367 return const_cast<OBJ&
> (ro);
379 return static_cast<const void*
> (std::addressof(x));
385 return static_cast<const void*
> (x);
393 return size_t(
getAdr (x));
402 return addrID(x) /
sizeof(size_t);
409 template<
class A,
class B>
419 template<
class A,
class B>
423 return static_cast<const void*
> (std::addressof(a))
424 == static_cast<const void*> (std::addressof(b));
432 template<
typename A,
typename B>
436 size_t loc1 =
slotNr (std::forward<A> (a));
437 size_t loc2 =
slotNr (std::forward<B> (b));
438 size_t dist = loc2 > loc1? loc2-loc1:loc1-loc2;
439 return dist < consideredNearby;
464 string sanitise (
string const& org);
470 string trim (
string const& org);
487 bool isYes (
string const&) noexcept;
493 bool isNo (
string const&) noexcept;
505 #define SIDEEFFECT __attribute__ ((unused)); 508 #define STRINGIFY(TOKEN) __STRNGFY(TOKEN) 509 #define __STRNGFY(TOKEN) #TOKEN 514 #define INSTANCEOF(CLASS, EXPR) (dynamic_cast<const CLASS*> (EXPR)) 517 #ifndef MAX // this is present to make this definition play nice with GLib 518 #define MAX(A,B) ((A < B) ? (B) : (A)) OBJ * unConst(const OBJ *)
shortcut to save some typing when having to define const and non-const variants of member functions ...
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).
bool startsWith(string const &str, string const &prefix)
check if string starts with a given prefix
const void * getAdr(X &x)
extract address but strip any type info
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
bool isNo(string const &textForm) noexcept
check if the given text is empty or can be interpreted as rejection (bool false)- ...
size_t addrID(X const &x)
generate an unique numeric ID based on the referred entity
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 isSameAdr(A const &a, B const &b)
compare plain object address identity, disregarding type.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...