node.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* node.h - Node
  2. * Copyright (C) 2017 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. #ifndef CORE_NODE_NODE_H_476155BB_19F8_5EF7_9AC8_30BEA7394210
  18. #define CORE_NODE_NODE_H_476155BB_19F8_5EF7_9AC8_30BEA7394210
  19. #include "abstract_node.h"
  20. #include "abstract_value.h"
  21. #include "list.h"
  22. namespace rainynite::core {
  23. /**
  24. * Basic representation of any time-changeable Node
  25. */
  26. template <typename T>
  27. class Node : public BaseValue<T>, public BaseOldNode {
  28. public:
  29. template <typename U>
  30. void init(string const& name, U value) {
  31. init_property(name, Type(typeid(U)), make_value<U>(value));
  32. }
  33. template <typename U>
  34. void init_list(string const& name) {
  35. auto list = make_shared<ListValue<U>>();
  36. list->new_id();
  37. init_property(name, Type(typeid(vector<U>)), list);
  38. }
  39. public:
  40. bool can_set_source(shared_ptr<AbstractValue> src) const override {
  41. if (link_count() == 0)
  42. return false;
  43. return get_link_type(0).accept(src->get_type());
  44. }
  45. void set_source(shared_ptr<AbstractValue> src) override {
  46. set_link(0, src);
  47. }
  48. protected:
  49. void node_changed() override {
  50. this->changed();
  51. }
  52. };
  53. } // namespace rainynite::core
  54. #endif