6#include <experimental/type_traits>
12const char* ase_gettext (
const String &untranslated);
13template<
class A0,
class... Ar>
const char* ase_gettext (
const char *format,
const A0 &a0,
const Ar &...restargs) ASE_PRINTF (1, 0);
23IconString
operator""_uc (
const char *key,
size_t);
24IconString
operator""_icon (
const char *key,
size_t);
29template<
typename MkFun,
size_t ...INDICES>
static auto
32 constexpr size_t N =
sizeof... (INDICES);
42template<std::
size_t LAST,
typename MkFun>
static auto
43make_case_table (
const MkFun &mkjump)
53 void operator= (
const EventFd&) =
delete;
89 static_assert (
sizeof (custom_data_) ==
sizeof (
void*));
90 CustomDataEntry& custom_data_entry (
VirtualBase *key);
95 void custom_data_destroy ();
99 {
std::any a (data); custom_data_entry (key).swap (a); }
102 {
return key->extract (custom_data_get (key)); }
105 {
return key->has_value (custom_data_get (key)); }
108 {
return custom_data_del (key); }
125 return (v >> 8) | (v << 8);
131 return __builtin_bswap32 (v);
132 return ( ((v & 0x000000ffU) << 24) |
133 ((v & 0x0000ff00U) << 8) |
134 ((v & 0x00ff0000U) >> 8) |
135 ((v & 0xff000000U) >> 24) );
141 return __builtin_bswap64 (v);
142 return ( ((v & 0x00000000000000ffUL) << 56) |
143 ((v & 0x000000000000ff00UL) << 40) |
144 ((v & 0x0000000000ff0000UL) << 24) |
145 ((v & 0x00000000ff000000UL) << 8) |
146 ((v & 0x000000ff00000000UL) >> 8) |
147 ((v & 0x0000ff0000000000UL) >> 24) |
148 ((v & 0x00ff000000000000UL) >> 40) |
149 ((v & 0xff00000000000000UL) >> 56) );
153template<
class A0,
class... Ar>
const char*
154ase_gettext (
const char *format,
const A0 &a0,
const Ar &...restargs)
156 return ase_gettext (
string_format (format, a0, restargs...));
163using callable_reserve_int =
decltype (
std::declval<T&>().reserve (
int (0)));
168template<
class Container,
class Iteratable> Container
182template<
typename RandIter,
class Cmp,
typename Arg,
int case_lookup_or_sibling_or_insertion>
184binary_lookup_fuzzy (RandIter begin, RandIter end, Cmp cmp_elements,
const Arg &arg)
186 RandIter current = end;
187 size_t n_elements = end - begin, offs = 0;
188 const bool want_lookup = case_lookup_or_sibling_or_insertion == 0;
190 const bool want_insertion_pos = case_lookup_or_sibling_or_insertion > 1;
192 while (offs < n_elements)
194 size_t i = (offs + n_elements) >> 1;
196 cmp = cmp_elements (arg, *current);
198 return want_insertion_pos ?
std::make_pair (current,
true) :
std::make_pair (current, false);
207 : (want_insertion_pos && cmp > 0)
208 ?
std::make_pair (current + 1, false)
209 :
std::make_pair (current, false));
217template<
typename RandIter,
class Cmp,
typename Arg>
221 return binary_lookup_fuzzy<RandIter,Cmp,Arg,2> (begin, end, cmp_elements, arg);
229template<
typename RandIter,
class Cmp,
typename Arg>
230extern inline RandIter
233 return binary_lookup_fuzzy<RandIter,Cmp,Arg,1> (begin, end, cmp_elements, arg).first;
241template<
typename RandIter,
class Cmp,
typename Arg>
242extern inline RandIter
243binary_lookup (RandIter begin, RandIter end, Cmp cmp_elements,
const Arg &arg)
246 return binary_lookup_fuzzy<RandIter,Cmp,Arg,0> (begin, end, cmp_elements, arg).first;
250template<
typename Value>
static inline int
251compare_lesser (
const Value &v1,
const Value &v2)
253 return -(v1 < v2) | (v2 < v1);
257template<
typename Value>
static inline int
258compare_greater (
const Value &v1,
const Value &v2)
260 return (v1 < v2) | -(v2 < v1);
266template<
class C>
inline size_t
269 for (
auto iter = container.begin(); iter != container.end(); iter++)
272 container.erase (iter);
279template<
class C>
inline size_t
283 for (
auto iter = container.begin(); iter != container.end(); )
286 iter = container.erase (iter);
295template<
typename C>
inline bool
298 for (
auto iter = container.begin(); iter != container.end(); iter++)
310 auto it = insmatch.first;
311 return vec.insert (it, value);
314template<
class IterableContainer>
ssize_t
315index_of (
const IterableContainer &c,
const std::function<
bool(
const typename IterableContainer::value_type &e)> &match)
T back_inserter(T... args)
DataListContainer - typesafe storage and retrieval of arbitrary members.
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.
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)
Perform a binary lookup to yield exact or nearest match.
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)
Perform binary lookup and yield exact match or end.
std::pair< RandIter, bool > binary_lookup_insertion_pos(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
Perform a binary lookup to find the insertion position for a new element.
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.
constexpr uint32_t uint32_swap_le_be(uint32_t v)
Swap 32-Bit integers between __BIG_ENDIAN and __LITTLE_ENDIAN systems.
constexpr uint16_t uint16_swap_le_be(uint16_t v)
Swap 16-Bit integers between __BIG_ENDIAN and __LITTLE_ENDIAN systems.
std::string String
Convenience alias for std::string.
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.