merged AI doc, some new pages

This commit is contained in:
2026-03-12 14:46:57 +03:00
parent 07ae277f9e
commit ed13838237
206 changed files with 14088 additions and 5152 deletions
+83 -25
View File
@@ -1,9 +1,16 @@
/*! \file pievaluator.h
* \ingroup Math
* \~\brief
* \~english Mathematic expressions calculator
* \~russian Вычислитель математических выражений
*/
//! \~\file pievaluator.h
//! \~\ingroup Math
//! \~\brief
//! \~english Mathematical expression evaluator
//! \~russian Вычислитель математических выражений
//! \~\details
//! \~english
//! Declares evaluator types, expression storage, and the evaluator that
//! prepares an expression once and then reuses compiled instructions.
//! \~russian
//! Объявляет типы вычислителя, контейнер выражения и вычислитель,
//! который один раз подготавливает выражение и затем повторно использует
//! скомпилированные инструкции.
/*
PIP - Platform Independent Primitives
Evaluator designed for stream calculations
@@ -40,6 +47,7 @@ enum eType {
etVariable,
etFunction
};
enum Operation {
oNone,
oAdd,
@@ -58,6 +66,7 @@ enum Operation {
oOr,
oFunction
};
enum BaseFunctions {
bfUnknown,
bfSin,
@@ -112,66 +121,84 @@ struct PIP_EXPORT Instruction {
function = -1;
operation = oNone;
}
Instruction(Operation oper, PIVector<short> opers, short out_ind, short func = -1) {
operation = oper;
operators = opers;
out = out_ind;
function = func;
}
Operation operation;
short out;
short function;
PIVector<short> operators;
};
struct PIP_EXPORT Element {
Element() {
num = 0;
var_num = -1;
type = etNumber;
}
Element(eType new_type, short new_num, short new_var_num = -1) { set(new_type, new_num, new_var_num); }
void set(eType new_type, short new_num, short new_var_num = -1) {
type = new_type;
num = new_num;
var_num = new_var_num;
}
eType type;
short num;
short var_num;
};
struct PIP_EXPORT Function {
Function() {
arguments = 0;
type = bfUnknown;
handler = nullptr;
}
Function(const PIString & name, short args, BaseFunctions ftype) {
identifier = name;
arguments = args;
type = ftype;
handler = nullptr;
}
Function(const PIString & name, short args, FuncHanlder h) {
identifier = name;
arguments = args;
type = bfCustom;
handler = h;
}
PIString identifier;
BaseFunctions type;
FuncHanlder handler;
short arguments;
};
struct PIP_EXPORT Variable {
Variable() { value = 0.; }
Variable(const PIString & var_name, complexd val) {
name = var_name;
value = val;
}
PIString name;
complexd value;
};
} // namespace PIEvaluatorTypes
/*
≠ :
≥ }
@@ -179,7 +206,6 @@ struct PIP_EXPORT Variable {
⋀ &
|
*/
class PIP_EXPORT PIEvaluatorContent {
friend class PIEvaluator;
BINARY_STREAM_FRIEND(PIEvaluatorContent);
@@ -209,7 +235,6 @@ public:
bool setVariableName(const PIString & var_name, const PIString & new_name) { return setVariableName(findVariable(var_name), new_name); }
void clearCustomVariables();
PIEvaluatorTypes::BaseFunctions getBaseFunction(const PIString & name);
void dump();
private:
@@ -219,64 +244,97 @@ private:
};
//! \~\ingroup Math
//! \~\brief
//! \~english Expression evaluator with reusable compiled instructions.
//! \~russian Вычислитель выражений с повторно используемыми скомпилированными инструкциями.
//!
//! \~\details
//! \~english
//! The evaluator prepares an expression with \a check(), keeps the processed
//! form and instruction list, and then reevaluates it after variable updates.
//! Built-in constants include \c i, \c pi, and \c e.
//! \~russian
//! Вычислитель подготавливает выражение через \a check(), сохраняет
//! обработанную форму и список инструкций, а затем повторно вычисляет его
//! после обновления переменных. Встроенные константы: \c i, \c pi и \c e.
class PIP_EXPORT PIEvaluator {
public:
//! Constructs an empty evaluator
//! \~english Constructs an empty evaluator.
//! \~russian Создает пустой вычислитель.
PIEvaluator() {
correct = false;
data_ = 0;
}
//! \~english Destroys the evaluator.
//! \~russian Уничтожает вычислитель.
~PIEvaluator() { ; }
//! Returns custom data
//! \~english Returns custom user data passed to callback functions.
//! \~russian Возвращает пользовательские данные, передаваемые в callback-функции.
void * data() { return data_; }
//! Set custom data to "_data"
//! \~english Sets custom user data for callback functions.
//! \~russian Устанавливает пользовательские данные для callback-функций.
void setData(void * _data) { data_ = _data; }
//! Check mathematical expression and parse it to list of instructions
//! \~english Checks and compiles an expression.
//! \~russian Проверяет и компилирует выражение.
bool check(const PIString & string);
//! Returns true if expression was checked succesfully
//! \~english Returns true if the last \a check() succeeded.
//! \~russian Возвращает true, если последний вызов \a check() завершился успешно.
bool isCorrect() const { return correct; }
//! Set variable value with name "name" to value "value". Add variable if it doesn`t exists
//! \~english Sets a named variable and creates it if needed.
//! \~russian Устанавливает именованную переменную и создает ее при необходимости.
int setVariable(const PIString & name, complexd value = complexd(0.));
//! Set variable value with index "index" to value "value". Don`t add variable if it doesn`t exists
//! \~english Sets a variable by index.
//! \~russian Устанавливает переменную по индексу.
void setVariable(int index, complexd value = 0.);
//! Evaluate last successfully checked with function \a check() expression and returns result
//! \~english Evaluates the last successfully compiled expression.
//! \~russian Вычисляет последнее успешно скомпилированное выражение.
complexd evaluate();
//! Remove all manually added variables
//! \~english Removes user-added variables and keeps built-in constants.
//! \~russian Удаляет добавленные пользователем переменные и сохраняет встроенные константы.
void clearCustomVariables() { content.clearCustomVariables(); }
//! Returns index of variable with name "name"
//! \~english Returns variable index by name, or -1.
//! \~russian Возвращает индекс переменной по имени или -1.
int variableIndex(const PIString & name) const { return content.findVariable(name); }
//! Returns all unknown variables founded in last expression passed to \a check() function
//! \~english Returns unknown variables found during the last \a check().
//! \~russian Возвращает неизвестные переменные, найденные при последнем \a check().
const PIStringList & unknownVariables() const { return unknownVars; }
//! Returns all used variables founded in last expression passed to \a check() function
//! \~english Returns variables used in the last checked expression.
//! \~russian Возвращает переменные, использованные в последнем проверенном выражении.
const PIStringList & usedVariables() const { return usedVars; }
//! Returns processed last expression passed to \a check() function
//! \~english Returns the normalized form of the last checked expression.
//! \~russian Возвращает нормализованную форму последнего проверенного выражения.
const PIString & expression() const { return currentString; }
//! Returns last error description occured in \a check() function
//! \~english Returns the last status or error text from \a check().
//! \~russian Возвращает последний статус или текст ошибки из \a check().
const PIString & error() const { return lastError; }
//! Returns last result of \a evaluate()
//! \~english Returns the last evaluation result.
//! \~russian Возвращает последний результат вычисления.
const complexd & lastResult() const { return out; }
//! Save to %PIByteArray evaluator state (expression, variables, errors, compiled instructions)
//! \~english Serializes evaluator state.
//! \~russian Сериализует состояние вычислителя.
PIByteArray save() const;
//! Restore from %PIByteArray evaluator state (expression, variables, errors, compiled instructions)
//! \~english Restores evaluator state from serialized data.
//! \~russian Восстанавливает состояние вычислителя из сериализованных данных.
void load(PIByteArray ba);
private: