Commit 44a6f24c authored by Volker Krause's avatar Volker Krause
Browse files

Factor out basic pre-processor macro building blocks

parent 08feaf5a
......@@ -64,6 +64,7 @@ ecm_generate_headers(KAndroidExtras_jni_FORWARDING_HEADERS
JniObject
JniMethod
JniReturnValue
JniPp
JniProperty
JniSignature
JniTypes
......
......@@ -9,6 +9,7 @@
#include "jniarray.h"
#include "jnimethod.h"
#include "jniobject.h"
#include "jnipp.h"
#include "jniproperty.h"
#include "jnireturnvalue.h"
#include "jnisignature.h"
......
/*
SPDX-FileCopyrightText: 2019-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KANDROIDEXTRAS_JNIPP_H
#define KANDROIDEXTRAS_JNIPP_H
/** @file jnipp.h
* Preprocessor macro implementation details.
*/
///@cond internal
// determine how many elements are in __VA_ARGS__
#define JNI_PP_NARG(...) JNI_PP_NARG_(__VA_ARGS__, JNI_PP_RSEQ_N())
#define JNI_PP_NARG_(...) JNI_PP_ARG_N(__VA_ARGS__)
#define JNI_PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, N, ...) N
#define JNI_PP_RSEQ_N() 7, 6, 5, 4, 3, 2, 1, 0
// preprocessor-level token concat
#define JNI_PP_CONCAT(arg1, arg2) JNI_PP_CONCAT1(arg1, arg2)
#define JNI_PP_CONCAT1(arg1, arg2) JNI_PP_CONCAT2(arg1, arg2)
#define JNI_PP_CONCAT2(arg1, arg2) arg1##arg2
///@endcond
#endif // KANDROIDEXTRAS_JNIPP_H
......@@ -7,20 +7,12 @@
#ifndef KANDROIDEXTRAS_JNITYPES_H
#define KANDROIDEXTRAS_JNITYPES_H
#include "jnipp.h"
/** C++/Android integration utilities built on top of @c QAndroidJniObject. */
namespace KAndroidExtras {
///@cond internal
// determine how many elements are in __VA_ARGS__
#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_RSEQ_N())
#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
#define PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, N, ...) N
#define PP_RSEQ_N() 7, 6, 5, 4, 3, 2, 1, 0
// preprocessor-level token concat
#define PP_CONCAT(arg1, arg2) PP_CONCAT1(arg1, arg2)
#define PP_CONCAT1(arg1, arg2) PP_CONCAT2(arg1, arg2)
#define PP_CONCAT2(arg1, arg2) arg1##arg2
// preprocessor "iteration" for regular classes
#define JNI_TYPE_1(name, type, ...) \
......@@ -37,7 +29,7 @@ namespace KAndroidExtras {
namespace type { JNI_TYPE_5(name #type "/", __VA_ARGS__) }
#define JNI_TYPE_7(name, type, ...) \
namespace type { JNI_TYPE_6(#type "/", __VA_ARGS__) }
#define JNI_TYPE_(N, name, ...) PP_CONCAT(JNI_TYPE_, N)(name, __VA_ARGS__)
#define JNI_TYPE_(N, name, ...) JNI_PP_CONCAT(JNI_TYPE_, N)(name, __VA_ARGS__)
// preprocessor "iteration" for nested classes
#define JNI_NESTED_TYPE_2(name, type, nested_type, ...) \
......@@ -52,15 +44,15 @@ namespace KAndroidExtras {
namespace type { JNI_NESTED_TYPE_5(name #type "/", __VA_ARGS__) }
#define JNI_NESTED_TYPE_7(name, type, ...) \
namespace type { JNI_NESTED_TYPE_6(#type "/", __VA_ARGS__) }
#define JNI_NESTED_TYPE_(N, name, ...) PP_CONCAT(JNI_NESTED_TYPE_, N)(name, __VA_ARGS__)
#define JNI_NESTED_TYPE_(N, name, ...) JNI_PP_CONCAT(JNI_NESTED_TYPE_, N)(name, __VA_ARGS__)
///@endcond
/** Macro to define Java types with their corresponding JNI signature strings. */
#define JNI_TYPE(...) JNI_TYPE_(PP_NARG(__VA_ARGS__), "", __VA_ARGS__)
#define JNI_TYPE(...) JNI_TYPE_(JNI_PP_NARG(__VA_ARGS__), "", __VA_ARGS__)
/** Macro to define a nested Java class with its corresponding JNI signature string. */
#define JNI_NESTED_TYPE(...) JNI_NESTED_TYPE_(PP_NARG(__VA_ARGS__), "", __VA_ARGS__)
#define JNI_NESTED_TYPE(...) JNI_NESTED_TYPE_(JNI_PP_NARG(__VA_ARGS__), "", __VA_ARGS__)
/** Functions for interfacing with the Java Native Interface (JNI). */
namespace Jni
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment