AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Env.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include "Converter.h"
   15#include "TypedMethods.h"
   16#include "Signature.h"
   17
   18namespace aui::jni {
   25    template<convertible Return = void, convertible... Args>
   26    Return callStaticMethod(jclass clazz, jmethodID methodId, const Args&... args) {
   27        auto e = env();
   28        if constexpr (std::is_void_v<Return>) {
   29            (e->*TypedMethods<Return>::CallStaticMethod)(clazz, methodId, toJni(args)...);
   30        } else {
   31            return fromJni<Return>((e->*TypedMethods<java_t_from_cpp_t<Return>>::CallStaticMethod)(clazz, methodId, toJni(args)...));
   32        }
   33    }
   34
   41    template<convertible Return = void, convertible... Args>
   42    Return callMethod(jobject thiz, jmethodID methodId, const Args&... args) {
   43        auto e = env();
   44        if constexpr (std::is_void_v<Return>) {
   45            (e->*TypedMethods<Return>::CallMethod)(thiz, methodId, toJni(args)...);
   46        } else {
   47            return fromJni<Return>((e->*TypedMethods<java_t_from_cpp_t<Return>>::CallMethod)(thiz, methodId, toJni(args)...));
   48        }
   49    }
   50}
Definition Converter.h:33
API_AUI_CORE const ACommandLineArgs & args() noexcept
JNIEnv * env()
Definition Globals.h:38
Definition TypedMethods.h:18