The open source OpenXR runtime
at main 185 lines 4.3 kB view raw
1// Copyright 2020-2021, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3// Author: Rylie Pavlik <rylie.pavlik@collabora.com> 4 5#pragma once 6 7#include "ObjectWrapperBase.h" 8 9namespace wrap { 10namespace java::lang { 11class Class; 12class ClassLoader; 13} // namespace java::lang 14 15} // namespace wrap 16 17namespace wrap { 18namespace java::lang { 19/*! 20 * Wrapper for java.lang.Class objects. 21 */ 22class Class : public ObjectWrapperBase { 23 public: 24 using ObjectWrapperBase::ObjectWrapperBase; 25 static constexpr const char *getTypeName() noexcept { 26 return "java/lang/Class"; 27 } 28 29 /*! 30 * Wrapper for the forName static method 31 * 32 * Java prototype: 33 * `public static java.lang.Class<?> forName(java.lang.String) throws 34 * java.lang.ClassNotFoundException;` 35 * 36 * JNI signature: (Ljava/lang/String;)Ljava/lang/Class; 37 * 38 */ 39 static Class forName(std::string const &name); 40 41 /*! 42 * Wrapper for the forName static method 43 * 44 * Java prototype: 45 * `public static java.lang.Class<?> forName(java.lang.String, boolean, 46 * java.lang.ClassLoader) throws java.lang.ClassNotFoundException;` 47 * 48 * JNI signature: 49 * (Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class; 50 * 51 */ 52 static Class forName(std::string const &name, bool initialize, 53 ClassLoader const &classLoader); 54 55 //! @overload 56 static Class forName(jstring name, bool initialize, 57 jni::Object classLoader); 58 /*! 59 * Wrapper for the getCanonicalName method 60 * 61 * Java prototype: 62 * `public java.lang.String getCanonicalName();` 63 * 64 * JNI signature: ()Ljava/lang/String; 65 * 66 */ 67 std::string getCanonicalName(); 68 69 /*! 70 * Class metadata 71 */ 72 struct Meta : public MetaBase { 73 jni::method_t forName; 74 jni::method_t forName1; 75 jni::method_t getCanonicalName; 76 77 /*! 78 * Singleton accessor 79 */ 80 static Meta &data() { 81 static Meta instance{}; 82 return instance; 83 } 84 85 private: 86 Meta(); 87 }; 88}; 89 90/*! 91 * Wrapper for java.lang.ClassLoader objects. 92 */ 93class ClassLoader : public ObjectWrapperBase { 94 public: 95 using ObjectWrapperBase::ObjectWrapperBase; 96 static constexpr const char *getTypeName() noexcept { 97 return "java/lang/ClassLoader"; 98 } 99 100 /*! 101 * Wrapper for the loadClass method 102 * 103 * Java prototype: 104 * `public java.lang.Class<?> loadClass(java.lang.String) throws 105 * java.lang.ClassNotFoundException;` 106 * 107 * JNI signature: (Ljava/lang/String;)Ljava/lang/Class; 108 * 109 */ 110 Class loadClass(std::string const &name); 111 112 //! @overload 113 Class loadClass(jstring name); 114 115 /*! 116 * Wrapper for the findLibrary method 117 * 118 * JNI signature: (Ljava/lang/String;)Ljava/lang/String; 119 * 120 */ 121 std::string findLibrary(std::string const &name); 122 123 /*! 124 * Class metadata 125 */ 126 struct Meta : public MetaBaseDroppable { 127 jni::method_t loadClass; 128 jni::method_t findLibrary; 129 130 /*! 131 * Singleton accessor 132 */ 133 static Meta &data() { 134 static Meta instance{}; 135 return instance; 136 } 137 138 private: 139 Meta(); 140 }; 141}; 142 143/*! 144 * Wrapper for java.lang.System objects. 145 */ 146class System : public ObjectWrapperBase { 147 public: 148 using ObjectWrapperBase::ObjectWrapperBase; 149 static constexpr const char *getTypeName() noexcept { 150 return "java/lang/System"; 151 } 152 153 /*! 154 * Wrapper for the mapLibraryName static method 155 * 156 * Java prototype: 157 * `public static native java.lang.String mapLibraryName(java.lang.String);` 158 * 159 * JNI signature: (Ljava/lang/String;)Ljava/lang/String; 160 * 161 */ 162 static std::string mapLibraryName(std::string const &name); 163 164 /*! 165 * Class metadata 166 */ 167 struct Meta : public MetaBase { 168 jni::method_t mapLibraryName; 169 170 /*! 171 * Singleton accessor 172 */ 173 static Meta &data() { 174 static Meta instance{}; 175 return instance; 176 } 177 178 private: 179 Meta(); 180 }; 181}; 182 183} // namespace java::lang 184} // namespace wrap 185#include "java.lang.impl.h"