Rerun C++ SDK
Loading...
Searching...
No Matches
time_column.hpp
1#pragma once
2
3#include <cassert>
4#include <chrono>
5#include <memory> // shared_ptr
6
7#include "collection.hpp"
8#include "error.hpp"
9#include "timeline.hpp"
10
11struct rr_time_column;
12
13namespace arrow {
14 class Array;
15}
16
17namespace rerun {
18 /// Describes whether an array is known to be sorted or not.
19 enum class SortingStatus {
20 /// It's not known whether the array is sorted or not.
21 Unknown = 0,
22
23 /// The array is known to be sorted.
24 Sorted = 1,
25
26 /// The array is known to be unsorted.
27 Unsorted = 2,
28 };
29
30 /// Arrow-encoded data for a column of time points.
31 ///
32 /// \see `rerun::RecordingStream::send_columns`
33 struct TimeColumn {
34 /// The timeline this column belongs to.
36
37 /// Time points as a primitive array of i64.
38 std::shared_ptr<arrow::Array> array;
39
40 /// The sorting order of the `times` array.
42
43 public:
44 /// Creates a time column from an array of time points.
45 ///
46 /// \param timeline The timeline this column belongs to.
47 /// \param times The time values.
48 /// Depending on the `TimeType` of the timeline this may be either timestamps or sequence numbers.
49 /// Make sure the sorting status is correctly specified.
50 /// \param sorting_status The sorting status of the time points.
51 /// Already sorted time points may perform better.
55 );
56
57 /// Creates a time column from an array of sequence points.
58 ///
59 /// \param timeline_name The name of the timeline this column belongs to.
60 /// \param sequence_points The sequence points.
61 /// Make sure the sorting status is correctly specified.
62 /// \param sorting_status The sorting status of the sequence points.
63 /// Already sorted time points may perform better.
65 std::string timeline_name, Collection<int64_t> sequence_points,
67 ) {
68 return TimeColumn(
69 Timeline(std::move(timeline_name), TimeType::Sequence),
70 std::move(sequence_points),
72 );
73 }
74
75 /// Creates a time column from an array of nanoseconds.
76 ///
77 /// \param timeline_name The name of the timeline this column belongs to.
78 /// \param times_in_nanoseconds Time values in nanoseconds.
79 /// Make sure the sorting status is correctly specified.
80 /// \param sorting_status The sorting status of the time points.
81 /// Already sorted time points may perform better.
83 std::string timeline_name, Collection<int64_t> times_in_nanoseconds,
85 );
86
87 /// Creates a time column from an array of seconds.
88 ///
89 /// \param timeline_name The name of the timeline this column belongs to.
90 /// \param times_in_seconds Time values in seconds.
91 /// Make sure the sorting status is correctly specified.
92 /// \param sorting_status The sorting status of the time points.
93 /// Already sorted time points may perform better.
95 std::string timeline_name, Collection<double> times_in_seconds,
97 );
98
99 /// Creates a time column from an array of arbitrary std::chrono durations.
100 ///
101 /// \param timeline_name The name of the timeline this column belongs to.
102 /// \param chrono_times Time values as chrono durations.
103 /// Make sure the sorting status is correctly specified.
104 /// \param sorting_status The sorting status of the time points.
105 /// Already sorted time points may perform better.
106 template <typename TRep, typename TPeriod>
108 std::string timeline_name,
109 const Collection<std::chrono::duration<TRep, TPeriod>>& chrono_times,
111 ) {
112 std::vector<int64_t> times(chrono_times.size());
113 for (size_t i = 0; i < chrono_times.size(); i++) {
114 times[i] =
115 std::chrono::duration_cast<std::chrono::nanoseconds>(chrono_times[i]).count();
116 }
117 return TimeColumn(
118 Timeline(std::move(timeline_name), TimeType::Time),
119 std::move(times),
121 );
122 }
123
124 /// To rerun C API component batch.
125 ///
126 /// The resulting `rr_time_column` keeps the `arrow::Array` alive until it is released.
127 Error to_c_ffi_struct(rr_time_column& out_column) const;
128 };
129} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:91
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
SortingStatus
Describes whether an array is known to be sorted or not.
Definition time_column.hpp:19
@ Sorted
The array is known to be sorted.
@ Unsorted
The array is known to be unsorted.
@ Unknown
It's not known whether the array is sorted or not.
Arrow-encoded data for a column of time points.
Definition time_column.hpp:33
Timeline timeline
The timeline this column belongs to.
Definition time_column.hpp:35
TimeColumn(Timeline timeline, Collection< int64_t > times, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of time points.
static TimeColumn from_seconds(std::string timeline_name, Collection< double > times_in_seconds, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of seconds.
std::shared_ptr< arrow::Array > array
Time points as a primitive array of i64.
Definition time_column.hpp:38
static TimeColumn from_times(std::string timeline_name, const Collection< std::chrono::duration< TRep, TPeriod > > &chrono_times, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of arbitrary std::chrono durations.
Definition time_column.hpp:107
static TimeColumn from_nanoseconds(std::string timeline_name, Collection< int64_t > times_in_nanoseconds, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of nanoseconds.
Error to_c_ffi_struct(rr_time_column &out_column) const
To rerun C API component batch.
static TimeColumn from_sequence_points(std::string timeline_name, Collection< int64_t > sequence_points, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of sequence points.
Definition time_column.hpp:64
SortingStatus sorting_status
The sorting order of the times array.
Definition time_column.hpp:41
Definition of a timeline.
Definition timeline.hpp:17