value.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* value.h - Node Value
  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_VALUE_H_7884E691_994C_52B4_A222_E536C3B5F9D9
  18. #define CORE_NODE_VALUE_H_7884E691_994C_52B4_A222_E536C3B5F9D9
  19. #include "abstract_value.h"
  20. namespace rainynite::core {
  21. template <typename T>
  22. class Value : public BaseValue<T> {
  23. public:
  24. bool is_const() const override {
  25. return true;
  26. }
  27. T get(shared_ptr<Context> /*context*/) const override {
  28. return value_;
  29. }
  30. void set(T new_value) override {
  31. value_ = new_value;
  32. this->changed();
  33. }
  34. T& mod() override {
  35. return value_;
  36. }
  37. bool can_set() const override {
  38. return true;
  39. }
  40. any static_any() const override {
  41. return value_;
  42. }
  43. public:
  44. template <typename... Args>
  45. void emplace(Args&&... args) {
  46. value_ = T(std::forward<Args>(args)...);
  47. }
  48. private:
  49. T value_;
  50. };
  51. } // namespace rainynite::core
  52. #endif