+ * Quickly calculate the sum of all values in an isochromatic interval. The formula in this calculation component consists of two components, such as "a+b, a+b+10". The result of a+b+1+a+b+2+a+b+3+...+a+b+10 will be calculated.
+ *
+ * @author zhao
+ */
+ class FastSumOfIntervalsBrackets : public NumberCalculation, public SharedCalculation {
+
+ private:
+ bool StartSharedPool = true;
+ string CurrentOwner;
+ string left;
+ string right;
+ CalculationNumberResults shareNumberCalculation = CalculationNumberResults(
+ -1, -1, "null"
+ );
+
+ public:
+
+ int step = 1;
+
+ string formatStr(std::string string) override;
+
+ void check(std::string string) override;
+
+ ME::CalculationNumberResults operator>>(std::string &format);
+
+ ME::CalculationNumberResults operator<<(std::string &format);
+
+ string getName() override;
+
+ /**
+ * 将两个结果对象,作为需要求和区间的起始与终止数值,以此进行区间的求和,不进行公式的计算
+ *
+ * Take the two result objects as the starting and ending values of the interval to be summed, so as to sum the interval, without calculating the formula
+ *
+ * @param start 起始点结果数值
+ * @param end 终止点结果数值
+ * @return 区间求和的结果对象
+ *
+ * The two formulas are used as the starting point and planting point of the summation interval, so as to sum the interval without making relevant judgments on the shared pool
+ *
+ * @param f1 起始点计算公式
+ * @param f2 终止点计算公式
+ * @return 区间求和的结果对象
+ *
+ * Result object of interval summation
+ */
+ CalculationNumberResults calculation(string f1, string f2);
+
+ CalculationNumberResults calculation(std::string Formula, bool formatRequired) override;
+
+ bool isStartSharedPool() override;
+
+ void setStartSharedPool(bool startSharedPool) override;
+
+ private:
+ CalculationNumberResults calculation(std::string Formula) override;
+ };
+
+} // ME
+
+#endif //MATHEMATICAL_EXPRESSION_CPP_FASTSUMOFINTERVALSBRACKETS_H
diff --git a/include/FunctionFormulaCalculationTwo.h b/include/FunctionFormulaCalculationTwo.h
new file mode 100644
index 0000000..4e7e420
--- /dev/null
+++ b/include/FunctionFormulaCalculationTwo.h
@@ -0,0 +1,31 @@
+//
+// Created by zhao on 2023/6/22.
+//
+
+#ifndef MATHEMATICAL_EXPRESSION_CPP_FUNCTIONFORMULACALCULATIONTWO_H
+#define MATHEMATICAL_EXPRESSION_CPP_FUNCTIONFORMULACALCULATIONTWO_H
+
+#include "FunctionFormulaCalculation.h"
+
+namespace ME {
+
+ class FunctionFormulaCalculationTwo : public FunctionFormulaCalculation {
+ public:
+ string formatStr(std::string string) override;
+
+ void check(std::string string) override;
+
+ CalculationNumberResults operator>>(std::string &format);
+
+ CalculationNumberResults operator<<(std::string &format);
+
+ string getName() override;
+
+ CalculationNumberResults calculation(std::string Formula, bool formatRequired) override;
+
+ CalculationNumberResults calculation(std::string Formula) override;
+ };
+
+}
+
+#endif //MATHEMATICAL_EXPRESSION_CPP_FUNCTIONFORMULACALCULATIONTWO_H
diff --git a/include/FunctionManager.h b/include/FunctionManager.h
index c58ba0f..91e531b 100644
--- a/include/FunctionManager.h
+++ b/include/FunctionManager.h
@@ -5,6 +5,7 @@
#ifndef MATHEMATICAL_EXPRESSION_CPP_FUNCTIONMANAGER_H
#define MATHEMATICAL_EXPRESSION_CPP_FUNCTIONMANAGER_H
+#include "MEStack.h"
namespace ME {
@@ -38,9 +39,27 @@ namespace ME {
* @param check 注册函数的时候是否要进行函数名称冲突的检查,这是一个默认为true的值,如果为 true 代表检查函数名称是否冲突。
*
* When registering a function, do you want to check for function name conflicts? This is a default value of true. If true, it means checking for function name conflicts.
+ * @deprecated("此函数不应继续调用,请调用 append(const std::string &name, const std::function)> &func, bool check = true); 相当于是函数的形参变为了 ME::MEStack")
*/
static void append(const std::string &name, const std::function &func, bool check = true);
+ /**
+ * 将一个函数添加添加到函数存储池中,相当于是进行的函数注册操作。
+ *
+ * Adding a function to the function storage pool is equivalent to registering a function.
+ * @param name 需要被注册函数的名称。
+ *
+ * The name of the function that needs to be registered.
+ * @param func 需要被注册的函数的实现。
+ *
+ * The implementation of the function that needs to be registered.
+ * @param check 注册函数的时候是否要进行函数名称冲突的检查,这是一个默认为true的值,如果为 true 代表检查函数名称是否冲突。
+ *
+ * When registering a function, do you want to check for function name conflicts? This is a default value of true. If true, it means checking for function name conflicts.
+ */
+ static void
+ append(const std::string &name, const std::function)> &func, bool check = true);
+
/**
* 从函数管理者中获取到指定名称的函数对象。
*
@@ -52,7 +71,7 @@ namespace ME {
*
* Specifies the Function object corresponding to the function name.
*/
- static std::function getFunction(const std::string &name);
+ static std::function)> getFunction(const std::string &name);
};
}
diff --git a/include/MEStack.h b/include/MEStack.h
index 358b5ae..f696374 100644
--- a/include/MEStack.h
+++ b/include/MEStack.h
@@ -30,7 +30,12 @@ namespace ME {
std::ostream &operator<<(std::ostream &out, const MEStack &meStack);
public:
- T get(int index);
+ /**
+ * 将栈中指定索引处的元素获取到,同时不影响栈中所有的元素
+ * @param index 需要获取的元素的位置
+ * @return 元素的具体数值
+ */
+ T get(int index) const;
/**
* 将栈中的栈顶元素直接取出,此操作将会删除栈顶元素,并将栈顶元素获取到。
@@ -40,7 +45,7 @@ namespace ME {
};
template
- T MEStack::get(int index) {
+ T MEStack::get(int index) const {
return this->c[index];
}
diff --git a/include/SharedCalculation.h b/include/SharedCalculation.h
new file mode 100644
index 0000000..d0c370a
--- /dev/null
+++ b/include/SharedCalculation.h
@@ -0,0 +1,37 @@
+//
+// Created by Liming on 2023/6/27.
+//
+
+#ifndef MATHEMATICAL_EXPRESSION_CPP_SHAREDCALCULATION_H
+#define MATHEMATICAL_EXPRESSION_CPP_SHAREDCALCULATION_H
+
+namespace ME {
+
+ /**
+ * 共享池计算组件,带有共享池的计算组件需要继承该抽象类
+ *
+ * A shared pool computing component. A computing component with a shared pool needs to inherit this abstract class
+ *
+ * @author zhao
+ */
+ class SharedCalculation {
+ virtual /**
+ * @return 该组件是否有启动共享池,一个布尔值,如果返回true代表共享池已经启动.
+ *
+ * Does this component have a startup shared pool? A Boolean value, if it returns true, it indicates that the shared pool has already been started.
+ */
+ bool isStartSharedPool() = 0;
+
+ virtual /**
+ * 设置共享池开关,共享池是在JavaApi中,1.1版本衍生出来的一种新特性,由于计算量的需求,引入该功能
+ *
+ * Set the shared pool switch. The shared pool is a new feature derived from version 1.1 in JavaApi. Due to the requirement of computing load, this function is introduced
+ *
+ * @param startSharedPool 共享池如果设置为true,代表被打开,将会共享检查与
+ */
+ void setStartSharedPool(bool startSharedPool) = 0;
+ };
+
+} // ME
+
+#endif //MATHEMATICAL_EXPRESSION_CPP_SHAREDCALCULATION_H
diff --git a/include/Utils.h b/include/Utils.h
index 34b89a2..765ed50 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -60,6 +60,21 @@ namespace StrUtils {
*/
std::string
replace(const std::string &old_string, const std::string &replace_string, const std::string &new_string);
+
+ /**
+ * 使用起始与终止的指针进行拷贝字符串
+ * @param start 起始的字符串指针
+ * @param end 终止的字符串指针
+ * @return 拷贝成功的字符串数据
+ */
+ std::string copy_str(std::string::const_iterator start, std::string::const_iterator end);
+
+ /**
+ * 去除字符串前后空字符串的函数
+ * @param data 需要被去除空值的字符串
+ * @return 去除成功后返回的新字符串
+ */
+ std::string trim(const std::string &data);
}
namespace NumberUtils {
@@ -117,6 +132,26 @@ namespace NumberUtils {
* Whether the left value and right value conform to the comparison operator
*/
bool ComparisonOperation(const std::string &ComparisonOperator, double left, double right);
+
+ /**
+ * 将区间内的所有数值进行累加
+ *
+ * @param start 区间起始数值
+ * @param end 区间终止数值
+ * @return 区间内所有数值的累加结果
+ */
+ static double sumOfRange(double start, double end);
+
+ /**
+ * 带有步长的方式计算一个区间内所有数值的累加
+ *
+ * @param start 区间起始数值
+ * @param end 区间终止数值
+ * @param step 区间内每一个元素之间的步长
+ * @return 区间内元素之和
+ */
+ double sumOfRange(double start, double end, double step);
+
}
#endif //MATHEMATICAL_EXPRESSION_CPP_UTILS_H
diff --git a/include/mathematical_expression.h b/include/mathematical_expression.h
index 49e1cd3..7baa756 100644
--- a/include/mathematical_expression.h
+++ b/include/mathematical_expression.h
@@ -10,8 +10,9 @@
#include "BooleanCalculationTwo.h"
#include "CumulativeCalculation.h"
#include "FunctionFormulaCalculation.h"
+#include "FunctionFormulaCalculationTwo.h"
-#define VERSION "1.0.1.1-mathematical_expression-C++";
+#define VERSION "1.0.2.1-mathematical_expression-C++";
/**
* 数学表达式解析计算库中的门户类,由该类获取到数学表达式计算库中的相关数据对象。
@@ -25,6 +26,7 @@ class mathematical_expression {
ME::BooleanCalculationTwo booleanCalculation2;
ME::CumulativeCalculation cumulativeCalculation;
ME::FunctionFormulaCalculation functionFormulaCalculation;
+ ME::FunctionFormulaCalculationTwo functionFormulaCalculation2;
public:
/**
@@ -77,7 +79,29 @@ class mathematical_expression {
*/
ME::FunctionFormulaCalculation getFunctionFormulaCalculation();
+ /**
+ *
+ * @return 函数数学表达式计算组件,该组件能够解析一个引用了函数的表达式,能够有效的实现自定义计算函数的效果。
+ 其支持多参函数
+ *
+ *Function
+ mathematical expression
+ calculation component, which
+ can parse
+ an expression
+ that references
+ a function
+ and
+ effectively achieve
+ the effect
+ of custom
+ calculation functions
+ .
+ */
+
+ ME::FunctionFormulaCalculationTwo getFunctionFormulaCalculation2();
};
+ostream &operator<<(ostream &out, mathematical_expression mathematicalExpression);
#endif //MATHEMATICAL_EXPRESSION_CPP_MATHEMATICAL_EXPRESSION_H
diff --git a/src/core/calculation/FastSumOfIntervalsBrackets.cpp b/src/core/calculation/FastSumOfIntervalsBrackets.cpp
new file mode 100644
index 0000000..cb67f5a
--- /dev/null
+++ b/src/core/calculation/FastSumOfIntervalsBrackets.cpp
@@ -0,0 +1,127 @@
+//
+// Created by Liming on 2023/6/27.
+//
+
+#include "FastSumOfIntervalsBrackets.h"
+#include "Utils.h"
+#include "CalculationConstant.h"
+
+static ME::BracketsCalculationTwo BRACKETS_CALCULATION_2 = ME::CalculationConstant::getBracketsCalculationTwo();
+
+namespace ME {
+
+ bool FastSumOfIntervalsBrackets::isStartSharedPool() {
+ return this->StartSharedPool;
+ }
+
+ void FastSumOfIntervalsBrackets::setStartSharedPool(bool startSharedPool) {
+ this->StartSharedPool = startSharedPool;
+ }
+
+ string FastSumOfIntervalsBrackets::formatStr(std::string string) {
+ return StrUtils::trim(string);
+ }
+
+ void FastSumOfIntervalsBrackets::check(std::string string) {
+ if (this->StartSharedPool && std::equal(this->CurrentOwner.begin(), this->CurrentOwner.end(), string.begin())) {
+ // 如果共享池开启,同时共享池中的数据所属身份属于当前公式,并且有计算结果,就直接停止检查,因为这个公式之前检查过
+ return;
+ }
+ // 在这里获取到前后两个公式
+ vector arrayList = StrUtils::splitByChar(string, COMMA);
+ unsigned int size = arrayList.size();
+ if (size == 2) {
+ std::string l = arrayList[0];
+ std::string r = arrayList[1];
+ BRACKETS_CALCULATION_2.check(l);
+ if (!std::equal(l.begin(), l.end(), r.begin())) {
+ BRACKETS_CALCULATION_2.check(r);
+ }
+ if (this->StartSharedPool) {
+ // 如果检查无误,就将检查之后的结果存储到共享池
+ this->left = l;
+ this->right = r;
+ this->CurrentOwner = string;
+ }
+ } else {
+ std::string data = "区间求和表达式解析错误,在该组件中的表达式,需要两个以逗号分割的表达式组成累加区间中的两个边界值。\n";
+ data.append("Error parsing the interval summation expression. The expression in this component needs two expressions separated by commas to form two boundary values in the cumulative interval.")
+ .append("Number of expressions you provide => ");
+ throw WrongFormat(data.append(to_string(size)));
+ }
+ }
+
+ string FastSumOfIntervalsBrackets::getName() {
+ return "FastSumOfIntervalsBrackets";
+ }
+
+ /**
+ * 将两个结果对象,作为需要求和区间的起始与终止数值,以此进行区间的求和,不进行公式的计算
+ *
+ * Take the two result objects as the starting and ending values of the interval to be summed, so as to sum the interval, without calculating the formula
+ *
+ * @param start 起始点结果数值
+ * @param end 终止点结果数值
+ * @return 区间求和的结果对象
+ *