JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
FunctionWrapper.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 20/08/18.
3 //
4 #ifndef __CLION_IDE__ // Prevent IDE lag from expanding all macros
5 #ifndef JODA_FUNCTIONWRAPPER_H
6 #define JODA_FUNCTIONWRAPPER_H
7 #include <tao/pegtl.hpp>
8 
10 
11 template <typename Rule>
12 struct functionAction : tao::pegtl::nothing<Rule> {};
13 
14 /*
15  * FCLASS: Classname of Function IValueProvider
16  * FSTRUCT: (Unique) Name of kexword-struct
17  * FKEXWORD: (Unique) Keyword name in querylanguage
18  */
19 #define REGISTER_FUNCTION(FCLASS, FSTRUCT, FKEYWORD) \
20  struct FSTRUCT : TAOCPP_PEGTL_KEYWORD(FKEYWORD) { \
21  static std::string toString() { return FKEYWORD; } \
22  }; \
23  template <> \
24  struct functionAction<FSTRUCT> { \
25  static void apply0(functionState &state) { \
26  state.factory = &FCLASS::_FACTORY; \
27  } \
28  };
29 } // namespace joda::queryparsing::grammar
30 
52 #include "states/States.h"
53 
55 REGISTER_FUNCTION(query::ArraySizeProvider, func_kw_arrSize, "SIZE")
56 REGISTER_FUNCTION(query::FileNameProvider, func_kw_FILE, "FILENAME")
57 REGISTER_FUNCTION(query::FilePosProvider<true>, func_kw_FILEPOSSTART,
58  "FILEPOSSTART")
59 REGISTER_FUNCTION(query::FilePosProvider<false>, func_kw_FILEPOSEND,
60  "FILEPOSEND")
61 REGISTER_FUNCTION(query::IDProvider, func_kw_ID, "ID")
62 REGISTER_FUNCTION(query::INListProvider, func_kw_IN, "IN")
63 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Array>, func_kw_isArray,
64  "ISARRAY")
65 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Object>, func_kw_isObject,
66  "ISOBJECT")
67 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Number>, func_kw_isNumber,
68  "ISNUMBER")
69 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Bool>, func_kw_isBool,
70  "ISBOOL")
71 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_String>, func_kw_isString,
72  "ISSTRING")
73 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Null>, func_kw_isNull,
74  "ISNULL")
75 REGISTER_FUNCTION(query::IsXBoolProvider<query::IV_Any>, func_kw_exists,
76  "EXISTS")
77 REGISTER_FUNCTION(query::ListAttributesProvider, func_kw_LISTATTRIBUTES,
78  "LISTATTRIBUTES")
79 REGISTER_FUNCTION(query::RegexExtractProvider, func_kw_REGEX_EXTRACT,
80  "REGEX_EXTRACT")
81 REGISTER_FUNCTION(query::RegexProvider, func_kw_REGEX, "REGEX")
82 REGISTER_FUNCTION(query::RegexReplaceProvider, func_kw_REGEX_REPLACE,
83  "REGEX_REPLACE")
84 REGISTER_FUNCTION(query::SCONTAINSProvider, func_kw_sContains, "SCONTAINS")
85 REGISTER_FUNCTION(query::STARTSWITHProvider, func_kw_STARTSWITH, "STARTSWITH")
86 REGISTER_FUNCTION(query::SeqNumberProvider, func_kw_SEQNUM, "SEQNUM")
87 REGISTER_FUNCTION(query::TypeProvider, func_kw_TYPE, "TYPE")
88 REGISTER_FUNCTION(query::SumProvider, func_kw_SUMFUNK, "SUM")
89 REGISTER_FUNCTION(query::SubtractProvider, func_kw_SUBFUNK, "SUB")
90 REGISTER_FUNCTION(query::ProductProvider, func_kw_PRODFUNK, "PROD")
91 REGISTER_FUNCTION(query::DivProvider, func_kw_DIVFUNK, "DIV")
92 REGISTER_FUNCTION(query::ModuloProvider, func_kw_MODFUNK, "MOD")
93 REGISTER_FUNCTION(query::PowerProvider, func_kw_POWFUNK, "POW")
94 REGISTER_FUNCTION(query::Atan2Provider, func_kw_ATAN2FUNK, "ATAN2")
95 REGISTER_FUNCTION(query::AbsProvider, func_kw_ABSFUNK, "ABS")
96 REGISTER_FUNCTION(query::RoundProvider, func_kw_ROUNDFUNK, "ROUND")
97 REGISTER_FUNCTION(query::SqrtProvider, func_kw_SQRTFUNK, "SQRT")
98 REGISTER_FUNCTION(query::CeilProvider, func_kw_CEILFUNK, "CEIL")
99 REGISTER_FUNCTION(query::FloorProvider, func_kw_FLOORFUNK, "FLOOR")
100 REGISTER_FUNCTION(query::DegreesProvider, func_kw_DEGREESFUNK, "DEGREES")
101 REGISTER_FUNCTION(query::RadiansProvider, func_kw_RADIANSFUNK, "RADIANS")
102 REGISTER_FUNCTION(query::AcosProvider, func_kw_ACOSFUNK, "ACOS")
103 REGISTER_FUNCTION(query::AsinProvider, func_kw_ASINFUNK, "ASIN")
104 REGISTER_FUNCTION(query::AtanProvider, func_kw_ATANFUNK, "ATAN")
105 REGISTER_FUNCTION(query::CosProvider, func_kw_COSFUNK, "COS")
106 REGISTER_FUNCTION(query::SinProvider, func_kw_SINFUNK, "SIN")
107 REGISTER_FUNCTION(query::TanProvider, func_kw_TANFUNK, "TAN")
108 REGISTER_FUNCTION(query::TruncProvider, func_kw_TRUNCFUNK, "TRUNC")
109 REGISTER_FUNCTION(query::LenProvider, func_kw_LENFUNK, "LEN")
110 REGISTER_FUNCTION(query::ConcatProvider, func_kw_CONCATFUNK, "CONCAT")
111 REGISTER_FUNCTION(query::FINDSTRProvider, func_kw_FINDSTRFUNK, "FINDSTR")
112 REGISTER_FUNCTION(query::SubStringProvider, func_kw_SUBSTRFUNK, "SUBSTR")
113 REGISTER_FUNCTION(query::UpperProvider, func_kw_UPPERFUNK, "UPPER")
114 REGISTER_FUNCTION(query::LowerProvider, func_kw_LOWERFUNK, "LOWER")
115 REGISTER_FUNCTION(query::LtrimProvider, func_kw_LTRIMFUNK, "LTRIM")
116 REGISTER_FUNCTION(query::RtrimProvider, func_kw_RTRIMFUNK, "RTRIM")
117 REGISTER_FUNCTION(query::PiProvider, func_kw_PIFUNK, "PI")
118 REGISTER_FUNCTION(query::MemberCountProvider, func_kw_MEMCOUNTFUNK, "MEMCOUNT")
119 REGISTER_FUNCTION(query::HashProvider, func_kw_HASHFUNK, "HASH")
120 REGISTER_FUNCTION(query::NowProvider, func_kw_NOWFUNK, "NOW")
121 REGISTER_FUNCTION(query::IntCastProvider, func_kw_INTFUNK, "INT")
122 REGISTER_FUNCTION(query::FloatCastProvider, func_kw_FLOATFUNK, "FLOAT")
123 REGISTER_FUNCTION(query::StringCastProvider, func_kw_STRINGFUNK, "STRING")
124 
125 template <typename... Rules>
126 struct stringableSOR : tao::pegtl::sor<Rules...> {
127  template <typename First, typename... Rest>
128  static constexpr auto toString() {
129  return First::toString() + " " + stringableSOR<Rest...>::toString();
130  }
131 
132  static constexpr auto toString() { return toString<Rules...>(); }
133 };
134 
135 template <>
136 struct stringableSOR<> {
137  static constexpr auto toString() { return ""; }
138 };
139 
141  : stringableSOR<
142  func_kw_exists, func_kw_isArray, func_kw_isObject, func_kw_isNumber,
143  func_kw_isBool, func_kw_isString, func_kw_isNull, func_kw_IN,
144  func_kw_sContains, func_kw_STARTSWITH, func_kw_arrSize, func_kw_ID,
145  func_kw_FILE, func_kw_FILEPOSSTART, func_kw_FILEPOSEND,
146  func_kw_SEQNUM, func_kw_LISTATTRIBUTES, func_kw_TYPE, func_kw_REGEX,
147  func_kw_REGEX_EXTRACT, func_kw_REGEX_REPLACE, func_kw_SUMFUNK,
148  func_kw_SUBFUNK, func_kw_PRODFUNK, func_kw_MODFUNK, func_kw_POWFUNK,
149  func_kw_ATAN2FUNK, // func_kw_ATAN2FUNK has to be before
150  // func_kw_ATANFUNK
151  func_kw_ABSFUNK, func_kw_ROUNDFUNK, func_kw_SQRTFUNK,
152  func_kw_CEILFUNK, func_kw_FLOORFUNK, func_kw_DEGREESFUNK,
153  func_kw_RADIANSFUNK, func_kw_ACOSFUNK, func_kw_ASINFUNK,
154  func_kw_ATANFUNK, func_kw_COSFUNK, func_kw_SINFUNK, func_kw_TANFUNK,
155  func_kw_TRUNCFUNK, func_kw_LENFUNK, func_kw_UPPERFUNK,
156  func_kw_LOWERFUNK, func_kw_LTRIMFUNK, func_kw_RTRIMFUNK,
157  func_kw_PIFUNK, func_kw_MEMCOUNTFUNK, func_kw_HASHFUNK,
158  func_kw_NOWFUNK, func_kw_DIVFUNK, func_kw_FINDSTRFUNK,
159  func_kw_SUBSTRFUNK, func_kw_INTFUNK, func_kw_FLOATFUNK,
160  func_kw_STRINGFUNK> {};
161 
162 } // namespace joda::queryparsing::grammar
163 
164 #endif // JODA_FUNCTIONWRAPPER_H
165 #endif
#define REGISTER_FUNCTION(FCLASS, FSTRUCT, FKEYWORD)
Definition: FunctionWrapper.h:19
UnaryNumberProvider< UnaryAcosCalculationFunction > AcosProvider
Definition: UnaryNumberProvider.h:298
UnaryNumberProvider< UnaryCeilCalculationFunction > CeilProvider
Definition: UnaryNumberProvider.h:207
BinaryNumberProvider< BinaryModCalculationFunction > ModuloProvider
Definition: BinaryNumberProvider.h:265
UnaryStringProvider< UnaryRtrimCalculationFunction > RtrimProvider
Definition: UnaryStringProvider.h:156
BinaryStringProvider< BinarySCONTAINSCalculationFunction > SCONTAINSProvider
Definition: BinaryStringProvider.h:97
BinaryNumberProvider< BinaryAtan2CalculationFunction > Atan2Provider
Definition: BinaryNumberProvider.h:323
UnaryPointerAcceptProvider< joda::query::providers::membercount::MemberCountCalculator > MemberCountProvider
Definition: MemberCountProvider.h:133
TemplateProvider< joda::query::providers::cast::FloatCastCalculator > FloatCastProvider
Definition: CastProvider.h:273
UnaryNumberProvider< UnarySqrtCalculationFunction > SqrtProvider
Definition: UnaryNumberProvider.h:185
UnaryNumberProvider< UnaryTanCalculationFunction > TanProvider
Definition: UnaryNumberProvider.h:411
TemplateProvider< joda::query::providers::cast::IntCastCalculator > IntCastProvider
Definition: CastProvider.h:140
BinaryStringProvider< BinaryFINDSTRCalculationFunction > FINDSTRProvider
Definition: BinaryStringProvider.h:144
UnaryNumberProvider< UnaryAsinCalculationFunction > AsinProvider
Definition: UnaryNumberProvider.h:323
UnaryNumberProvider< UnaryDegreesCalculationFunction > DegreesProvider
Definition: UnaryNumberProvider.h:251
UnaryStringProvider< UnaryUpperCalculationFunction > UpperProvider
Definition: UnaryStringProvider.h:106
UnaryNumberProvider< UnaryAbsCalculationFunction > AbsProvider
Definition: UnaryNumberProvider.h:116
UnaryNumberProvider< UnaryFloorCalculationFunction > FloorProvider
Definition: UnaryNumberProvider.h:229
UnaryNumberProvider< UnaryRadiansCalculationFunction > RadiansProvider
Definition: UnaryNumberProvider.h:273
UnaryStringProvider< UnaryLenCalculationFunction > LenProvider
Definition: UnaryStringProvider.h:91
UnaryNumberProvider< UnaryAtanCalculationFunction > AtanProvider
Definition: UnaryNumberProvider.h:345
UnaryStringProvider< UnaryLowerCalculationFunction > LowerProvider
Definition: UnaryStringProvider.h:121
UnaryNumberProvider< UnaryRoundCalculationFunction > RoundProvider
Definition: UnaryNumberProvider.h:138
UnaryNumberProvider< UnaryTruncCalculationFunction > TruncProvider
Definition: UnaryNumberProvider.h:160
ConstantNumber< PiConstantFunction > PiProvider
Definition: ConstantNumber.h:54
BinaryNumberProvider< BinarySumCalculationFunction > SumProvider
Definition: BinaryNumberProvider.h:152
BinaryNumberProvider< BinaryDivCalculationFunction > DivProvider
Definition: BinaryNumberProvider.h:210
BinaryStringProvider< BinaryConcatCalculationFunction > ConcatProvider
Definition: BinaryStringProvider.h:129
BinaryNumberProvider< BinarySubCalculationFunction > SubtractProvider
Definition: BinaryNumberProvider.h:181
UnaryNumberProvider< UnarySinCalculationFunction > SinProvider
Definition: UnaryNumberProvider.h:389
UnaryStringProvider< UnaryLtrimCalculationFunction > LtrimProvider
Definition: UnaryStringProvider.h:138
BinaryNumberProvider< BinaryProdCalculationFunction > ProductProvider
Definition: BinaryNumberProvider.h:236
ConstantNumber< NowConstantFunction > NowProvider
Definition: ConstantNumber.h:70
BinaryNumberProvider< BinaryPowCalculationFunction > PowerProvider
Definition: BinaryNumberProvider.h:297
UnaryNumberProvider< UnaryCosCalculationFunction > CosProvider
Definition: UnaryNumberProvider.h:367
BinaryStringProvider< BinarySTARTSWITHCalculationFunction > STARTSWITHProvider
Definition: BinaryStringProvider.h:114
UnaryPointerAcceptProvider< joda::query::providers::hash::HashCalculator > HashProvider
Definition: HashProvider.h:135
TemplateProvider< joda::query::providers::listattributes::ListAttributesCalculator > ListAttributesProvider
Definition: ListAttributesProvider.h:178
TemplateProvider< joda::query::providers::cast::StringCastCalculator > StringCastProvider
Definition: CastProvider.h:420
Definition: FunctionWrapper.h:12
Definition: FunctionWrapper.h:160
static constexpr auto toString()
Definition: FunctionWrapper.h:137