SystemTime.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-15
  6. * Changed: 2023-05-18
  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. using std::string;
  35. SystemTime::SystemTime(const shared_ptr<SystemTimeParameter> &_parameter) : Class(SystemTime::_fetchClassName()), parameter(_parameter)
  36. {
  37. NullPointerArgumentEvaluator{_parameter}.evaluate();
  38. }
  39. SystemTime::SystemTime() : Class(SystemTime::_fetchClassName())
  40. {
  41. this->_generateParameter();
  42. }
  43. SystemTime::~SystemTime() noexcept = default;
  44. bool SystemTime::set(const DateParameter &_dateParameter) const
  45. {
  46. return this->parameter->getClock()->setTime(_dateParameter);
  47. }
  48. string SystemTime::_fetchClassName()
  49. {
  50. static const string className = "SystemTime";
  51. return className;
  52. }
  53. void SystemTime::_generateParameter()
  54. {
  55. this->parameter = make_shared<SystemTimeParameter>();
  56. #if defined(unix) || defined(__APPLE__)
  57. this->parameter->setClock(make_shared<PosixClock>());
  58. #endif
  59. #ifdef _WIN32
  60. this->parameter->setClock(make_shared<WindowsClock>());
  61. #endif
  62. }