OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
CSVCellGroup.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
26 #define INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
27 
28 // Internal Includes
29 #include <osvr/Util/CSV.h>
30 #include <osvr/Util/TimeValue.h>
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 // - none
37 
38 namespace osvr {
39 namespace util {
40  struct DefaultGroupTag;
48  template <typename RowProxyType, typename GroupTag = DefaultGroupTag>
49  class CellGroupProxy {
50  public:
51  CellGroupProxy(RowProxyType &row, const char *groupPrefix)
52  : row_(row), prefix_(groupPrefix){};
53 
54  RowProxyType getRow() { return std::forward<RowProxyType>(row_); }
55 
56  std::string const &getPrefix() const { return prefix_; }
57 
58  private:
59  RowProxyType &row_;
60  const std::string prefix_;
61  };
62 
67  template <typename RowProxyType, typename GroupTag, typename... CellArgs>
68  inline CellGroupProxy<RowProxyType, GroupTag> &
69  operator<<(CellGroupProxy<RowProxyType, GroupTag> &group,
70  detail::Cell<CellArgs...> &&currentCell) {
71  // cell.addHeaderPrefix(group.getPrefix());
72  group.getRow().add(cell(group.getPrefix() + currentCell.getHeader(),
73  currentCell.getData()));
74  return group;
75  }
76 
77  namespace detail {
80  template <typename T, typename Tag = DefaultGroupTag> class CellGroup {
81  public:
82  CellGroup(const char *prefix, T const &data)
83  : prefix_(prefix), data_(data) {}
84 
85  const char *getPrefix() const { return prefix_; }
86  T const &getData() const { return data_; }
87 
88  private:
89  const char *prefix_;
90  T const &data_;
91  };
92 
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> &;
102  auto proxy =
103  CellGroupProxy<RowProxyType, Tag>{row, group.getPrefix()};
104  proxy << group.getData();
105  return row;
106  }
107 
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);
121  }
122 
123  } // namespace detail
124 
126  template <typename T>
127  inline detail::CellGroup<T> cellGroup(const char *groupHeader,
128  T const &data) {
129  return detail::CellGroup<T>{groupHeader, data};
130  }
133  template <typename Tag, typename T>
134  inline detail::CellGroup<T, Tag>
135  cellGroup(const char *groupHeader, T const &data,
136  Tag * /*dummy*/ = static_cast<Tag *>(nullptr)) {
137  return detail::CellGroup<T, Tag>{groupHeader, data};
138  }
141  template <typename T> inline detail::CellGroup<T> cellGroup(T const &data) {
142  return detail::CellGroup<T>{"", data};
143  }
144 
147  template <typename Tag, typename T>
148  inline detail::CellGroup<T, Tag>
149  cellGroup(T const &data, Tag * /*dummy*/ = static_cast<Tag *>(nullptr)) {
150  return detail::CellGroup<T, Tag>{"", data};
151  }
152 
153  template <typename T>
154  inline void operator<<(CellGroupProxy<T, DefaultGroupTag> &group,
155  time::TimeValue const &tv) {
156  group << cell("seconds", tv.seconds)
157  << cell("microseconds", tv.microseconds);
158  }
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());
163  }
164 
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());
170  }
171 
172 } // namespace util
173 } // namespace osvr
174 #endif // INCLUDED_CSVCellGroup_h_GUID_F36004E7_71A4_43AD_7353_B67BCBD8045A
::OSVR_TimeValue TimeValue
C++-friendly typedef for the OSVR_TimeValue structure.
Definition: TimeValue.h:48
detail::CellGroup< T > cellGroup(const char *groupHeader, T const &data)
Helper function to create a cell group with a group header prefix.
Definition: CSVCellGroup.h:160
Header providing a C++ wrapper around TimeValueC.h.
Header.
detail::Cell< T > cell(const char *header, T const &data)
Helper free function to make a CSV cell.
Definition: CSV.h:401