JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
ConstantNumber.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 24/05/2019.
3 //
4 
5 #ifndef JODA_CONSTANTNUMBER_H
6 #define JODA_CONSTANTNUMBER_H
7 #include "AtomProvider.h"
8 #include "IValueProvider.h"
9 
10 namespace joda::query {
23 template <class Calc>
24 class ConstantNumber : public AtomProvider<typename Calc::AtomType> {
25  public:
26  explicit ConstantNumber(
27  std::vector<std::unique_ptr<IValueProvider>> &&parameters)
28  : AtomProvider<typename Calc::AtomType>(Calc::value()) {
29  if (parameters.size() != 0) {
30  throw WrongParameterCountException(parameters.size(), 0, getName());
31  }
32  }
33 
34  explicit ConstantNumber()
35  : AtomProvider<typename Calc::AtomType>(Calc::value()) {}
36 
37  std::string getName() const override { return std::string(Calc::name); }
38 
39  std::string toString() const override { return getName() + "()"; }
40 
42 };
43 
48  typedef double AtomType;
49  static constexpr auto name = "PI";
50 
51  static constexpr auto value() { return M_PI; }
52 };
53 
55 
60  typedef uint64_t AtomType;
61  static constexpr auto name = "NOW";
62 
63  static auto value() {
64  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
65  std::chrono::system_clock::now().time_since_epoch());
66  return ms.count();
67  }
68 };
69 
71 
73 
75 } // namespace joda::query
76 #endif // JODA_CONSTANTNUMBER_H
#define CREATE_FACTORY(FCLASS)
Definition: IValueProvider.h:20
Definition: AtomProvider.h:22
Definition: ConstantNumber.h:24
std::string getName() const override
Definition: ConstantNumber.h:37
ConstantNumber()
Definition: ConstantNumber.h:34
std::string toString() const override
Definition: ConstantNumber.h:39
ConstantNumber(std::vector< std::unique_ptr< IValueProvider >> &&parameters)
Definition: ConstantNumber.h:26
Definition: IValueProvider.h:96
Definition: AttributeStatAggregator.h:12
ConstantNumber< PiConstantFunction > PiProvider
Definition: ConstantNumber.h:54
ConstantNumber< NowConstantFunction > NowProvider
Definition: ConstantNumber.h:70
Definition: ConstantNumber.h:59
uint64_t AtomType
Definition: ConstantNumber.h:60
static auto value()
Definition: ConstantNumber.h:63
static constexpr auto name
Definition: ConstantNumber.h:61
Definition: ConstantNumber.h:47
static constexpr auto name
Definition: ConstantNumber.h:49
static constexpr auto value()
Definition: ConstantNumber.h:51
double AtomType
Definition: ConstantNumber.h:48