JniClass.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-04-07
  6. * Changed: 2024-09-11
  7. *
  8. * */
  9. #ifndef LS_STD_JNI_CLASS_HPP
  10. #define LS_STD_JNI_CLASS_HPP
  11. #include "JniClassParameter.hpp"
  12. #include "JniMethod.hpp"
  13. #include "JniReturnValue.hpp"
  14. #include <jni.h>
  15. #include <ls-std/core/interface/IJniApi.hpp>
  16. #include <ls-std/os/dynamic-goal.hpp>
  17. #include <memory>
  18. #include <string>
  19. #include <unordered_map>
  20. /*
  21. * @doc: class(name: 'JniClass', package: 'core')
  22. * @doc: core.JniClass.description('This class represents a Java class within the Java Native Interface (JNI).')
  23. * */
  24. namespace ls::std::core::experimental
  25. {
  26. class LS_STD_DYNAMIC_GOAL JniClass
  27. {
  28. public:
  29. explicit JniClass(const ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> &_parameter, const ::std::string &_path);
  30. virtual ~JniClass();
  31. [[nodiscard]] ls::std::core::experimental::JniReturnValue callMethod(const ::std::string &_methodIdentifier);
  32. [[nodiscard]] bool hasMethod(const ::std::string &_methodIdentifier);
  33. bool load(); // nodiscard is optional here
  34. bool loadMethod(const ::std::string &_methodIdentifier, const ::std::string &_methodSignature); // nodiscard is optional here
  35. private:
  36. jclass javaClass{};
  37. ::std::unordered_map<::std::string, ls::std::core::experimental::JniMethod> methods{};
  38. ::std::shared_ptr<ls::std::core::experimental::JniClassParameter> parameter{};
  39. ::std::string path{};
  40. void _callBooleanMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  41. void _callByteMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  42. void _callCharMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  43. void _callDoubleMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  44. void _callFloatMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  45. void _callIntMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  46. void _callLongMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  47. void _callShortMethod(const ::std::string &_methodIdentifier, ls::std::core::experimental::JniReturnValue &_returnValue);
  48. void _createJniApi() const;
  49. [[nodiscard]] bool _hasMethod(const ::std::string &_methodIdentifier);
  50. };
  51. }
  52. #endif