2#ifndef __ASE_UTILS_HH__ 
    3#define __ASE_UTILS_HH__ 
    7#include <experimental/type_traits> 
   17template<class ...A> 
void debug             (const 
char *cond, const 
char *format, const A &...args) ASE_ALWAYS_INLINE;
 
   18template<class ...A> 
void fatal_error       (const 
char *format, const A &...args) ASE_NORETURN;
 
   19template<class ...A> 
void warning           (const 
char *format, const A &...args);
 
   20template<class... A> 
void printout          (const 
char *format, const A &...args) ASE_PRINTF (1, 0);
 
   21template<class... A> 
void printerr          (const 
char *format, const A &...args) ASE_PRINTF (1, 0);
 
   24const 
char*                                ase_gettext (const 
String &untranslated);
 
   25template<class A0, class... Ar> const 
char* ase_gettext (const 
char *format, const A0 &a0, const Ar &...restargs) ASE_PRINTF (1, 0);
 
   35IconString 
operator""_uc (
const char *key, 
size_t);
 
   36IconString 
operator""_icon (
const char *key, 
size_t);
 
   41template<
typename MkFun, 
size_t ...INDICES> 
static auto 
   44  constexpr size_t N = 
sizeof... (INDICES);
 
   54template<std::
size_t LAST, 
typename MkFun> 
static auto 
   55make_case_table (
const MkFun &mkjump)
 
   65  void     operator= (
const EventFd&) = 
delete; 
 
 
  101  static_assert (
sizeof (custom_data_) == 
sizeof (
void*));
 
  102  CustomDataEntry& custom_data_entry (
VirtualBase *key);
 
  107  void            custom_data_destroy ();
 
  111  { 
std::any a (data); custom_data_entry (key).swap (a); }
 
 
  114  { 
return key->extract (custom_data_get (key)); }
 
 
  117  { 
return key->has_value (custom_data_get (key)); }
 
 
  120  { 
return custom_data_del (key); }
 
 
 
  137  return (v >> 8) | (v << 8);
 
 
  143  return __builtin_bswap32 (v);
 
  144  return ( ((v & 0x000000ffU) << 24) |
 
  145           ((v & 0x0000ff00U) <<  8) |
 
  146           ((v & 0x00ff0000U) >>  8) |
 
  147           ((v & 0xff000000U) >> 24) );
 
 
  153  return __builtin_bswap64 (v);
 
  154  return ( ((v & 0x00000000000000ffUL) << 56) |
 
  155           ((v & 0x000000000000ff00UL) << 40) |
 
  156           ((v & 0x0000000000ff0000UL) << 24) |
 
  157           ((v & 0x00000000ff000000UL) <<  8) |
 
  158           ((v & 0x000000ff00000000UL) >>  8) |
 
  159           ((v & 0x0000ff0000000000UL) >> 24) |
 
  160           ((v & 0x00ff000000000000UL) >> 40) |
 
  161           ((v & 0xff00000000000000UL) >> 56) );
 
 
  174inline bool ASE_ALWAYS_INLINE ASE_PURE
 
  181template<
class ...Args> 
inline void ASE_ALWAYS_INLINE
 
  182debug (
const char *cond, 
const char *format, 
const Args &...args)
 
 
  195template<
class ...Args> 
void ASE_NORETURN
 
  196fatal_error (
const char *format, 
const Args &...args)
 
 
  202template<
class ...Args> 
void 
  203warning (
const char *format, 
const Args &...args)
 
 
  209template<
class... Args> 
void 
  210printout (
const char *format, 
const Args &...args)
 
 
  216template<
class... Args> 
void 
  217printerr (
const char *format, 
const Args &...args)
 
 
  223template<
class A0, 
class... Ar> 
const char*
 
  224ase_gettext (
const char *format, 
const A0 &a0, 
const Ar &...restargs)
 
  226  return ase_gettext (
string_format (format, a0, restargs...));
 
 
  233using callable_reserve_int = 
decltype (
std::declval<T&>().reserve (
int (0)));
 
  238template<
class Container, 
class Iteratable> Container
 
  252template<
typename RandIter, 
class Cmp, 
typename Arg, 
int case_lookup_or_sibling_or_insertion>
 
  254binary_lookup_fuzzy (RandIter begin, RandIter end, Cmp cmp_elements, 
const Arg &arg)
 
  256  RandIter current = end;
 
  257  size_t n_elements = end - begin, offs = 0;
 
  258  const bool want_lookup = case_lookup_or_sibling_or_insertion == 0;
 
  260  const bool want_insertion_pos = case_lookup_or_sibling_or_insertion > 1;
 
  262  while (offs < n_elements)
 
  264      size_t i = (offs + n_elements) >> 1;
 
  266      cmp = cmp_elements (arg, *current);
 
  268        return want_insertion_pos ? 
std::make_pair (current, 
true) : 
std::make_pair (current,  false);
 
  277          : (want_insertion_pos && cmp > 0)
 
  278          ? 
std::make_pair (current + 1, false)
 
  279          : 
std::make_pair (current, false));
 
  287template<
typename RandIter, 
class Cmp, 
typename Arg>
 
  291  return binary_lookup_fuzzy<RandIter,Cmp,Arg,2> (begin, end, cmp_elements, arg);
 
 
  299template<
typename RandIter, 
class Cmp, 
typename Arg>
 
  300extern inline RandIter
 
  303  return binary_lookup_fuzzy<RandIter,Cmp,Arg,1> (begin, end, cmp_elements, arg).first;
 
 
  311template<
typename RandIter, 
class Cmp, 
typename Arg>
 
  312extern inline RandIter
 
  313binary_lookup (RandIter begin, RandIter end, Cmp cmp_elements, 
const Arg &arg)
 
  316  return binary_lookup_fuzzy<RandIter,Cmp,Arg,0> (begin, end, cmp_elements, arg).first;
 
 
  320template<
typename Value> 
static inline int 
  321compare_lesser (
const Value &v1, 
const Value &v2)
 
  323  return -(v1 < v2) | (v2 < v1);
 
  327template<
typename Value> 
static inline int 
  328compare_greater (
const Value &v1, 
const Value &v2)
 
  330  return (v1 < v2) | -(v2 < v1);
 
  336template<
class C> 
inline size_t 
  339  for (
auto iter = container.begin(); iter != container.end(); iter++)
 
  342        container.erase (iter);
 
 
  349template<
class C> 
inline size_t 
  353  for (
auto iter = container.begin(); iter != container.end(); )
 
  356        iter = container.erase (iter);
 
 
  365template<
typename C> 
inline bool 
  368  for (
auto iter = container.begin(); iter != container.end(); iter++)
 
 
  380  auto it = insmatch.first;
 
  381  return vec.insert (it, value);
 
 
  384template<
class IterableContainer> 
ssize_t 
  385index_of (
const IterableContainer &c, 
const std::function<
bool(
const typename IterableContainer::value_type &e)> &match)
 
 
 
 
T back_inserter(T... args)
 
T get_custom_data(CustomDataKey< T > *key) const
Retrieve contents of the custom keyed data member, returns DataKey::fallback if nothing was set.
 
bool has_custom_data(CustomDataKey< T > *key) const
Retrieve wether contents of the custom keyed data member exists.
 
bool del_custom_data(CustomDataKey< T > *key)
Delete the current contents of the custom keyed data member, invokes DataKey::destroy.
 
void set_custom_data(CustomDataKey< T > *key, T data)
Assign data to the custom keyed data member, deletes any previously set data.
 
CustomDataKey objects are used to identify and manage custom data members of CustomDataContainer obje...
 
virtual T fallback()
Return default T instance.
 
const std::type_info & type() const noexcept
Return the typeid of T.
 
bool opened()
Indicates whether eventfd has been opened.
 
void flush()
Clear pending wakeups.
 
int inputfd()
Returns the file descriptor for POLLIN.
 
bool pollin()
Checks whether events are pending.
 
int open()
Opens the eventfd and returns -errno.
 
void wakeup()
Wakeup polling end.
 
#define ASE_UNLIKELY(expr)
Compiler hint to optimize for expr evaluating to false.
 
std::vector< T >::iterator insert_sorted(std::vector< T > &vec, const T &value, Compare compare)
Insert value into sorted vec using binary_lookup_insertion_pos() with compare.
 
Container container_copy(const Iteratable &source)
Create a Container with copies of the elements of source.
 
RandIter binary_lookup_sibling(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
 
size_t erase_all(C &container, const std::function< bool(typename C::value_type const &value)> &pred)
Erase all elements for which pred() is true in vector or list.
 
size_t erase_first(C &container, const std::function< bool(typename C::value_type const &value)> &pred)
Erase first element for which pred() is true in vector or list.
 
RandIter binary_lookup(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
 
std::pair< RandIter, bool > binary_lookup_insertion_pos(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
 
bool contains(const C &container, const std::function< bool(typename C::value_type const &value)> &pred)
Returns true if container element for which pred() is true.
 
The Anklang C++ API namespace.
 
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
 
constexpr uint64_t uint64_swap_le_be(uint64_t v)
Swap 64-Bit integers between __BIG_ENDIAN and __LITTLE_ENDIAN systems.
 
bool debug_key_enabled(const char *conditional)
Check if conditional is enabled by $ASE_DEBUG.
 
bool ase_fatal_warnings
Global boolean to cause the program to abort on warnings.
 
void assertion_failed(const char *msg, const char *file, int line, const char *func) noexcept
Print instructive message, handle "breakpoint", "backtrace" and "fatal-warnings" in $ASE_DEBUG.
 
String diag_prefix(uint8 code)
Create prefix for warnings and errors.
 
uint8_t uint8
An 8-bit unsigned integer.
 
constexpr uint32_t uint32_swap_le_be(uint32_t v)
Swap 32-Bit integers between __BIG_ENDIAN and __LITTLE_ENDIAN systems.
 
void diag_flush(uint8 code, const String &txt)
Handle stdout and stderr printing with flushing.
 
void assertion_fatal(const char *msg, const char *file, int line, const char *func) noexcept
Print a debug message via assertion_failed() and abort the program.
 
constexpr uint16_t uint16_swap_le_be(uint16_t v)
Swap 16-Bit integers between __BIG_ENDIAN and __LITTLE_ENDIAN systems.
 
bool ase_debugging_enabled
Global boolean to reduce debugging penalty where possible.
 
bool debug_enabled() ASE_PURE
Check if any kind of debugging is enabled by $ASE_DEBUG.
 
void debug_message(const char *cond, const std::string &message)
Print a debug message, called from Ase::debug().
 
std::string String
Convenience alias for std::string.
 
::std::string debug_key_value(const char *conditional)
Retrieve the value assigned to debug key conditional in $ASE_DEBUG.
 
Value type used to interface with various property types.
 
Common base type to allow casting between polymorphic classes.
 
IconString SvgIcon(const String &svgdata)
Create an IconString consisting of an SVG string.
 
IconString UcIcon(const String &unicode)
Create an IconString consisting of a single/double unicode character.
 
IconString KwIcon(const String &keywords)
Create an IconString consisting of keywords.