src/TimeFrame/interval_data.hpp
src/TimeFrame/interval_data.hpp
Classes
| Name | |
|---|---|
| struct | IntervalT |
Types
| Name | |
|---|---|
| using IntervalT< int64_t > | Interval |
| using IntervalT< TimeFrameIndex > | TimeFrameInterval |
| using IntervalT< ClockTicks > | ClockTicksInterval |
Functions
| Name | |
|---|---|
| template <typename T > bool |
operator<(IntervalT< T > const & a, IntervalT< T > const & b) |
| template <typename T > bool |
is_overlapping(IntervalT< T > const & a, IntervalT< T > const & b) |
| template <typename T > bool |
is_contiguous(IntervalT< T > const & a, IntervalT< T > const & b) |
| template <typename T > bool |
is_contained(IntervalT< T > const & a, IntervalT< T > const & b) |
| template <typename T > bool |
is_contained(IntervalT< T > const & a, T const time) |
| template bool | is_overlapping(Interval const & a, Interval const & b) |
| template bool | is_contiguous(Interval const & a, Interval const & b) |
| template bool | is_contained(Interval const & a, Interval const & b) |
| template bool | is_contained(Interval const & a, int64_t const time) |
| template bool | operator<(Interval const & a, Interval const & b) |
| template bool | is_overlapping(TimeFrameInterval const & a, TimeFrameInterval const & b) |
| template bool | is_contiguous(TimeFrameInterval const & a, TimeFrameInterval const & b) |
| template bool | is_contained(TimeFrameInterval const & a, TimeFrameInterval const & b) |
| template bool | is_contained(TimeFrameInterval const & a, TimeFrameIndex const time) |
| template bool | operator<(TimeFrameInterval const & a, TimeFrameInterval const & b) |
| ClockTicksInterval | toClockTicksInterval(TimeFrameInterval const & interval, TimeFrame const & time_frame) Convert a TimeFrame-indexed interval to absolute clock ticks. |
| TimeFrameInterval | toTimeFrameInterval(ClockTicksInterval const & interval, TimeFrame const & time_frame) Convert a clock-tick interval to TimeFrame indices. |
Types Documentation
using Interval
using Interval = IntervalT<int64_t>;using TimeFrameInterval
using TimeFrameInterval = IntervalT<TimeFrameIndex>;using ClockTicksInterval
using ClockTicksInterval = IntervalT<ClockTicks>;Functions Documentation
function operator<
template <typename T >
inline bool operator<(
IntervalT< T > const & a,
IntervalT< T > const & b
)function is_overlapping
template <typename T >
inline bool is_overlapping(
IntervalT< T > const & a,
IntervalT< T > const & b
)function is_contiguous
template <typename T >
inline bool is_contiguous(
IntervalT< T > const & a,
IntervalT< T > const & b
)function is_contained
template <typename T >
inline bool is_contained(
IntervalT< T > const & a,
IntervalT< T > const & b
)function is_contained
template <typename T >
inline bool is_contained(
IntervalT< T > const & a,
T const time
)function is_overlapping
template bool is_overlapping(
Interval const & a,
Interval const & b
)function is_contiguous
template bool is_contiguous(
Interval const & a,
Interval const & b
)function is_contained
template bool is_contained(
Interval const & a,
Interval const & b
)function is_contained
template bool is_contained(
Interval const & a,
int64_t const time
)function operator<
template bool operator<(
Interval const & a,
Interval const & b
)function is_overlapping
template bool is_overlapping(
TimeFrameInterval const & a,
TimeFrameInterval const & b
)function is_contiguous
template bool is_contiguous(
TimeFrameInterval const & a,
TimeFrameInterval const & b
)function is_contained
template bool is_contained(
TimeFrameInterval const & a,
TimeFrameInterval const & b
)function is_contained
template bool is_contained(
TimeFrameInterval const & a,
TimeFrameIndex const time
)function operator<
template bool operator<(
TimeFrameInterval const & a,
TimeFrameInterval const & b
)function toClockTicksInterval
inline ClockTicksInterval toClockTicksInterval(
TimeFrameInterval const & interval,
TimeFrame const & time_frame
)Convert a TimeFrame-indexed interval to absolute clock ticks.
Parameters:
- interval Interval with start/end as indices into
time_frame - time_frame TimeFrame used to resolve indices to ClockTicks
Return: ClockTicksInterval in physical time
function toTimeFrameInterval
inline TimeFrameInterval toTimeFrameInterval(
ClockTicksInterval const & interval,
TimeFrame const & time_frame
)Convert a clock-tick interval to TimeFrame indices.
Parameters:
Return: TimeFrameInterval with start/end indices into time_frame
Source code
#ifndef INTERVAL_DATA_HPP
#define INTERVAL_DATA_HPP
#include "TimeFrame/ClockTicks.hpp"
#include "TimeFrame/TimeFrame.hpp"
#include "TimeFrame/TimeFrameIndex.hpp"
#include <cstdint>
template<typename T>
struct IntervalT {
T start;
T end;
bool operator==(IntervalT const & other) const {
return start == other.start && end == other.end;
}
};
// Type aliases for backwards compatibility and common types
using Interval = IntervalT<int64_t>;
using TimeFrameInterval = IntervalT<TimeFrameIndex>;
using ClockTicksInterval = IntervalT<ClockTicks>;
template<typename T>
inline bool operator<(IntervalT<T> const & a, IntervalT<T> const & b) {
return a.start < b.start;
}
template<typename T>
inline bool is_overlapping(IntervalT<T> const & a, IntervalT<T> const & b) {
return a.start <= b.end && b.start <= a.end;
}
template<typename T>
inline bool is_contiguous(IntervalT<T> const & a, IntervalT<T> const & b) {
return a.end + T(1) == b.start || b.end + T(1) == a.start;
}
template<typename T>
inline bool is_contained(IntervalT<T> const & a, IntervalT<T> const & b) {
return a.start <= b.start && a.end >= b.end;
}
template<typename T>
inline bool is_contained(IntervalT<T> const & a, T const time) {
return a.start <= time && time <= a.end;
}
//instantiate the template functions for the common types
template bool is_overlapping(Interval const & a, Interval const & b);
template bool is_contiguous(Interval const & a, Interval const & b);
template bool is_contained(Interval const & a, Interval const & b);
template bool is_contained(Interval const & a, int64_t const time);
template bool operator<(Interval const & a, Interval const & b);
template bool is_overlapping(TimeFrameInterval const & a, TimeFrameInterval const & b);
template bool is_contiguous(TimeFrameInterval const & a, TimeFrameInterval const & b);
template bool is_contained(TimeFrameInterval const & a, TimeFrameInterval const & b);
template bool is_contained(TimeFrameInterval const & a, TimeFrameIndex const time);
template bool operator<(TimeFrameInterval const & a, TimeFrameInterval const & b);
[[nodiscard]] inline ClockTicksInterval toClockTicksInterval(
TimeFrameInterval const & interval,
TimeFrame const & time_frame) {
return ClockTicksInterval{
time_frame.getTimeAtIndex(interval.start),
time_frame.getTimeAtIndex(interval.end)};
}
[[nodiscard]] inline TimeFrameInterval toTimeFrameInterval(
ClockTicksInterval const & interval,
TimeFrame const & time_frame) {
return TimeFrameInterval{
time_frame.getIndexAtTime(interval.start),
time_frame.getIndexAtTime(interval.end)};
}
#endif//INTERVAL_DATA_HPPUpdated on 2026-11-13 at 20:25:44 +0000