Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
BasicMathExpressionEvaluator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Internationalization/FastDecimalFormat.h"
7#include "Misc/ExpressionParserTypes.h"
8#include "Misc/Optional.h"
9#include "Templates/ValueOrError.h"
10
11struct FDecimalNumberFormattingRules;
12
13#define DEFINE_EXPRESSION_OPERATOR_NODE(EXPORTAPI, TYPE, ...) namespace
14 ExpressionParser {
15 struct EXPORTAPI TYPE { static const TCHAR* const Moniker; }; \
16}DEFINE_EXPRESSION_NODE_TYPE
17 (ExpressionParser::TYPE, __VA_ARGS__)
18
19/** Define some expression types for basic arithmetic */
20DEFINE_EXPRESSION_OPERATOR_NODE(, FSubExpressionStart, 0xCC40A083, 0xADBF46E2, 0xA93D12BB, 0x525D7417)
21DEFINE_EXPRESSION_OPERATOR_NODE(, FSubExpressionEnd, 0x125E4C67, 0x96EB48C4, 0x8894E09C, 0xB3CD56BF)
22
23DEFINE_EXPRESSION_OPERATOR_NODE(, FPlus, 0x6F88756B, 0xF9234263, 0x9B13614F, 0x2706074B)
24DEFINE_EXPRESSION_OPERATOR_NODE(, FPlusEquals, 0x05A878C9, 0x0E6C44A4, 0x9A73920D, 0x3175AB48)
25DEFINE_EXPRESSION_OPERATOR_NODE(, FMinus, 0xE6240779, 0xEE2849CF, 0x95A0E648, 0x22D58713)
26DEFINE_EXPRESSION_OPERATOR_NODE(, FMinusEquals, 0x8D1E08E3, 0x5F534245, 0xA987AD7E, 0xDB78A4B7)
27DEFINE_EXPRESSION_OPERATOR_NODE(, FStar, 0xF287B3BF, 0x35DF4141, 0xA8B4F57B, 0x7E06DF47)
28DEFINE_EXPRESSION_OPERATOR_NODE(, FStarEquals, 0xBA359BB0, 0xCEB54682, 0x9160EB4F, 0xD1687C7F)
29DEFINE_EXPRESSION_OPERATOR_NODE(, FForwardSlash, 0xF99670F8, 0x74794256, 0xBB0CAE6D, 0xC67CD5B6)
30DEFINE_EXPRESSION_OPERATOR_NODE(, FForwardSlashEquals, 0x4AFE0CF8, 0xF9054360, 0xBE5DCE80, 0xDC2E22F6)
31DEFINE_EXPRESSION_OPERATOR_NODE(, FPercent, 0x936E4434, 0x0A014F2D, 0xBEEC90D3, 0x4D3ECEA2)
32DEFINE_EXPRESSION_OPERATOR_NODE(, FSquareRoot, 0xE7C03E11, 0x9DE84B4B, 0xBA4C2B76, 0x69BF028E)
33DEFINE_EXPRESSION_OPERATOR_NODE(, FPower, 0x93388F8D, 0x1D9B4DFE, 0xBD4D6CC4, 0x12D1DE99)
34
36{
37 /** Get the default set number formatting rules based on the current locale and user settings */
38 const FDecimalNumberFormattingRules& GetLocalizedNumberFormattingRules();
39
40 /** Parse a number formatted using the given rules from the given stream, optionally from a specific read position */
41 TOptional<FStringToken> ParseNumberWithFallback(const FTokenStream& InStream, const FDecimalNumberFormattingRules& InPrimaryFormattingRules, const FDecimalNumberFormattingRules& InFallbackFormattingRules, FStringToken* Accumulate = nullptr, double* OutValue = nullptr);
42
43 /** Parse a number formatted using the given rules from the given stream, optionally from a specific read position */
44 TOptional<FStringToken> ParseNumberWithRules(const FTokenStream& InStream, const FDecimalNumberFormattingRules& InFormattingRules, FStringToken* Accumulate = nullptr, double* OutValue = nullptr);
45
46 /** Parse a localized number from the given stream, optionally from a specific read position */
47 TOptional<FStringToken> ParseLocalizedNumberWithAgnosticFallback(const FTokenStream& InStream, FStringToken* Accumulate = nullptr, double* OutValue = nullptr);
48
49 /** Parse a localized number from the given stream, optionally from a specific read position */
50 TOptional<FStringToken> ParseLocalizedNumber(const FTokenStream& InStream, FStringToken* Accumulate = nullptr, double* OutValue = nullptr);
51
52 /** Parse a number from the given stream, optionally from a specific read position */
53 TOptional<FStringToken> ParseNumber(const FTokenStream& InStream, FStringToken* Accumulate = nullptr, double* OutValue = nullptr);
54
55 /** Consume a number formatted using the given rules from the specified consumer's stream, if one exists at the current read position */
56 TOptional<FExpressionError> ConsumeNumberWithRules(FExpressionTokenConsumer& Consumer, const FDecimalNumberFormattingRules& InFormattingRules);
57
58 /** Consume a localized number from the specified consumer's stream, if one exists at the current read position */
60
61 /** Consume a localized number from the specified consumer's stream, if one exists at the current read position */
63
64 /** Consume a number from the specified consumer's stream, if one exists at the current read position */
66
67 /** Consume a symbol from the specified consumer's stream, if one exists at the current read position */
68 template<typename TSymbol>
70 {
72 if (Token.IsSet())
73 {
75 }
76
78 }
79}
80
81/** A basic math expression evaluator */
83{
84public:
85 /** Constructor that sets up the parser's lexer and compiler */
87
88 /** Evaluate the given expression, resulting in either a double value, or an error */
89 TValueOrError<double, FExpressionError> Evaluate(const TCHAR* InExpression, double InExistingValue = 0) const;
90
91private:
95};
#define DEFINE_EXPRESSION_OPERATOR_NODE(EXPORTAPI, TYPE,...)
TOperatorJumpTable FOperatorJumpTable
TValueOrError< double, FExpressionError > Evaluate(const TCHAR *InExpression, double InExistingValue=0) const
TOptional< FExpressionError > ConsumeLocalizedNumber(FExpressionTokenConsumer &Consumer)
TOptional< FExpressionError > ConsumeLocalizedNumberWithAgnosticFallback(FExpressionTokenConsumer &Consumer)
const FDecimalNumberFormattingRules & GetLocalizedNumberFormattingRules()
TOptional< FExpressionError > ConsumeSymbol(FExpressionTokenConsumer &Consumer)
TOptional< FExpressionError > ConsumeNumberWithRules(FExpressionTokenConsumer &Consumer, const FDecimalNumberFormattingRules &InFormattingRules)
TOptional< FStringToken > ParseNumberWithRules(const FTokenStream &InStream, const FDecimalNumberFormattingRules &InFormattingRules, FStringToken *Accumulate=nullptr, double *OutValue=nullptr)
TOptional< FStringToken > ParseLocalizedNumber(const FTokenStream &InStream, FStringToken *Accumulate=nullptr, double *OutValue=nullptr)
TOptional< FStringToken > ParseNumber(const FTokenStream &InStream, FStringToken *Accumulate=nullptr, double *OutValue=nullptr)
TOptional< FStringToken > ParseLocalizedNumberWithAgnosticFallback(const FTokenStream &InStream, FStringToken *Accumulate=nullptr, double *OutValue=nullptr)
TOptional< FStringToken > ParseNumberWithFallback(const FTokenStream &InStream, const FDecimalNumberFormattingRules &InPrimaryFormattingRules, const FDecimalNumberFormattingRules &InFallbackFormattingRules, FStringToken *Accumulate=nullptr, double *OutValue=nullptr)
TOptional< FExpressionError > ConsumeNumber(FExpressionTokenConsumer &Consumer)
FGuid(uint32 InA, uint32 InB, uint32 InC, uint32 InD)
Definition Guid.h:127