time_period.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* time_period.cpp - TimePeriod related nodes
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <core/node_info/macros.h>
  18. #include <core/node/new_node.h>
  19. #include <core/time/period.h>
  20. namespace rainynite::core::nodes {
  21. class CompositeTimePeriod :
  22. public NewNode<
  23. CompositeTimePeriod,
  24. TimePeriod,
  25. types::Only<Time>,
  26. types::Only<Time>
  27. >
  28. {
  29. DOC_STRING(
  30. "Construct time period from starting and one-past-last point."
  31. )
  32. NODE_PROPERTIES("first", "last")
  33. DEFAULT_VALUES(Time{}, Time{})
  34. PROPERTY(first)
  35. PROPERTY(last)
  36. protected:
  37. TimePeriod get(shared_ptr<Context> ctx) const override {
  38. return {first_value<Time>(ctx), last_value<Time>(ctx)};
  39. }
  40. };
  41. REGISTER_NODE(CompositeTimePeriod);
  42. class SizedTimePeriod :
  43. public NewNode<
  44. SizedTimePeriod,
  45. TimePeriod,
  46. types::Only<Time>,
  47. types::Only<Time>
  48. >
  49. {
  50. DOC_STRING(
  51. "Construct time period from starting point and length."
  52. )
  53. NODE_PROPERTIES("first", "length")
  54. DEFAULT_VALUES(Time{}, Time{})
  55. PROPERTY(first)
  56. PROPERTY(length)
  57. protected:
  58. TimePeriod get(shared_ptr<Context> ctx) const override {
  59. auto first = first_value<Time>(ctx);
  60. return {first, first + length_value<Time>(ctx)};
  61. }
  62. };
  63. REGISTER_NODE(SizedTimePeriod);
  64. } // namespace rainynite::core::nodes