IterationFormula.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef MANDEL_ITERATIONFORMULA_H
  2. #define MANDEL_ITERATIONFORMULA_H
  3. #include <variant>
  4. #include <memory>
  5. #include <string>
  6. namespace mnd
  7. {
  8. struct IterationFormula;
  9. struct Constant;
  10. struct Variable;
  11. struct UnaryOperation;
  12. struct BinaryOperation;
  13. struct Addition;
  14. struct Multiplication;
  15. struct Division;
  16. struct Pow;
  17. using Expression = std::variant<
  18. Constant,
  19. Variable,
  20. UnaryOperation,
  21. Addition,
  22. Multiplication,
  23. Division,
  24. Pow
  25. >;
  26. std::unique_ptr<Expression> parse(const std::string& formula);
  27. std::string toString(const mnd::Expression&);
  28. }
  29. struct mnd::IterationFormula
  30. {
  31. std::unique_ptr<Expression> expr;
  32. };
  33. struct mnd::Constant
  34. {
  35. double value;
  36. inline Constant(double value) :
  37. value{ value }
  38. {}
  39. inline Constant() :
  40. value{ 1010 }
  41. {}
  42. };
  43. struct mnd::Variable
  44. {
  45. std::string name;
  46. };
  47. struct mnd::UnaryOperation
  48. {
  49. std::unique_ptr<Expression> operand;
  50. /*inline UnaryOperation(const UnaryOperation& other) :
  51. operand{ std::make_unique<Expression>(*other.operand) }
  52. {}*/
  53. };
  54. struct mnd::BinaryOperation
  55. {
  56. std::unique_ptr<Expression> left;
  57. std::unique_ptr<Expression> right;
  58. /*inline BinaryOperation(const BinaryOperation& other) :
  59. left{ std::make_unique<Expression>(*other.left) },
  60. right{ std::make_unique<Expression>(*other.right) }
  61. {}*/
  62. };
  63. struct mnd::Addition : mnd::BinaryOperation
  64. {
  65. bool subtraction = false;
  66. };
  67. struct mnd::Multiplication : mnd::BinaryOperation
  68. {
  69. };
  70. struct mnd::Division : mnd::BinaryOperation
  71. {
  72. };
  73. struct mnd::Pow : mnd::BinaryOperation
  74. {
  75. };
  76. namespace mnd
  77. {
  78. }
  79. #endif // MANDEL_ITERATIONFORMULA_H