src/TimeFrame/TimeFrame.hpp
src/TimeFrame/TimeFrame.hpp
Classes
| Name | |
|---|---|
| class | TimeFrame |
| struct | TimeIndexAndFrame |
| struct | TimePosition Position in time with clock identity. |
| struct | FilenameTimeFrameOptions Options for creating TimeFrame from image folder filenames. |
Types
| Name | |
|---|---|
| enum class | FilenameTimeFrameMode { FOUND_VALUES, ZERO_TO_MAX, MIN_TO_MAX} Mode for creating TimeFrame from filename-extracted values. |
Functions
| Name | |
|---|---|
| std::pair< TimeFrameIndex, TimeFrameIndex > | convertTimeFrameRange(TimeFrameIndex start_index, TimeFrameIndex stop_index, TimeFrame const & from_time_frame, TimeFrame const & to_time_frame) Converts a time index range from one TimeFrame to another. |
| TimeFrameIndex | convert_time_index(TimeFrameIndex const time, TimeFrame const * source_timeframe, TimeFrame const * target_timeframe) Convert a time index from one TimeFrame to another. |
| std::shared_ptr< TimeFrame > | createTimeFrameFromFilenames(FilenameTimeFrameOptions const & options) |
Types Documentation
enum FilenameTimeFrameMode
| Enumerator | Value | Description |
|---|---|---|
| FOUND_VALUES | Use only the values found in filenames (sparse). | |
| ZERO_TO_MAX | Create range from 0 to maximum found value (dense). | |
| MIN_TO_MAX | Create range from minimum to maximum found value (dense). |
Mode for creating TimeFrame from filename-extracted values.
Functions Documentation
function convertTimeFrameRange
std::pair< TimeFrameIndex, TimeFrameIndex > convertTimeFrameRange(
TimeFrameIndex start_index,
TimeFrameIndex stop_index,
TimeFrame const & from_time_frame,
TimeFrame const & to_time_frame
)Converts a time index range from one TimeFrame to another.
Parameters:
- start_index The start index in the source timeframe
- stop_index The stop index in the source timeframe
- from_time_frame The source timeframe containing the input range
- to_time_frame The target timeframe for the converted range
Return: A pair of TimeFrameIndex representing the converted start and stop indices
This function takes a range defined by start and stop indices in the source timeframe and converts it to the corresponding range in the target timeframe. The conversion is done by:
- Getting the time values at the source indices
- Finding the corresponding indices in the target timeframe
function convert_time_index
TimeFrameIndex convert_time_index(
TimeFrameIndex const time,
TimeFrame const * source_timeframe,
TimeFrame const * target_timeframe
)Convert a time index from one TimeFrame to another.
Parameters:
- time The time index to convert.
- source_timeframe The source TimeFrame.
- target_timeframe The target TimeFrame.
Return: The converted time index.
function createTimeFrameFromFilenames
std::shared_ptr< TimeFrame > createTimeFrameFromFilenames(
FilenameTimeFrameOptions const & options
)Source code
#ifndef TIMEFRAME_HPP
#define TIMEFRAME_HPP
#include "ClockTicks.hpp"
#include "TimeFrameIndex.hpp"
#include <memory>
#include <string>
#include <vector>
class TimeFrame {
public:
TimeFrame() = default;
explicit TimeFrame(std::vector<int> const & times);
[[nodiscard]] int getTotalFrameCount() const { return _total_frame_count; };
[[nodiscard]] ClockTicks getTimeAtIndex(TimeFrameIndex index) const;
[[nodiscard]] TimeFrameIndex getIndexAtTime(ClockTicks time, bool preceding = true) const;
[[nodiscard]] int checkFrameInbounds(int frame_id) const;
protected:
private:
std::vector<ClockTicks> _times;
int _total_frame_count{0};
};
//TimeFrameIndex and TimeFrame struct
struct TimeIndexAndFrame {
TimeFrameIndex index;
TimeFrame const * const time_frame;
TimeIndexAndFrame(int64_t index_value, TimeFrame const * time_frame_ptr)
: index(TimeFrameIndex(index_value)),
time_frame(time_frame_ptr) {}
TimeIndexAndFrame(TimeFrameIndex time_frame_index, TimeFrame const * time_frame_ptr)
: index(time_frame_index),
time_frame(time_frame_ptr) {}
};
[[nodiscard]] std::pair<TimeFrameIndex, TimeFrameIndex> convertTimeFrameRange(
TimeFrameIndex start_index,
TimeFrameIndex stop_index,
TimeFrame const & from_time_frame,
TimeFrame const & to_time_frame);
TimeFrameIndex convert_time_index(TimeFrameIndex const time,
TimeFrame const * source_timeframe,
TimeFrame const * target_timeframe);
struct TimePosition {
TimeFrameIndex index{0};
std::shared_ptr<TimeFrame> time_frame;
TimePosition() = default;
TimePosition(TimeFrameIndex idx, std::shared_ptr<TimeFrame> tf)
: index(idx),
time_frame(std::move(tf)) {}
explicit TimePosition(int64_t idx, std::shared_ptr<TimeFrame> tf = nullptr)
: index(TimeFrameIndex(idx)),
time_frame(std::move(tf)) {}
[[nodiscard]] bool sameClock(TimePosition const & other) const {
return time_frame.get() == other.time_frame.get();
}
[[nodiscard]] bool sameClock(TimeFrame const * other) const {
return time_frame.get() == other;
}
[[nodiscard]] bool sameClock(std::shared_ptr<TimeFrame> const & other) const {
return time_frame.get() == other.get();
}
[[nodiscard]] TimeFrameIndex convertTo(TimeFrame const * target) const {
if (!time_frame || !target || time_frame.get() == target) {
return index;
}
return convert_time_index(index, time_frame.get(), target);
}
[[nodiscard]] TimeFrameIndex convertTo(std::shared_ptr<TimeFrame> const & target) const {
return convertTo(target.get());
}
[[nodiscard]] bool isValid() const {
return time_frame != nullptr;
}
bool operator==(TimePosition const & other) const {
return sameClock(other) && index == other.index;
}
bool operator!=(TimePosition const & other) const {
return !(*this == other);
}
};
// ========== Filename-based TimeFrame Creation ==========
enum class FilenameTimeFrameMode {
FOUND_VALUES,
ZERO_TO_MAX,
MIN_TO_MAX
};
struct FilenameTimeFrameOptions {
std::string folder_path;
std::string file_extension;
std::string regex_pattern;
FilenameTimeFrameMode mode;
bool sort_ascending = true;
};
std::shared_ptr<TimeFrame> createTimeFrameFromFilenames(FilenameTimeFrameOptions const & options);
#endif// TIMEFRAME_HPPUpdated on 2026-11-13 at 20:25:44 +0000