7#define ALPAQA_DL_ABI_VERSION 0xA1A000000001
11#define ALPAQA_DL_ABI_VERSION_DEFAULT = ALPAQA_DL_ABI_VERSION
13#define ALPAQA_DL_ABI_VERSION_DEFAULT
36 void (*eval_grad_g_prod)(
54 void (*eval_hess_L_prod)(
71 void (*eval_hess_ψ_prod)(
102 void (*eval_grad_f_grad_g_prod)(
149 void (*initialize_box_C)(
153 void (*initialize_box_D)(
157 void (*initialize_l1_reg)(
173 void (*cleanup)(
void *);
210 void (*eval_grad_f_prod)(
251 void (*eval_add_Q_N)(
256 void (*eval_add_R_masked)(
264 void (*eval_add_S_masked)(
272 void (*eval_add_R_prod_masked)(
282 void (*eval_add_S_prod_masked)(
300 void (*eval_constr_N)(
304 void (*eval_grad_constr_prod)(
310 void (*eval_grad_constr_prod_N)(
315 void (*eval_add_gn_hess_constr)(
321 void (*eval_add_gn_hess_constr_N)(
335 void (*cleanup)(
void *);
345#define ALPAQA_PROBLEM_FUNCTIONS_INIT(self) \
347 memset((self), 0, sizeof(*(self))); \
348 (self)->abi_version = ALPAQA_DL_ABI_VERSION; \
352#if defined(__cplusplus) && __cplusplus > 201703L
360 std::map<std::string, std::any>
dict{};
377 if (extra_functions ==
nullptr)
379 extra_functions->
dict.insert_or_assign(
380 std::move(name), std::function{std::forward<Func>(func)});
387 std::forward<Func>(func));
394 std::forward<Func>(func));
397template <
class Result,
class T,
class Ret,
class... Args>
399 Ret (T::*member)(Args...)) {
401 [member](
void *self_, Args... args) -> Ret {
402 auto *self = reinterpret_cast<T *>(self_);
403 return (self->*member)(std::forward<Args>(args)...);
407template <
class Result,
class T,
class Ret,
class... Args>
409 Ret (T::*member)(Args...)
const) {
411 [member](
const void *self_, Args... args) -> Ret {
412 const auto *self = reinterpret_cast<const T *>(self_);
413 return (self->*member)(std::forward<Args>(args)...);
418template <
auto Member,
class Class,
class Ret,
class... Args>
420 return [](
void *self_, Args... args) -> Ret {
421 auto *self =
reinterpret_cast<Class *
>(self_);
422 return (self->*Member)(std::forward<Args>(args)...);
426template <
auto Member,
class Class,
class Ret,
class... Args>
428 return []<
class Self>(Self * self_, Args... args) -> Ret
429 requires std::is_void_v<Self>
431 const auto *self =
reinterpret_cast<const Class *
>(self_);
432 return (self->*Member)(std::forward<Args>(args)...);
436template <auto Member,
class Class,
class Ret>
438 return []<
class Self>(Self * self_) ->
decltype(
auto)
439 requires std::is_void_v<Self>
441 using CClass = std::conditional_t<std::is_const_v<Self>,
442 std::add_const_t<Class>, Class>;
443 auto *self =
reinterpret_cast<CClass *
>(self_);
444 return self->*Member;
456template <auto Member>
458 return detail::member_caller<Member>(Member);
469 delete extra_functions;
476#undef ALPAQA_DL_ABI_VERSION_DEFAULT
#define ALPAQA_DL_ABI_VERSION_DEFAULT
struct alpaqa_function_dict_s alpaqa_function_dict_t
Opaque type for a C++-only map of extra functions.
ptrdiff_t alpaqa_length_t
alpaqa_length_t alpaqa_index_t
std::map< std::string, std::any > dict
void unregister_functions(function_dict_t *&extra_functions)
Cleans up the extra functions registered by register_function.
void register_function(function_dict_t *&extra_functions, std::string name, Func &&func)
Make the given function available to alpaqa.
void register_member_function(Result &result, std::string name, Ret(T::*member)(Args...))
static auto member_caller()
Wrap the given member function of signature into a lambda function that accepts the instance as a voi...
alpaqa_function_dict_t * extra_functions
Pointer to a map of extra functions (C++ only).
alpaqa_control_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.
void * instance
Owning pointer.
alpaqa_function_dict_t * extra_functions
Pointer to a map of extra functions (C++ only).
void * instance
Owning pointer.
alpaqa_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.