Spicy
interval.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <hilti/ast/builder/type.h>
6 #include <hilti/ast/operators/common.h>
7 #include <hilti/ast/types/integer.h>
8 #include <hilti/ast/types/interval.h>
9 #include <hilti/ast/types/real.h>
10 
11 namespace hilti {
12 namespace operator_ {
13 
14 STANDARD_OPERATOR_2(interval, Equal, type::Bool(), type::Interval(), type::Interval(), "Compares two interval values.")
15 STANDARD_OPERATOR_2(interval, Unequal, type::Bool(), type::Interval(), type::Interval(),
16  "Compares two interval values.")
17 STANDARD_OPERATOR_2(interval, Sum, type::Interval(), type::Interval(), type::Interval(),
18  "Returns the sum of the intervals.");
19 STANDARD_OPERATOR_2(interval, Difference, type::Interval(), type::Interval(), type::Interval(),
20  "Returns the difference of the intervals.");
21 STANDARD_OPERATOR_2(interval, Greater, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
22 STANDARD_OPERATOR_2(interval, GreaterEqual, type::Bool(), type::Interval(), type::Interval(),
23  "Compares the intervals.");
24 STANDARD_OPERATOR_2(interval, Lower, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
25 STANDARD_OPERATOR_2(interval, LowerEqual, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
26 STANDARD_OPERATOR_2x(interval, MultipleUnsignedInteger, Multiple, type::Interval(), type::Interval(),
27  type::UnsignedInteger(64), "Multiples the interval with the given factor.");
28 STANDARD_OPERATOR_2x(interval, MultipleReal, Multiple, type::Interval(), type::Interval(), type::Real(),
29  "Multiplies the interval with the given factor.");
30 
31 BEGIN_METHOD(interval, Seconds)
32  auto signature() const {
33  return Signature{.self = type::Interval(), .result = type::Real(), .id = "seconds", .args = {}, .doc = R"(
34 Returns the interval as a real value representing seconds.
35 )"};
36  }
37 END_METHOD
38 
39 BEGIN_METHOD(interval, Nanoseconds)
40  auto signature() const {
41  return Signature{.self = type::Interval(),
42  .result = type::SignedInteger(64),
43  .id = "nanoseconds",
44  .args = {},
45  .doc = R"(
46 Returns the interval as an integer value representing nanoseconds.
47 )"};
48  }
49 END_METHOD
50 
51 } // namespace operator_
52 } // namespace hilti