SystemTime.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-15
  6. * Changed: 2023-04-01
  7. *
  8. * */
  9. #include <ls-std/core/Class.hpp>
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #if defined(unix) || defined(__APPLE__)
  12. #include <ls-std/time/system-time/PosixClock.hpp>
  13. #endif
  14. #include <ls-std/time/system-time/SystemTime.hpp>
  15. #include <ls-std/time/system-time/SystemTimeParameter.hpp>
  16. #ifdef _WIN32
  17. #include <ls-std/time/system-time/WindowsClock.hpp>
  18. #endif
  19. #include <memory>
  20. using ls::std::core::Class;
  21. using ls::std::core::NullPointerArgumentEvaluator;
  22. using ls::std::time::DateParameter;
  23. #if defined(unix) || defined(__APPLE__)
  24. using ls::std::time::PosixClock;
  25. #endif
  26. using ls::std::time::SystemTime;
  27. using ls::std::time::SystemTimeParameter;
  28. #ifdef _WIN32
  29. using ls::std::time::WindowsClock;
  30. #endif
  31. using ls::std::time::type::UnixTimestamp;
  32. using std::make_shared;
  33. using std::shared_ptr;
  34. SystemTime::SystemTime(const shared_ptr<SystemTimeParameter> &_parameter) : SystemTime()
  35. {
  36. NullPointerArgumentEvaluator{_parameter}.evaluate();
  37. this->parameter = _parameter;
  38. }
  39. SystemTime::SystemTime() : Class("SystemTime")
  40. {
  41. this->_generateParameter();
  42. }
  43. SystemTime::~SystemTime() noexcept = default;
  44. bool SystemTime::set(const DateParameter &_dateParameter)
  45. {
  46. return this->parameter->getClock()->setTime(_dateParameter);
  47. }
  48. void SystemTime::_generateParameter()
  49. {
  50. this->parameter = make_shared<SystemTimeParameter>();
  51. #if defined(unix) || defined(__APPLE__)
  52. this->parameter->setClock(make_shared<PosixClock>());
  53. #endif
  54. #ifdef _WIN32
  55. this->parameter->setClock(make_shared<WindowsClock>());
  56. #endif
  57. }