com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-16
  6. * Changed: 2023-04-08
  7. *
  8. * */
  9. #include <iostream>
  10. #include <ls-std/core/evaluator/NullPointerEvaluator.hpp>
  11. #include <ls-std/core/jni/JniClass.hpp>
  12. #include <ls-std/core/jni/JniClassParameter.hpp>
  13. #include <ls-std/time/system-time/SystemTime.hpp>
  14. #include <ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.h>
  15. #include <memory>
  16. using ls::std::core::JniClass;
  17. using ls::std::core::JniClassParameter;
  18. using ls::std::core::NullPointerEvaluator;
  19. using ls::std::time::DateParameter;
  20. using ls::std::time::SystemTime;
  21. using ls::std::time::type::Day;
  22. using ls::std::time::type::Hour;
  23. using ls::std::time::type::Minute;
  24. using ls::std::time::type::Month;
  25. using ls::std::time::type::Second;
  26. using ls::std::time::type::Year;
  27. using std::cout;
  28. using std::endl;
  29. using std::make_shared;
  30. using std::pair;
  31. using std::shared_ptr;
  32. using std::string;
  33. JNIEXPORT jboolean JNICALL Java_com_lynarstudios_ls_std_time_systemtime_SystemTimeJni_set(JNIEnv *_environment, jobject _object, jobject _dateParameter)
  34. {
  35. shared_ptr<JniClassParameter> parameter = make_shared<JniClassParameter>();
  36. parameter->setJavaEnvironment(_environment);
  37. parameter->setJavaObject(_dateParameter);
  38. JniClass javaClass{parameter, "com/lynarstudios/ls/std/time/systemtime/DateParameter"};
  39. cout << (javaClass.load() ? "class loaded..." : "could not load class...") << endl;
  40. cout << (javaClass.loadMethod("getYear", "()I") ? "method loaded..." : "could not load method...") << endl;
  41. cout << (javaClass.loadMethod("getMonth", "()B") ? "method loaded..." : "could not load method...") << endl;
  42. cout << (javaClass.loadMethod("getDay", "()B") ? "method loaded..." : "could not load method...") << endl;
  43. cout << (javaClass.loadMethod("getHour", "()B") ? "method loaded..." : "could not load method...") << endl;
  44. cout << (javaClass.loadMethod("getMinute", "()B") ? "method loaded..." : "could not load method...") << endl;
  45. cout << (javaClass.loadMethod("getSecond", "()B") ? "method loaded..." : "could not load method...") << endl;
  46. Year year = javaClass.callMethod("getYear").getIntegerValue();
  47. Month month = javaClass.callMethod("getMonth").getByteValue();
  48. Day day = javaClass.callMethod("getDay").getByteValue();
  49. Hour hour = javaClass.callMethod("getHour").getByteValue();
  50. Minute minute = javaClass.callMethod("getMinute").getByteValue();
  51. Second second = javaClass.callMethod("getSecond").getByteValue();
  52. // map
  53. DateParameter dateParameter{};
  54. dateParameter.setYear(year);
  55. dateParameter.setMonth(month);
  56. dateParameter.setDay(day);
  57. dateParameter.setHour(hour);
  58. dateParameter.setMinute(minute);
  59. dateParameter.setSecond(second);
  60. return SystemTime{}.set(dateParameter);
  61. }