WPILibC++ 2024.3.2
wpi::java Namespace Reference

Java Native Interface (JNI) utility functions. More...

Namespaces

namespace  detail
 

Classes

class  JCallbackManager
 
class  JCallbackThread
 Generic callback thread implementation. More...
 
class  JClass
 Finds a class and keeps it as a global reference. More...
 
struct  JClassInit
 
class  JException
 Finds an exception class and keep it as a global reference. More...
 
struct  JExceptionInit
 
class  JGlobal
 
class  JLocal
 Container class for cleaning up Java local references. More...
 
class  JSingletonCallbackManager
 
class  JStringRef
 Java string (jstring) reference. More...
 

Typedefs

template<typename T , size_t Extent = std::dynamic_extent>
using JSpan = detail::JSpanBase< T, false, Extent >
 
template<typename T , size_t Extent = std::dynamic_extent>
using CriticalJSpan = detail::JSpanBase< T, true, Extent >
 

Functions

std::string GetJavaStackTrace (JNIEnv *env, std::string *func=nullptr, std::string_view excludeFuncPrefix={})
 Gets a Java stack trace. More...
 
jstring MakeJString (JNIEnv *env, std::string_view str)
 Convert a UTF8 string into a jstring. More...
 
template<typename T >
jintArray MakeJIntArray (JNIEnv *env, std::span< const T > arr)
 Convert a span to a jintArray. More...
 
template<typename T >
jintArray MakeJIntArray (JNIEnv *env, const SmallVectorImpl< T > &arr)
 Convert a SmallVector to a jintArray. More...
 
template<typename T >
jintArray MakeJIntArray (JNIEnv *env, const std::vector< T > &arr)
 Convert a std::vector to a jintArray. More...
 
jbyteArray MakeJByteArray (JNIEnv *env, std::span< const uint8_t > str)
 Convert a span into a jbyteArray. More...
 
jbooleanArray MakeJBooleanArray (JNIEnv *env, std::span< const int > arr)
 Convert an array of integers into a jbooleanArray. More...
 
jbooleanArray MakeJBooleanArray (JNIEnv *env, std::span< const bool > arr)
 Convert an array of booleans into a jbooleanArray. More...
 
template<class T >
requires (sizeof(typename T::value_type) == sizeof(jlong) && std::integral<typename T::value_type>)
jlongArray MakeJLongArray (JNIEnv *env, const T &arr)
 
jobjectArray MakeJStringArray (JNIEnv *env, std::span< const std::string > arr)
 Convert an array of std::string into a jarray of jstring. More...
 
jobjectArray MakeJStringArray (JNIEnv *env, std::span< std::string_view > arr)
 Convert an array of std::string into a jarray of jstring. More...
 
std::string GetJavaStackTrace (JNIEnv *env, std::string_view skipPrefix)
 

Detailed Description

Java Native Interface (JNI) utility functions.

Typedef Documentation

◆ CriticalJSpan

template<typename T , size_t Extent = std::dynamic_extent>
using wpi::java::CriticalJSpan = typedef detail::JSpanBase<T, true, Extent>

◆ JSpan

template<typename T , size_t Extent = std::dynamic_extent>
using wpi::java::JSpan = typedef detail::JSpanBase<T, false, Extent>

Function Documentation

◆ GetJavaStackTrace() [1/2]

std::string wpi::java::GetJavaStackTrace ( JNIEnv *  env,
std::string *  func = nullptr,
std::string_view  excludeFuncPrefix = {} 
)
inline

Gets a Java stack trace.

Also provides the last function in the stack trace not starting with excludeFuncPrefix (useful for e.g. finding the first user call to a series of library functions).

Parameters
envJRE environment.
funcStorage for last function in the stack trace not starting with excludeFuncPrefix.
excludeFuncPrefixPrefix for functions to ignore in stack trace.

◆ GetJavaStackTrace() [2/2]

std::string wpi::java::GetJavaStackTrace ( JNIEnv *  env,
std::string_view  skipPrefix 
)
inline

◆ MakeJBooleanArray() [1/2]

jbooleanArray wpi::java::MakeJBooleanArray ( JNIEnv *  env,
std::span< const bool >  arr 
)
inline

Convert an array of booleans into a jbooleanArray.

Parameters
envJRE environment.
arrArray to convert.

◆ MakeJBooleanArray() [2/2]

jbooleanArray wpi::java::MakeJBooleanArray ( JNIEnv *  env,
std::span< const int >  arr 
)
inline

Convert an array of integers into a jbooleanArray.

Parameters
envJRE environment.
arrArray to convert.

◆ MakeJByteArray()

jbyteArray wpi::java::MakeJByteArray ( JNIEnv *  env,
std::span< const uint8_t >  str 
)
inline

Convert a span into a jbyteArray.

Parameters
envJRE environment.
strspan to convert.

◆ MakeJIntArray() [1/3]

template<typename T >
jintArray wpi::java::MakeJIntArray ( JNIEnv *  env,
const SmallVectorImpl< T > &  arr 
)
inline

Convert a SmallVector to a jintArray.

This is required in addition to ArrayRef because template resolution occurs prior to implicit conversions.

Parameters
envJRE environment.
arrSmallVector to convert.

◆ MakeJIntArray() [2/3]

template<typename T >
jintArray wpi::java::MakeJIntArray ( JNIEnv *  env,
const std::vector< T > &  arr 
)
inline

Convert a std::vector to a jintArray.

This is required in addition to ArrayRef because template resolution occurs prior to implicit conversions.

Parameters
envJRE environment.
arrSmallVector to convert.

◆ MakeJIntArray() [3/3]

template<typename T >
jintArray wpi::java::MakeJIntArray ( JNIEnv *  env,
std::span< const T >  arr 
)
inline

Convert a span to a jintArray.

Parameters
envJRE environment.
arrSpan to convert.

◆ MakeJLongArray()

template<class T >
requires (sizeof(typename T::value_type) == sizeof(jlong) && std::integral<typename T::value_type>)
jlongArray wpi::java::MakeJLongArray ( JNIEnv *  env,
const T &  arr 
)
inline

◆ MakeJString()

jstring wpi::java::MakeJString ( JNIEnv *  env,
std::string_view  str 
)
inline

Convert a UTF8 string into a jstring.

Parameters
envJRE environment.
strString to convert.

◆ MakeJStringArray() [1/2]

jobjectArray wpi::java::MakeJStringArray ( JNIEnv *  env,
std::span< const std::string >  arr 
)
inline

Convert an array of std::string into a jarray of jstring.

Parameters
envJRE environment.
arrArray to convert.

◆ MakeJStringArray() [2/2]

jobjectArray wpi::java::MakeJStringArray ( JNIEnv *  env,
std::span< std::string_view arr 
)
inline

Convert an array of std::string into a jarray of jstring.

Parameters
envJRE environment.
arrArray to convert.