instance.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * instance.cpp - explicit template instantiation
  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/list.h>
  20. #include <core/types.h>
  21. #include <core/all_types.h>
  22. #include <core/serialize/node_writer.h>
  23. #include <core/time/parse.h>
  24. #include <core/time/format.h>
  25. #include <core/renderable.h>
  26. #include <core/document.h>
  27. #include <core/color.h>
  28. #include <core/nothing_io.h>
  29. #include <geom_helpers/knots_io.h>
  30. #include <geom_helpers/point_io.h>
  31. #include <geom_helpers/null_shape.h>
  32. #include <geom_helpers/rectangle.h>
  33. #include <geom_helpers/circle.h>
  34. namespace Geom {
  35. TYPE_INFO(BezierKnots, "BezierPath", [](auto&& s) {
  36. return parse_named_knots(s);
  37. });
  38. TYPE_INFO(Knot, "BezierKnot", [](auto&& s) {
  39. return parse_knot(s);
  40. });
  41. TYPE_INFO(Point, "Point", [](auto&& s) {
  42. return parse_point(s);
  43. });
  44. TYPE_INFO(NullShape, "NullShape", [](auto&&) {
  45. return NullShape {};
  46. });
  47. TYPE_INFO(Rectangle, "Rectangle", [](auto&& /*rect*/) {
  48. // TODO
  49. return Rectangle {};
  50. });
  51. TYPE_INFO(Circle, "Circle", [](auto&& /*circle*/) {
  52. // TODO
  53. return Circle {};
  54. });
  55. } // namespace Geom
  56. namespace std {
  57. TYPE_INFO(string, "String", [](auto&& s) {
  58. return s;
  59. });
  60. } // namespace std
  61. namespace rainynite::core {
  62. namespace colors {
  63. TYPE_INFO(Color, "Color", [](auto&& s) {
  64. return parse_hex(s);
  65. });
  66. } // namespace color
  67. namespace nodes {
  68. TYPE_INFO(Nothing, "Nothing", [](auto&&) {
  69. return Nothing();
  70. });
  71. TYPE_INFO(bool, "Boolean", [](auto&& s) {
  72. if (s == "true")
  73. return true;
  74. else if (s == "false")
  75. return false;
  76. throw serialize::DeserializationError("Cannot parse bool from \""+s+"\"");
  77. });
  78. TYPE_INFO(double, "Real", [](auto&& s) {
  79. // TODO: check correctness & locale issues
  80. return std::stod(s);
  81. });
  82. TYPE_INFO(TimePeriod, "TimePeriod", [](auto&& s) {
  83. return parse_time_period(s);
  84. });
  85. TYPE_INFO(Time, "Time", [](auto&& s) {
  86. return parse_time(s);
  87. });
  88. TYPE_INFO(Renderable, "Renderable", [](auto&&) -> any {
  89. throw serialize::DeserializationError("Renderable type cannot be deserialized");
  90. });
  91. TYPE_INFO(DocumentType, "Document", [](auto&&) -> any {
  92. throw serialize::DeserializationError("Document type cannot be deserialized");
  93. });
  94. TYPE_INFO(TimePointType, "Frame", [](auto&&) -> any {
  95. throw serialize::DeserializationError("Frame type cannot be deserialized");
  96. });
  97. class ValueTypeInfoBase {
  98. public:
  99. virtual string operator()(any const& object) const = 0;
  100. };
  101. class ValueTypeInfo : public ValueTypeInfoBase, class_init::Registered<ValueTypeInfo, AbstractReference, ValueTypeInfoBase> {
  102. public:
  103. virtual string operator()(any const& object) const {
  104. auto value = any_cast<AbstractReference>(object);
  105. return class_init::type_info<TypeInfo, string>(value->get_type());
  106. }
  107. };
  108. NODE_INFO_TEMPLATE(Value, Value<T>, T);
  109. NODE_INFO_TEMPLATE(List, ListValue<T>, vector<T>);
  110. TYPE_INSTANCES_WO_RENDERABLE(ValueNodeInfo)
  111. TYPE_INSTANCES(ListNodeInfo)
  112. } // namespace nodes
  113. REGISTER_NODE(UntypedListValue);
  114. namespace serialize {
  115. TYPE_INSTANCES_WO_RENDERABLE(AutoValueToString)
  116. } // namespace serialize
  117. } // namespace rainynite::core