time_period.cpp 1.8 KB

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