25 #ifndef INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
26 #define INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
40 struct DefaultGroupTag;
48 template <
typename RowProxyType,
typename GroupTag = DefaultGroupTag>
49 class CellGroupProxy {
51 CellGroupProxy(RowProxyType &row,
const char *groupPrefix)
52 : row_(row), prefix_(groupPrefix){};
54 RowProxyType getRow() {
return std::forward<RowProxyType>(row_); }
56 std::string
const &getPrefix()
const {
return prefix_; }
60 const std::string prefix_;
67 template <
typename RowProxyType,
typename GroupTag,
typename... CellArgs>
68 inline CellGroupProxy<RowProxyType, GroupTag> &
69 operator<<(CellGroupProxy<RowProxyType, GroupTag> &group,
70 detail::Cell<CellArgs...> &¤tCell) {
72 group.getRow().add(
cell(group.getPrefix() + currentCell.getHeader(),
73 currentCell.getData()));
80 template <
typename T,
typename Tag = DefaultGroupTag>
class CellGroup {
82 CellGroup(
const char *prefix, T
const &data)
83 : prefix_(prefix), data_(data) {}
85 const char *getPrefix()
const {
return prefix_; }
86 T
const &getData()
const {
return data_; }
97 template <
typename Derived,
typename T,
typename Tag>
98 inline CSVRowProxy<Derived> &
99 operator<<(CSVRowProxy<Derived> &row,
100 detail::CellGroup<T, Tag>
const &group) {
101 using RowProxyType = CSVRowProxy<Derived> &;
103 CellGroupProxy<RowProxyType, Tag>{row, group.getPrefix()};
104 proxy << group.getData();
112 template <
typename Derived,
typename T,
typename Tag>
113 inline CSVRowProxy<Derived> &&
114 operator<<(CSVRowProxy<Derived> &&row,
115 detail::CellGroup<T>
const &group) {
116 using RowProxyType = CSVRowProxy<Derived> &&;
117 auto proxy = CellGroupProxy<RowProxyType, Tag>{
118 std::forward<RowProxyType>(row), group.getPrefix()};
119 proxy << group.getData();
120 return std::move(row);
126 template <
typename T>
127 inline detail::CellGroup<T>
cellGroup(
const char *groupHeader,
129 return detail::CellGroup<T>{groupHeader, data};
133 template <
typename Tag,
typename T>
134 inline detail::CellGroup<T, Tag>
136 Tag * = static_cast<Tag *>(
nullptr)) {
141 template <
typename T>
inline detail::CellGroup<T>
cellGroup(T
const &data) {
142 return detail::CellGroup<T>{
"", data};
147 template <
typename Tag,
typename T>
148 inline detail::CellGroup<T, Tag>
149 cellGroup(T
const &data, Tag * = static_cast<Tag *>(
nullptr)) {
153 template <
typename T>
154 inline void operator<<(CellGroupProxy<T, DefaultGroupTag> &group,
156 group <<
cell(
"seconds", tv.seconds)
157 <<
cell(
"microseconds", tv.microseconds);
159 template <
typename T>
160 inline void operator<<(CellGroupProxy<T, DefaultGroupTag> &group,
161 Eigen::Vector3d
const &v) {
162 group <<
cell(
"x", v.x()) <<
cell(
"y", v.y()) <<
cell(
"z", v.z());
165 template <
typename T>
166 inline void operator<<(CellGroupProxy<T, DefaultGroupTag> &group,
167 Eigen::Quaterniond
const &q) {
168 group <<
cell(
"qw", q.w()) <<
cell(
"qx", q.x()) <<
cell(
"qy", q.y())
169 <<
cell(
"qz", q.z());
174 #endif // INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
::OSVR_TimeValue TimeValue
C++-friendly typedef for the OSVR_TimeValue structure.
detail::CellGroup< T > cellGroup(const char *groupHeader, T const &data)
Helper function to create a cell group with a group header prefix.
Header providing a C++ wrapper around TimeValueC.h.
detail::Cell< T > cell(const char *header, T const &data)
Helper free function to make a CSV cell.