cast.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* cast.h - common node casts
  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_CAST_H_D35FC2FE_53C0_5F57_9E51_7B3FD5202D55
  18. #define CORE_NODE_CAST_H_D35FC2FE_53C0_5F57_9E51_7B3FD5202D55
  19. #include <core/std/memory.h>
  20. namespace rainynite::core {
  21. class AbstractValue;
  22. template <typename T>
  23. class BaseValue;
  24. class AbstractListLinked;
  25. class AbstractNode;
  26. template <class From>
  27. shared_ptr<AbstractValue> abstract_value_cast(From&& pointer) {
  28. return dynamic_pointer_cast<AbstractValue>(std::forward<From>(pointer));
  29. }
  30. template <typename T, class From>
  31. shared_ptr<BaseValue<T>> base_value_cast(From&& pointer) {
  32. return dynamic_pointer_cast<BaseValue<T>>(std::forward<From>(pointer));
  33. }
  34. template <class From>
  35. shared_ptr<AbstractListLinked> list_cast(From&& pointer) {
  36. return dynamic_pointer_cast<AbstractListLinked>(std::forward<From>(pointer));
  37. }
  38. template <class From>
  39. shared_ptr<AbstractNode> abstract_node_cast(From&& pointer) {
  40. return dynamic_pointer_cast<AbstractNode>(std::forward<From>(pointer));
  41. }
  42. } // namespace rainynite::core
  43. #endif