Advertisement
SirBaconBitz

Untitled

May 15th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 36.32 KB | None | 0 0
  1. #include "Variable.h"
  2. #include <utility>
  3.  
  4. Variable::Variable(VariableType type, bool b): type(type), value(b) {}
  5.  
  6. Variable::Variable(VariableType type, char c): type(type), value(c) {}
  7.  
  8. Variable::Variable(VariableType type, int i): type(type), value(i) {}
  9.  
  10. Variable::Variable(VariableType type, long long l): type(type), value(l) {}
  11.  
  12. Variable::Variable(VariableType type, float f): type(type), value(f) {}
  13.  
  14. Variable::Variable(VariableType type, double d): type(type), value(d) {}
  15.  
  16. Variable::Variable(VariableType type, std::string s): type(type), value(s) {}
  17.  
  18. Variable::Variable(VariableType type): type(type) {
  19.     switch (type) {
  20.         case boole:
  21.             value = false;
  22.             break;
  23.         case chr:
  24.             value = (char) 0x0;
  25.             break;
  26.         case i32:
  27.             value = 0;
  28.             break;
  29.         case i64:
  30.             value = 0ll;
  31.             break;
  32.         case f32:
  33.             value = 0.0f;
  34.             break;
  35.         case f64:
  36.             value = 0.0l;
  37.             break;
  38.         case str:
  39.             value = std::string();
  40.             break;
  41.         default:
  42.             value = nullptr;
  43.             break;
  44.     }
  45. }
  46.  
  47. Variable::Variable(const Variable &other): type(other.type), value(other.value) {}
  48.  
  49. std::any Variable::getValue() {
  50.     return value;
  51. }
  52.  
  53. void Variable::setValue(std::any value) {
  54.     this->value = value;
  55. }
  56.  
  57. VariableType Variable::getType() {
  58.     return type;
  59. }
  60.  
  61. VariableType Variable::resolveTypeString(std::string string) {
  62.     if (string == "boole") {
  63.         return boole;
  64.     } else if (string == "chr") {
  65.         return chr;
  66.     } else if (string == "i32") {
  67.         return i32;
  68.     } else if (string == "i64") {
  69.         return i64;
  70.     } else if (string == "f32") {
  71.         return f32;
  72.     } else if (string == "f64") {
  73.         return f64;
  74.     } else if (string == "str") {
  75.         return str;
  76.     } else {
  77.         return null;
  78.     }
  79. }
  80.  
  81. std::string Variable::resolveTypeEnum(VariableType type) {
  82.     switch (type) {
  83.         case boole:
  84.             return "bool";
  85.         case chr:
  86.             return "char";
  87.         case i32:
  88.             return "i32";
  89.         case i64:
  90.             return "i64";
  91.         case f32:
  92.             return "f32";
  93.         case f64:
  94.             return "f64";
  95.         case str:
  96.             return "str";
  97.         default:
  98.             return "null";
  99.     }
  100. }
  101.  
  102. std::string Variable::toString() {
  103.     switch (type) {
  104.         case boole:
  105.             return std::any_cast<bool>(value) ? std::string("true") : std::string("false");
  106.         case chr:
  107.             return std::string() + std::any_cast<char>(value);
  108.         case i32:
  109.             return std::to_string(std::any_cast<int>(value));
  110.         case i64:
  111.             return std::to_string(std::any_cast<long long>(value));
  112.         case f32:
  113.             return std::to_string(std::any_cast<float>(value));
  114.         case f64:
  115.             return std::to_string(std::any_cast<double>(value));
  116.         case str:
  117.             return std::any_cast<std::string>(value);
  118.         default:
  119.             return std::string("null");
  120.     }
  121. }
  122.  
  123. Variable Variable::add(const Variable& other) {
  124.     if (type == boole || type == null || other.type == boole || other.type == null) return Variable(null);
  125.  
  126.     if (type == chr && other.type == chr) {
  127.         return Variable(chr, std::any_cast<char>(value) + std::any_cast<char>(other.value));
  128.     } else if (type == chr && other.type == i32) {
  129.         return Variable(i32, std::any_cast<char>(value) + std::any_cast<int>(other.value));
  130.     } else if (type == chr && other.type == i64) {
  131.         return Variable(i64, (long long) std::any_cast<char>(value) + std::any_cast<long long>(other.value));
  132.     } else if (type == chr && other.type == f32) {
  133.         return Variable(f32, std::any_cast<char>(value) + std::any_cast<float>(other.value));
  134.     } else if (type == chr && other.type == f64) {
  135.         return Variable(f64, std::any_cast<char>(value) + std::any_cast<double>(other.value));
  136.     } else if (type == chr && other.type == str) {
  137.         return Variable(str, std::any_cast<char>(value) + std::any_cast<std::string>(other.value));
  138.     } else if (type == i32 && other.type == chr) {
  139.         return Variable(i32, std::any_cast<int>(value) + std::any_cast<char>(other.value));
  140.     } else if (type == i32 && other.type == i32) {
  141.         return Variable(i32, std::any_cast<int>(value) + std::any_cast<int>(other.value));
  142.     } else if (type == i32 && other.type == i64) {
  143.         return Variable(i64, (long long) std::any_cast<int>(value) + std::any_cast<long long>(other.value));
  144.     } else if (type == i32 && other.type == f32) {
  145.         return Variable(f32, std::any_cast<int>(value) + std::any_cast<float>(other.value));
  146.     } else if (type == i32 && other.type == f64) {
  147.         return Variable(f64, std::any_cast<int>(value) + std::any_cast<double>(other.value));
  148.     } else if (type == i32 && other.type == str) {
  149.         return Variable(str, std::to_string(std::any_cast<int>(value)) + std::any_cast<std::string>(other.value));
  150.     } else if (type == i64 && other.type == chr) {
  151.         return Variable(i64, (long long) std::any_cast<long long>(value) + std::any_cast<char>(other.value));
  152.     } else if (type == i64 && other.type == i32) {
  153.         return Variable(i64, (long long) std::any_cast<long long>(value) + std::any_cast<int>(other.value));
  154.     } else if (type == i64 && other.type == i64) {
  155.         return Variable(i64, (long long) std::any_cast<long long>(value) + std::any_cast<long long>(other.value));
  156.     } else if (type == i64 && other.type == f32) {
  157.         return Variable(f32, std::any_cast<long long>(value) + std::any_cast<float>(other.value));
  158.     } else if (type == i64 && other.type == f64) {
  159.         return Variable(f64, std::any_cast<long long>(value) + std::any_cast<double>(other.value));
  160.     } else if (type == i64 && other.type == str) {
  161.         return Variable(str, std::to_string(std::any_cast<long long>(value)) + std::any_cast<std::string>(other.value));
  162.     } else if (type == f32 && other.type == chr) {
  163.         return Variable(f32, std::any_cast<float>(value) + std::any_cast<char>(other.value));
  164.     } else if (type == f32 && other.type == i32) {
  165.         return Variable(f32, std::any_cast<float>(value) + std::any_cast<int>(other.value));
  166.     } else if (type == f32 && other.type == i64) {
  167.         return Variable(f32, std::any_cast<float>(value) + std::any_cast<long long>(other.value));
  168.     } else if (type == f32 && other.type == f32) {
  169.         return Variable(f32, std::any_cast<float>(value) + std::any_cast<float>(other.value));
  170.     } else if (type == f32 && other.type == f64) {
  171.         return Variable(f64, std::any_cast<float>(value) + std::any_cast<double>(other.value));
  172.     } else if (type == f32 && other.type == str) {
  173.         return Variable(str, std::to_string(std::any_cast<float>(value)) + std::any_cast<std::string>(other.value));
  174.     } else if (type == f64 && other.type == chr) {
  175.         return Variable(f64, std::any_cast<double>(value) + std::any_cast<char>(other.value));
  176.     } else if (type == f64 && other.type == i32) {
  177.         return Variable(f64, std::any_cast<double>(value) + std::any_cast<int>(other.value));
  178.     } else if (type == f64 && other.type == i64) {
  179.         return Variable(f64, std::any_cast<double>(value) + std::any_cast<long long>(other.value));
  180.     } else if (type == f64 && other.type == f32) {
  181.         return Variable(f64, std::any_cast<double>(value) + std::any_cast<float>(other.value));
  182.     } else if (type == f64 && other.type == f64) {
  183.         return Variable(f64, std::any_cast<double>(value) + std::any_cast<double>(other.value));
  184.     } else if (type == f64 && other.type == str) {
  185.         return Variable(str, std::to_string(std::any_cast<double>(value)) + std::any_cast<std::string>(other.value));
  186.     } else if (type == str && other.type == chr) {
  187.         return Variable(str, std::any_cast<std::string>(value) + std::any_cast<char>(other.value));
  188.     } else if (type == str && other.type == i32) {
  189.         return Variable(str, std::any_cast<std::string>(value) + std::to_string(std::any_cast<int>(other.value)));
  190.     } else if (type == str && other.type == i64) {
  191.         return Variable(str, std::any_cast<std::string>(value) + std::to_string(std::any_cast<long long>(other.value)));
  192.     } else if (type == str && other.type == f32) {
  193.         return Variable(str, std::any_cast<std::string>(value) + std::to_string(std::any_cast<float>(other.value)));
  194.     } else if (type == str && other.type == f64) {
  195.         return Variable(str, std::any_cast<std::string>(value) + std::to_string(std::any_cast<double>(other.value)));
  196.     } else if (type == str && other.type == str) {
  197.         return Variable(str, std::any_cast<std::string>(value) + std::any_cast<std::string>(other.value));
  198.     }
  199.     return Variable(null);
  200. }
  201.  
  202. Variable Variable::sub(const Variable& other) {
  203.     if (type == boole || type == null || other.type == boole || other.type == null || type == str || other.type == str) return Variable(null);
  204.  
  205.     if (type == chr && other.type == chr) {
  206.         return Variable(chr, std::any_cast<char>(value) - std::any_cast<char>(other.value));
  207.     } else if (type == chr && other.type == i32) {
  208.         return Variable(i32, std::any_cast<char>(value) - std::any_cast<int>(other.value));
  209.     } else if (type == chr && other.type == i64) {
  210.         return Variable(i64, (long long) std::any_cast<char>(value) - std::any_cast<long long>(other.value));
  211.     } else if (type == chr && other.type == f32) {
  212.         return Variable(f32, std::any_cast<char>(value) - std::any_cast<float>(other.value));
  213.     } else if (type == chr && other.type == f64) {
  214.         return Variable(f64, std::any_cast<char>(value) - std::any_cast<double>(other.value));
  215.     } else if (type == i32 && other.type == chr) {
  216.         return Variable(i32, std::any_cast<int>(value) - std::any_cast<char>(other.value));
  217.     } else if (type == i32 && other.type == i32) {
  218.         return Variable(i32, std::any_cast<int>(value) - std::any_cast<int>(other.value));
  219.     } else if (type == i32 && other.type == i64) {
  220.         return Variable(i64, (long long) std::any_cast<int>(value) - std::any_cast<long long>(other.value));
  221.     } else if (type == i32 && other.type == f32) {
  222.         return Variable(f32, std::any_cast<int>(value) - std::any_cast<float>(other.value));
  223.     } else if (type == i32 && other.type == f64) {
  224.         return Variable(f64, std::any_cast<int>(value) - std::any_cast<double>(other.value));
  225.     } else if (type == i64 && other.type == chr) {
  226.         return Variable(i64, (long long) std::any_cast<long long>(value) - std::any_cast<char>(other.value));
  227.     } else if (type == i64 && other.type == i32) {
  228.         return Variable(i64, (long long) std::any_cast<long long>(value) - std::any_cast<int>(other.value));
  229.     } else if (type == i64 && other.type == i64) {
  230.         return Variable(i64, (long long) std::any_cast<long long>(value) - std::any_cast<long long>(other.value));
  231.     } else if (type == i64 && other.type == f32) {
  232.         return Variable(f32, std::any_cast<long long>(value) - std::any_cast<float>(other.value));
  233.     } else if (type == i64 && other.type == f64) {
  234.         return Variable(f64, std::any_cast<long long>(value) - std::any_cast<double>(other.value));
  235.     } else if (type == f32 && other.type == chr) {
  236.         return Variable(f32, std::any_cast<float>(value) - std::any_cast<char>(other.value));
  237.     } else if (type == f32 && other.type == i32) {
  238.         return Variable(f32, std::any_cast<float>(value) - std::any_cast<int>(other.value));
  239.     } else if (type == f32 && other.type == i64) {
  240.         return Variable(f32, std::any_cast<float>(value) - std::any_cast<long long>(other.value));
  241.     } else if (type == f32 && other.type == f32) {
  242.         return Variable(f32, std::any_cast<float>(value) - std::any_cast<float>(other.value));
  243.     } else if (type == f32 && other.type == f64) {
  244.         return Variable(f64, std::any_cast<float>(value) - std::any_cast<double>(other.value));
  245.     } else if (type == f64 && other.type == chr) {
  246.         return Variable(f64, std::any_cast<double>(value) - std::any_cast<char>(other.value));
  247.     } else if (type == f64 && other.type == i32) {
  248.         return Variable(f64, std::any_cast<double>(value) - std::any_cast<int>(other.value));
  249.     } else if (type == f64 && other.type == i64) {
  250.         return Variable(f64, std::any_cast<double>(value) - std::any_cast<long long>(other.value));
  251.     } else if (type == f64 && other.type == f32) {
  252.         return Variable(f64, std::any_cast<double>(value) - std::any_cast<float>(other.value));
  253.     } else if (type == f64 && other.type == f64) {
  254.         return Variable(f64, std::any_cast<double>(value) - std::any_cast<double>(other.value));
  255.     }
  256.     return Variable(null);
  257. }
  258.  
  259. Variable Variable::mul(const Variable& other) {
  260.     if (type == boole || type == null || other.type == boole || other.type == null || type == str || other.type == str) return Variable(null);
  261.  
  262.     if (type == chr && other.type == chr) {
  263.         return Variable(chr, std::any_cast<char>(value) * std::any_cast<char>(other.value));
  264.     } else if (type == chr && other.type == i32) {
  265.         return Variable(i32, std::any_cast<char>(value) * std::any_cast<int>(other.value));
  266.     } else if (type == chr && other.type == i64) {
  267.         return Variable(i64, (long long) std::any_cast<char>(value) * std::any_cast<long long>(other.value));
  268.     } else if (type == chr && other.type == f32) {
  269.         return Variable(f32, std::any_cast<char>(value) * std::any_cast<float>(other.value));
  270.     } else if (type == chr && other.type == f64) {
  271.         return Variable(f64, std::any_cast<char>(value) * std::any_cast<double>(other.value));
  272.     } else if (type == i32 && other.type == chr) {
  273.         return Variable(i32, std::any_cast<int>(value) * std::any_cast<char>(other.value));
  274.     } else if (type == i32 && other.type == i32) {
  275.         return Variable(i32, std::any_cast<int>(value) * std::any_cast<int>(other.value));
  276.     } else if (type == i32 && other.type == i64) {
  277.         return Variable(i64, (long long) std::any_cast<int>(value) * std::any_cast<long long>(other.value));
  278.     } else if (type == i32 && other.type == f32) {
  279.         return Variable(f32, std::any_cast<int>(value) * std::any_cast<float>(other.value));
  280.     } else if (type == i32 && other.type == f64) {
  281.         return Variable(f64, std::any_cast<int>(value) * std::any_cast<double>(other.value));
  282.     } else if (type == i64 && other.type == chr) {
  283.         return Variable(i64, (long long) std::any_cast<long long>(value) * std::any_cast<char>(other.value));
  284.     } else if (type == i64 && other.type == i32) {
  285.         return Variable(i64, (long long) std::any_cast<long long>(value) * std::any_cast<int>(other.value));
  286.     } else if (type == i64 && other.type == i64) {
  287.         return Variable(i64, (long long) std::any_cast<long long>(value) * std::any_cast<long long>(other.value));
  288.     } else if (type == i64 && other.type == f32) {
  289.         return Variable(f32, std::any_cast<long long>(value) * std::any_cast<float>(other.value));
  290.     } else if (type == i64 && other.type == f64) {
  291.         return Variable(f64, std::any_cast<long long>(value) * std::any_cast<double>(other.value));
  292.     } else if (type == f32 && other.type == chr) {
  293.         return Variable(f32, std::any_cast<float>(value) * std::any_cast<char>(other.value));
  294.     } else if (type == f32 && other.type == i32) {
  295.         return Variable(f32, std::any_cast<float>(value) * std::any_cast<int>(other.value));
  296.     } else if (type == f32 && other.type == i64) {
  297.         return Variable(f32, std::any_cast<float>(value) * std::any_cast<long long>(other.value));
  298.     } else if (type == f32 && other.type == f32) {
  299.         return Variable(f32, std::any_cast<float>(value) * std::any_cast<float>(other.value));
  300.     } else if (type == f32 && other.type == f64) {
  301.         return Variable(f64, std::any_cast<float>(value) * std::any_cast<double>(other.value));
  302.     } else if (type == f64 && other.type == chr) {
  303.         return Variable(f64, std::any_cast<double>(value) * std::any_cast<char>(other.value));
  304.     } else if (type == f64 && other.type == i32) {
  305.         return Variable(f64, std::any_cast<double>(value) * std::any_cast<int>(other.value));
  306.     } else if (type == f64 && other.type == i64) {
  307.         return Variable(f64, std::any_cast<double>(value) * std::any_cast<long long>(other.value));
  308.     } else if (type == f64 && other.type == f32) {
  309.         return Variable(f64, std::any_cast<double>(value) * std::any_cast<float>(other.value));
  310.     } else if (type == f64 && other.type == f64) {
  311.         return Variable(f64, std::any_cast<double>(value) * std::any_cast<double>(other.value));
  312.     }
  313.     return Variable(null);
  314. }
  315.  
  316. Variable Variable::div(const Variable& other) {
  317.     if (type == boole || type == null || other.type == boole || other.type == null || type == str || other.type == str) return Variable(null);
  318.  
  319.     if (type == chr && other.type == chr) {
  320.         return Variable(chr, std::any_cast<char>(value) / std::any_cast<char>(other.value));
  321.     } else if (type == chr && other.type == i32) {
  322.         return Variable(i32, std::any_cast<char>(value) / std::any_cast<int>(other.value));
  323.     } else if (type == chr && other.type == i64) {
  324.         return Variable(i64, (long long) std::any_cast<char>(value) / std::any_cast<long long>(other.value));
  325.     } else if (type == chr && other.type == f32) {
  326.         return Variable(f32, std::any_cast<char>(value) / std::any_cast<float>(other.value));
  327.     } else if (type == chr && other.type == f64) {
  328.         return Variable(f64, std::any_cast<char>(value) / std::any_cast<double>(other.value));
  329.     } else if (type == i32 && other.type == chr) {
  330.         return Variable(i32, std::any_cast<int>(value) / std::any_cast<char>(other.value));
  331.     } else if (type == i32 && other.type == i32) {
  332.         return Variable(i32, std::any_cast<int>(value) / std::any_cast<int>(other.value));
  333.     } else if (type == i32 && other.type == i64) {
  334.         return Variable(i64, (long long) std::any_cast<int>(value) / std::any_cast<long long>(other.value));
  335.     } else if (type == i32 && other.type == f32) {
  336.         return Variable(f32, std::any_cast<int>(value) / std::any_cast<float>(other.value));
  337.     } else if (type == i32 && other.type == f64) {
  338.         return Variable(f64, std::any_cast<int>(value) / std::any_cast<double>(other.value));
  339.     } else if (type == i64 && other.type == chr) {
  340.         return Variable(i64, (long long) std::any_cast<long long>(value) / std::any_cast<char>(other.value));
  341.     } else if (type == i64 && other.type == i32) {
  342.         return Variable(i64, (long long) std::any_cast<long long>(value) / std::any_cast<int>(other.value));
  343.     } else if (type == i64 && other.type == i64) {
  344.         return Variable(i64, (long long) std::any_cast<long long>(value) / std::any_cast<long long>(other.value));
  345.     } else if (type == i64 && other.type == f32) {
  346.         return Variable(f32, std::any_cast<long long>(value) / std::any_cast<float>(other.value));
  347.     } else if (type == i64 && other.type == f64) {
  348.         return Variable(f64, std::any_cast<long long>(value) / std::any_cast<double>(other.value));
  349.     } else if (type == f32 && other.type == chr) {
  350.         return Variable(f32, std::any_cast<float>(value) / std::any_cast<char>(other.value));
  351.     } else if (type == f32 && other.type == i32) {
  352.         return Variable(f32, std::any_cast<float>(value) / std::any_cast<int>(other.value));
  353.     } else if (type == f32 && other.type == i64) {
  354.         return Variable(f32, std::any_cast<float>(value) / std::any_cast<long long>(other.value));
  355.     } else if (type == f32 && other.type == f32) {
  356.         return Variable(f32, std::any_cast<float>(value) / std::any_cast<float>(other.value));
  357.     } else if (type == f32 && other.type == f64) {
  358.         return Variable(f64, std::any_cast<float>(value) / std::any_cast<double>(other.value));
  359.     } else if (type == f64 && other.type == chr) {
  360.         return Variable(f64, std::any_cast<double>(value) / std::any_cast<char>(other.value));
  361.     } else if (type == f64 && other.type == i32) {
  362.         return Variable(f64, std::any_cast<double>(value) / std::any_cast<int>(other.value));
  363.     } else if (type == f64 && other.type == i64) {
  364.         return Variable(f64, std::any_cast<double>(value) / std::any_cast<long long>(other.value));
  365.     } else if (type == f64 && other.type == f32) {
  366.         return Variable(f64, std::any_cast<double>(value) / std::any_cast<float>(other.value));
  367.     } else if (type == f64 && other.type == f64) {
  368.         return Variable(f64, std::any_cast<double>(value) / std::any_cast<double>(other.value));
  369.     }
  370.     return Variable(null);
  371. }
  372.  
  373. Variable Variable::mod(const Variable& other) {
  374.     if (type == boole || type == null || other.type == boole || other.type == null || type == str || other.type == str) return Variable(null);
  375.  
  376.     if (type == chr && other.type == chr) {
  377.         return Variable(chr, std::any_cast<char>(value) % std::any_cast<char>(other.value));
  378.     } else if (type == chr && other.type == i32) {
  379.         return Variable(i32, std::any_cast<char>(value) % std::any_cast<int>(other.value));
  380.     } else if (type == chr && other.type == i64) {
  381.         return Variable(i64, (long long) std::any_cast<char>(value) % std::any_cast<long long>(other.value));
  382.     } else if (type == chr && other.type == f32) {
  383.         return Variable(f32, std::fmod(std::any_cast<char>(value), std::any_cast<float>(other.value)));
  384.     } else if (type == chr && other.type == f64) {
  385.         return Variable(f32, std::fmod(std::any_cast<char>(value), std::any_cast<double>(other.value)));
  386.     } else if (type == i32 && other.type == chr) {
  387.         return Variable(i32, std::any_cast<int>(value) % std::any_cast<char>(other.value));
  388.     } else if (type == i32 && other.type == i32) {
  389.         return Variable(i32, std::any_cast<int>(value) % std::any_cast<int>(other.value));
  390.     } else if (type == i32 && other.type == i64) {
  391.         return Variable(i64, (long long) std::any_cast<int>(value) % std::any_cast<long long>(other.value));
  392.     } else if (type == i32 && other.type == f32) {
  393.         return Variable(f32, std::fmod(std::any_cast<int>(value), std::any_cast<float > (other.value)));
  394.     } else if (type == i32 && other.type == f64) {
  395.         return Variable(f32, std::fmod(std::any_cast<int>(value), std::any_cast<double>(other.value)));
  396.     } else if (type == i64 && other.type == chr) {
  397.         return Variable(i64, (long long) std::any_cast<long long>(value) % std::any_cast<char>(other.value));
  398.     } else if (type == i64 && other.type == i32) {
  399.         return Variable(i64, (long long) std::any_cast<long long>(value) % std::any_cast<int>(other.value));
  400.     } else if (type == i64 && other.type == i64) {
  401.         return Variable(i64, (long long) std::any_cast<long long>(value) % std::any_cast<long long>(other.value));
  402.     } else if (type == i64 && other.type == f32) {
  403.         return Variable(f32, std::fmod(std::any_cast<long long>(value), std::any_cast<float>(other.value)));
  404.     } else if (type == i64 && other.type == f64) {
  405.         return Variable(f32, std::fmod(std::any_cast<long long>(value), std::any_cast<double>(other.value)));
  406.     } else if (type == f32 && other.type == chr) {
  407.         return Variable(f32, std::fmod(std::any_cast<float>(value), std::any_cast<char>(other.value)));
  408.     } else if (type == f32 && other.type == i32) {
  409.         return Variable(f32, std::fmod(std::any_cast<float>(value), std::any_cast<int>(other.value)));
  410.     } else if (type == f32 && other.type == i64) {
  411.         return Variable(f32, std::fmod(std::any_cast<float>(value), std::any_cast<long long>(other.value)));
  412.     } else if (type == f32 && other.type == f32) {
  413.         return Variable(f32, std::fmod(std::any_cast<float>(value), std::any_cast<float>(other.value)));
  414.     } else if (type == f32 && other.type == f64) {
  415.         return Variable(f32, std::fmod(std::any_cast<float>(value), std::any_cast<double>(other.value)));
  416.     } else if (type == f64 && other.type == chr) {
  417.         return Variable(f32, std::fmod(std::any_cast<double>(value), std::any_cast<char>(other.value)));
  418.     } else if (type == f64 && other.type == i32) {
  419.         return Variable(f32, std::fmod(std::any_cast<double>(value), std::any_cast<int>(other.value)));
  420.     } else if (type == f64 && other.type == i64) {
  421.         return Variable(f32, std::fmod(std::any_cast<double>(value), std::any_cast<long long>(other.value)));
  422.     } else if (type == f64 && other.type == f32) {
  423.         return Variable(f32, std::fmod(std::any_cast<double>(value), std::any_cast<float>(other.value)));
  424.     } else if (type == f64 && other.type == f64) {
  425.         return Variable(f32, std::fmod(std::any_cast<double>(value), std::any_cast<double>(other.value)));
  426.     }
  427.     return Variable(null);
  428. }
  429.  
  430. Variable Variable::equals(const Variable& other) {
  431.     if (type == null && other.type == null) return Variable(boole, true);
  432.     else if (type == boole && other.type == boole) {
  433.         bool a = std::any_cast<bool>(value);
  434.         bool b = std::any_cast<bool>(other.value);
  435.         return Variable(boole, a == b);
  436.     }
  437.  
  438.     if (type == chr && other.type == chr) {
  439.         return Variable(boole, std::any_cast<char>(value) == std::any_cast<char>(other.value));
  440.     } else if (type == chr && other.type == i32) {
  441.         return Variable(boole, std::any_cast<char>(value) == std::any_cast<int>(other.value));
  442.     } else if (type == chr && other.type == i64) {
  443.         return Variable(boole, std::any_cast<char>(value) == std::any_cast<long long>(other.value));
  444.     } else if (type == chr && other.type == f32) {
  445.         return Variable(boole, std::any_cast<char>(value) == std::any_cast<float>(other.value));
  446.     } else if (type == chr && other.type == f64) {
  447.         return Variable(boole, std::any_cast<char>(value) == std::any_cast<double>(other.value));
  448.     } else if (type == chr && other.type == str) {
  449.         return Variable(boole, std::string() + std::any_cast<char>(value) == std::any_cast<std::string>(other.value));
  450.     } else if (type == i32 && other.type == chr) {
  451.         return Variable(boole, std::any_cast<int>(value) == std::any_cast<char>(other.value));
  452.     } else if (type == i32 && other.type == i32) {
  453.         return Variable(boole, std::any_cast<int>(value) == std::any_cast<int>(other.value));
  454.     } else if (type == i32 && other.type == i64) {
  455.         return Variable(boole, std::any_cast<int>(value) == std::any_cast<long long>(other.value));
  456.     } else if (type == i32 && other.type == f32) {
  457.         return Variable(boole, std::any_cast<int>(value) == std::any_cast<float>(other.value));
  458.     } else if (type == i32 && other.type == f64) {
  459.         return Variable(boole, std::any_cast<int>(value) == std::any_cast<double>(other.value));
  460.     } else if (type == i32 && other.type == str) {
  461.         return Variable(boole, std::to_string(std::any_cast<int>(value)) == std::any_cast<std::string>(other.value));
  462.     } else if (type == i64 && other.type == chr) {
  463.         return Variable(boole, std::any_cast<long long>(value) == std::any_cast<char>(other.value));
  464.     } else if (type == i64 && other.type == i32) {
  465.         return Variable(boole, std::any_cast<long long>(value) == std::any_cast<int>(other.value));
  466.     } else if (type == i64 && other.type == i64) {
  467.         return Variable(boole, std::any_cast<long long>(value) == std::any_cast<long long>(other.value));
  468.     } else if (type == i64 && other.type == f32) {
  469.         return Variable(boole, std::any_cast<long long>(value) == std::any_cast<float>(other.value));
  470.     } else if (type == i64 && other.type == f64) {
  471.         return Variable(boole, std::any_cast<long long>(value) == std::any_cast<double>(other.value));
  472.     } else if (type == i64 && other.type == str) {
  473.         return Variable(boole, std::to_string(std::any_cast<long long>(value)) == std::any_cast<std::string>(other.value));
  474.     } else if (type == f32 && other.type == chr) {
  475.         return Variable(boole, std::any_cast<float>(value) == std::any_cast<char>(other.value));
  476.     } else if (type == f32 && other.type == i32) {
  477.         return Variable(boole, std::any_cast<float>(value) == std::any_cast<int>(other.value));
  478.     } else if (type == f32 && other.type == i64) {
  479.         return Variable(boole, std::any_cast<float>(value) == std::any_cast<long long>(other.value));
  480.     } else if (type == f32 && other.type == f32) {
  481.         return Variable(boole, std::any_cast<float>(value) == std::any_cast<float>(other.value));
  482.     } else if (type == f32 && other.type == f64) {
  483.         return Variable(boole, std::any_cast<float>(value) == std::any_cast<double>(other.value));
  484.     } else if (type == f32 && other.type == str) {
  485.         return Variable(boole, std::to_string(std::any_cast<float>(value)) == std::any_cast<std::string>(other.value));
  486.     } else if (type == f64 && other.type == chr) {
  487.         return Variable(boole, std::any_cast<double>(value) == std::any_cast<char>(other.value));
  488.     } else if (type == f64 && other.type == i32) {
  489.         return Variable(boole, std::any_cast<double>(value) == std::any_cast<int>(other.value));
  490.     } else if (type == f64 && other.type == i64) {
  491.         return Variable(boole, std::any_cast<double>(value) == std::any_cast<long long>(other.value));
  492.     } else if (type == f64 && other.type == f32) {
  493.         return Variable(boole, std::any_cast<double>(value) == std::any_cast<float>(other.value));
  494.     } else if (type == f64 && other.type == f64) {
  495.         return Variable(boole, std::any_cast<double>(value) == std::any_cast<double>(other.value));
  496.     } else if (type == f64 && other.type == str) {
  497.         return Variable(boole, std::to_string(std::any_cast<double>(value)) == std::any_cast<std::string>(other.value));
  498.     } else if (type == str && other.type == chr) {
  499.         return Variable(boole, std::any_cast<std::string>(value) == std::string() + std::any_cast<char>(other.value));
  500.     } else if (type == str && other.type == i32) {
  501.         return Variable(boole, std::any_cast<std::string>(value) == std::to_string(std::any_cast<int>(other.value)));
  502.     } else if (type == str && other.type == i64) {
  503.         return Variable(boole, std::any_cast<std::string>(value) == std::to_string(std::any_cast<long long>(other.value)));
  504.     } else if (type == str && other.type == f32) {
  505.         return Variable(boole, std::any_cast<std::string>(value) == std::to_string(std::any_cast<float>(other.value)));
  506.     } else if (type == str && other.type == f64) {
  507.         return Variable(boole, std::any_cast<std::string>(value) == std::to_string(std::any_cast<double>(other.value)));
  508.     } else if (type == str && other.type == str) {
  509.         return Variable(boole, std::any_cast<std::string>(value) == std::any_cast<std::string>(other.value));
  510.     }
  511.     return Variable(boole, false);
  512. }
  513.  
  514. Variable Variable::notEquals(const Variable& other) {
  515.     Variable equal = equals(other);
  516.     bool val = std::any_cast<bool>(equal.value);
  517.     return Variable(boole, !val);
  518. }
  519.  
  520. Variable Variable::greater(const Variable& other) {
  521.     if (type == boole || type == str || type == null || other.type == boole || other.type == str || other.type == null) return Variable(null);
  522.  
  523.     if (type == chr && other.type == chr) {
  524.         return Variable(boole, std::any_cast<char>(value) > std::any_cast<char>(other.value));
  525.     } else if (type == chr && other.type == i32) {
  526.         return Variable(boole, std::any_cast<char>(value) > std::any_cast<int>(other.value));
  527.     } else if (type == chr && other.type == i64) {
  528.         return Variable(boole, std::any_cast<char>(value) > std::any_cast<long long>(other.value));
  529.     } else if (type == chr && other.type == f32) {
  530.         return Variable(boole, std::any_cast<char>(value) > std::any_cast<float>(other.value));
  531.     } else if (type == chr && other.type == f64) {
  532.         return Variable(boole, std::any_cast<char>(value) > std::any_cast<double>(other.value));
  533.     } else if (type == i32 && other.type == chr) {
  534.         return Variable(boole, std::any_cast<int>(value) > std::any_cast<char>(other.value));
  535.     } else if (type == i32 && other.type == i32) {
  536.         return Variable(boole, std::any_cast<int>(value) > std::any_cast<int>(other.value));
  537.     } else if (type == i32 && other.type == i64) {
  538.         return Variable(boole, std::any_cast<int>(value) > std::any_cast<long long>(other.value));
  539.     } else if (type == i32 && other.type == f32) {
  540.         return Variable(boole, std::any_cast<int>(value) > std::any_cast<float>(other.value));
  541.     } else if (type == i32 && other.type == f64) {
  542.         return Variable(boole, std::any_cast<int>(value) > std::any_cast<double>(other.value));
  543.     } else if (type == i64 && other.type == chr) {
  544.         return Variable(boole, std::any_cast<long long>(value) > std::any_cast<char>(other.value));
  545.     } else if (type == i64 && other.type == i32) {
  546.         return Variable(boole, std::any_cast<long long>(value) > std::any_cast<int>(other.value));
  547.     } else if (type == i64 && other.type == i64) {
  548.         return Variable(boole, std::any_cast<long long>(value) > std::any_cast<long long>(other.value));
  549.     } else if (type == i64 && other.type == f32) {
  550.         return Variable(boole, std::any_cast<long long>(value) > std::any_cast<float>(other.value));
  551.     } else if (type == i64 && other.type == f64) {
  552.         return Variable(boole, std::any_cast<long long>(value) > std::any_cast<double>(other.value));
  553.     } else if (type == f32 && other.type == chr) {
  554.         return Variable(boole, std::any_cast<float>(value) > std::any_cast<char>(other.value));
  555.     } else if (type == f32 && other.type == i32) {
  556.         return Variable(boole, std::any_cast<float>(value) > std::any_cast<int>(other.value));
  557.     } else if (type == f32 && other.type == i64) {
  558.         return Variable(boole, std::any_cast<float>(value) > std::any_cast<long long>(other.value));
  559.     } else if (type == f32 && other.type == f32) {
  560.         return Variable(boole, std::any_cast<float>(value) > std::any_cast<float>(other.value));
  561.     } else if (type == f32 && other.type == f64) {
  562.         return Variable(boole, std::any_cast<float>(value) > std::any_cast<double>(other.value));
  563.     } else if (type == f64 && other.type == chr) {
  564.         return Variable(boole, std::any_cast<double>(value) > std::any_cast<char>(other.value));
  565.     } else if (type == f64 && other.type == i32) {
  566.         return Variable(boole, std::any_cast<double>(value) > std::any_cast<int>(other.value));
  567.     } else if (type == f64 && other.type == i64) {
  568.         return Variable(boole, std::any_cast<double>(value) > std::any_cast<long long>(other.value));
  569.     } else if (type == f64 && other.type == f32) {
  570.         return Variable(boole, std::any_cast<double>(value) > std::any_cast<float>(other.value));
  571.     } else if (type == f64 && other.type == f64) {
  572.         return Variable(boole, std::any_cast<double>(value) > std::any_cast<double>(other.value));
  573.     }
  574.     return Variable(null);
  575. }
  576.  
  577. Variable Variable::less(const Variable& other) {
  578.     if (type == boole || type == str || type == null || other.type == boole || other.type == str || other.type == null) return Variable(null);
  579.  
  580.     if (type == chr && other.type == chr) {
  581.         return Variable(boole, std::any_cast<char>(value) < std::any_cast<char>(other.value));
  582.     } else if (type == chr && other.type == i32) {
  583.         return Variable(boole, std::any_cast<char>(value) < std::any_cast<int>(other.value));
  584.     } else if (type == chr && other.type == i64) {
  585.         return Variable(boole, std::any_cast<char>(value) < std::any_cast<long long>(other.value));
  586.     } else if (type == chr && other.type == f32) {
  587.         return Variable(boole, std::any_cast<char>(value) < std::any_cast<float>(other.value));
  588.     } else if (type == chr && other.type == f64) {
  589.         return Variable(boole, std::any_cast<char>(value) < std::any_cast<double>(other.value));
  590.     } else if (type == i32 && other.type == chr) {
  591.         return Variable(boole, std::any_cast<int>(value) < std::any_cast<char>(other.value));
  592.     } else if (type == i32 && other.type == i32) {
  593.         return Variable(boole, std::any_cast<int>(value) < std::any_cast<int>(other.value));
  594.     } else if (type == i32 && other.type == i64) {
  595.         return Variable(boole, std::any_cast<int>(value) < std::any_cast<long long>(other.value));
  596.     } else if (type == i32 && other.type == f32) {
  597.         return Variable(boole, std::any_cast<int>(value) < std::any_cast<float>(other.value));
  598.     } else if (type == i32 && other.type == f64) {
  599.         return Variable(boole, std::any_cast<int>(value) < std::any_cast<double>(other.value));
  600.     } else if (type == i64 && other.type == chr) {
  601.         return Variable(boole, std::any_cast<long long>(value) < std::any_cast<char>(other.value));
  602.     } else if (type == i64 && other.type == i32) {
  603.         return Variable(boole, std::any_cast<long long>(value) < std::any_cast<int>(other.value));
  604.     } else if (type == i64 && other.type == i64) {
  605.         return Variable(boole, std::any_cast<long long>(value) < std::any_cast<long long>(other.value));
  606.     } else if (type == i64 && other.type == f32) {
  607.         return Variable(boole, std::any_cast<long long>(value) < std::any_cast<float>(other.value));
  608.     } else if (type == i64 && other.type == f64) {
  609.         return Variable(boole, std::any_cast<long long>(value) < std::any_cast<double>(other.value));
  610.     } else if (type == f32 && other.type == chr) {
  611.         return Variable(boole, std::any_cast<float>(value) < std::any_cast<char>(other.value));
  612.     } else if (type == f32 && other.type == i32) {
  613.         return Variable(boole, std::any_cast<float>(value) < std::any_cast<int>(other.value));
  614.     } else if (type == f32 && other.type == i64) {
  615.         return Variable(boole, std::any_cast<float>(value) < std::any_cast<long long>(other.value));
  616.     } else if (type == f32 && other.type == f32) {
  617.         return Variable(boole, std::any_cast<float>(value) < std::any_cast<float>(other.value));
  618.     } else if (type == f32 && other.type == f64) {
  619.         return Variable(boole, std::any_cast<float>(value) < std::any_cast<double>(other.value));
  620.     } else if (type == f64 && other.type == chr) {
  621.         return Variable(boole, std::any_cast<double>(value) < std::any_cast<char>(other.value));
  622.     } else if (type == f64 && other.type == i32) {
  623.         return Variable(boole, std::any_cast<double>(value) < std::any_cast<int>(other.value));
  624.     } else if (type == f64 && other.type == i64) {
  625.         return Variable(boole, std::any_cast<double>(value) < std::any_cast<long long>(other.value));
  626.     } else if (type == f64 && other.type == f32) {
  627.         return Variable(boole, std::any_cast<double>(value) < std::any_cast<float>(other.value));
  628.     } else if (type == f64 && other.type == f64) {
  629.         return Variable(boole, std::any_cast<double>(value) < std::any_cast<double>(other.value));
  630.     }
  631.     return Variable(null);
  632. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement