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
11// X.h (of X11) has a macro called `Unsorted`
12// See <https://codebrowser.dev/kde/include/X11/X.h.html#_M/Unsorted>
13// and <https://github.com/rerun-io/rerun/issues/7846>.
14#ifdef Unsorted
15#error \
16 "Found a macro 'Unsorted' (probably from X11), conflicting with `rerun::SortingStatus::Unsorted`. Add '#undef Unsorted' before '#include <rerun.hpp>' to work around this."
17#endif
18
19struct rr_time_column;
20
21namespace arrow {
22 class Array;
23}
24
25namespace rerun {
26 /// Describes whether an array is known to be sorted or not.
27 enum class SortingStatus {
28 /// It's not known whether the array is sorted or not.
29 Unknown = 0,
30
31 /// The array is known to be sorted.
32 Sorted = 1,
33
34 /// The array is known to be unsorted.
35 Unsorted = 2,
36 };
37
38 /// Arrow-encoded data for a column of time points.
39 ///
40 /// \see `rerun::RecordingStream::send_columns`
41 struct TimeColumn {
42 /// The timeline this column belongs to.
44
45 /// Time points as a primitive array of i64.
46 std::shared_ptr<arrow::Array> array;
47
48 /// The sorting order of the `times` array.
50
51 public:
52 /// Creates a time column from an array of time points.
53 ///
54 /// \param timeline The timeline this column belongs to.
55 /// \param times The time values.
56 /// Depending on the `TimeType` of the timeline this may be either timestamps or sequence numbers.
57 /// Make sure the sorting status is correctly specified.
58 /// \param sorting_status The sorting status of the time points.
59 /// Already sorted time points may perform better.
63 );
64
65 /// Creates a time column from an array of sequence points.
66 ///
67 /// \param timeline_name The name of the timeline this column belongs to.
68 /// \param sequence_points The sequence points.
69 /// Make sure the sorting status is correctly specified.
70 /// \param sorting_status The sorting status of the sequence points.
71 /// Already sorted time points may perform better.
73 std::string timeline_name, Collection<int64_t> sequence_points,
75 ) {
76 return TimeColumn(
77 Timeline(std::move(timeline_name), TimeType::Sequence),
78 std::move(sequence_points),
80 );
81 }
82
83 /// Creates a time column from an array of nanoseconds.
84 ///
85 /// \param timeline_name The name of the timeline this column belongs to.
86 /// \param times_in_nanoseconds Time values in nanoseconds.
87 /// Make sure the sorting status is correctly specified.
88 /// \param sorting_status The sorting status of the time points.
89 /// Already sorted time points may perform better.
91 std::string timeline_name, Collection<int64_t> times_in_nanoseconds,
93 );
94
95 /// Creates a time column from an array of seconds.
96 ///
97 /// \param timeline_name The name of the timeline this column belongs to.
98 /// \param times_in_seconds Time values in seconds.
99 /// Make sure the sorting status is correctly specified.
100 /// \param sorting_status The sorting status of the time points.
101 /// Already sorted time points may perform better.
103 std::string timeline_name, Collection<double> times_in_seconds,
105 );
106
107 /// Creates a time column from an array of arbitrary std::chrono durations.
108 ///
109 /// \param timeline_name The name of the timeline this column belongs to.
110 /// \param chrono_times Time values as chrono durations.
111 /// Make sure the sorting status is correctly specified.
112 /// \param sorting_status The sorting status of the time points.
113 /// Already sorted time points may perform better.
114 template <typename TRep, typename TPeriod>
116 std::string timeline_name,
117 const Collection<std::chrono::duration<TRep, TPeriod>>& chrono_times,
119 ) {
120 std::vector<int64_t> times(chrono_times.size());
121 for (size_t i = 0; i < chrono_times.size(); i++) {
122 times[i] =
123 std::chrono::duration_cast<std::chrono::nanoseconds>(chrono_times[i]).count();
124 }
125 return TimeColumn(
126 Timeline(std::move(timeline_name), TimeType::Time),
127 std::move(times),
129 );
130 }
131
132 /// To rerun C API component batch.
133 ///
134 /// The resulting `rr_time_column` keeps the `arrow::Array` alive until it is released.
135 Error to_c_ffi_struct(rr_time_column& out_column) const;
136 };
137} // 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:95
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
SortingStatus
Describes whether an array is known to be sorted or not.
Definition time_column.hpp:27
@ 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:41
Timeline timeline
The timeline this column belongs to.
Definition time_column.hpp:43
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:46
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:115
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:72
SortingStatus sorting_status
The sorting order of the times array.
Definition time_column.hpp:49
Definition of a timeline.
Definition timeline.hpp:17