DataHeader.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
36 //----------------------------------------------------------------------
37 #ifndef ICL_CORE_DATA_HEADER_H_INCLUDED
38 #define ICL_CORE_DATA_HEADER_H_INCLUDED
39 
40 #include <string>
41 #include <boost/shared_ptr.hpp>
42 #include <boost/date_time.hpp>
43 #include <boost/version.hpp>
44 #if (BOOST_VERSION >= 104800)
45 # include <boost/type_traits/has_left_shift.hpp>
46 #endif
47 #include <icl_core/ImportExport.h>
48 #include <icl_core/BaseTypes.h>
49 
50 #ifdef _IC_BUILDER_EIGEN_
51 #include <Eigen/Core>
52 #endif
53 
54 namespace icl_core {
55 
61 struct DataHeader
62 {
68  timestamp(),
70  { }
71 
73  DataHeader(const std::string& coordinate_system,
74  const boost::posix_time::ptime& timestamp,
76  : coordinate_system(coordinate_system),
77  timestamp(timestamp),
79  { }
80 
83  { }
84 
86  std::string coordinate_system;
88  boost::posix_time::ptime timestamp;
96  std::size_t dsin;
97 };
98 
99 
104 {
106  typedef boost::shared_ptr<StampedBase> Ptr;
107  typedef boost::shared_ptr<const StampedBase> ConstPtr;
108 
111  {}
112 
113  virtual ~StampedBase()
114  {}
115 
119  virtual void print(std::ostream& os) const = 0;
120 
122  virtual DataHeader& header() = 0;
124  virtual const DataHeader& header() const = 0;
125 };
126 
127 namespace internal {
128 
136 template <typename T, bool has_left_shift>
137 struct ToStream;
138 
139 template <typename T>
140 struct ToStream<T, false>
141 {
142  static std::ostream& print(std::ostream& os, const T& obj)
143  {
144  return os << sizeof(T) << " data bytes";
145  }
146 };
147 
148 template <typename T>
149 struct ToStream<T, true>
150 {
151  static std::ostream& print(std::ostream& os, const T& obj)
152  {
153  return os << obj;
154  }
155 };
156 
157 }
158 
162 template <class DataType>
163 struct Stamped : public StampedBase
164 {
165 private:
166  // IMPORTANT: Do not change the order (data -> header) as it is
167  // important for memory alignment!
168 
170  DataType m_data;
173 
174 public:
175  /* If we build against Eigen it is possible that the DataType depends on
176  * Eigen. Then the Stamped should be aligned.
177  */
178 #ifdef _IC_BUILDER_EIGEN_
179  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
180 #endif
181 
183  typedef boost::shared_ptr<Stamped<DataType> > Ptr;
185  typedef boost::shared_ptr<const Stamped<DataType> > ConstPtr;
186 
189  : m_header()
190  { }
191 
193  Stamped(const DataType& data)
194  : m_data(data),
195  m_header()
196  { }
197 
199  Stamped(const DataHeader& header)
200  : m_header(header)
201  { }
202 
204  Stamped(const DataType& data, const DataHeader& header)
205  : m_data(data),
206  m_header(header)
207  { }
208 
210  inline operator DataType () const { return m_data; }
211 
213  virtual DataHeader& header() { return m_header; }
215  virtual const DataHeader& header() const { return m_header; }
216 
220  inline DataType& get() { return m_data; }
224  inline const DataType& get() const { return m_data; }
229  inline const DataType& cget() const { return m_data; }
230 
232  inline DataType& operator * () { return m_data; }
234  inline const DataType& operator * () const { return m_data; }
235 
237  inline DataType *operator -> () { return &m_data; }
239  inline const DataType *operator -> () const { return &m_data; }
240 
262  virtual void print(std::ostream& os) const
263  {
264  os << "[seq: " << this->m_header.sequence_number
265  << ", timestamp: " << boost::posix_time::to_simple_string(this->m_header.timestamp)
266  << ", DSIN: " << this->m_header.dsin
267  << ", Frame: " << m_header.coordinate_system
268  << "; ";
269 #if (BOOST_VERSION >= 104800)
271 #else
272  // Boost versions prior to 1.48 do not have the has_left_shift
273  // type trait.
275 #endif
276  os << "]";
277  }
278 };
279 
284 ICL_CORE_IMPORT_EXPORT std::ostream& operator << (std::ostream& os, StampedBase const& stamped);
285 
286 }
287 
288 #endif
unsigned int uint32_t
Definition: msvc_stdint.h:93
std::ostream & operator<<(std::ostream &os, StampedBase const &stamped)
Definition: DataHeader.cpp:27
Stamped(const DataHeader &header)
Implicit construction from a data header.
Definition: DataHeader.h:199
virtual void print(std::ostream &os) const
Definition: DataHeader.h:262
virtual DataHeader & header()
Access the data header.
Definition: DataHeader.h:213
Stamped()
Default constructor which leaves the data uninitialized.
Definition: DataHeader.h:188
boost::shared_ptr< StampedBase > Ptr
Convenience shared pointer typedefs.
Definition: DataHeader.h:106
virtual ~StampedBase()
Definition: DataHeader.h:113
#define ICL_CORE_IMPORT_EXPORT
Definition: ImportExport.h:42
std::string coordinate_system
An identifier for the coordinate system used.
Definition: DataHeader.h:86
virtual const DataHeader & header() const
Access the data header (const version).
Definition: DataHeader.h:215
StampedBase()
define default Constructor and Destructor for boost_dynamic_cast
Definition: DataHeader.h:110
boost::shared_ptr< Stamped< DataType > > Ptr
Convenience smart pointer typedef.
Definition: DataHeader.h:183
Stamped(const DataType &data, const DataHeader &header)
Full constructor.
Definition: DataHeader.h:204
DataHeader m_header
The data header.
Definition: DataHeader.h:172
static std::ostream & print(std::ostream &os, const T &obj)
Definition: DataHeader.h:142
Contains import/export definitions for the Win32 plattform.
Stamped(const DataType &data)
Implicit construction from a data value.
Definition: DataHeader.h:193
DataHeader(const std::string &coordinate_system, const boost::posix_time::ptime &timestamp, uint32_t sequence_number=0)
Constructor.
Definition: DataHeader.h:73
const DataType & cget() const
Definition: DataHeader.h:229
DataType m_data
The wrapped data.
Definition: DataHeader.h:170
Contains Interface base classes and base types.
boost::shared_ptr< const Stamped< DataType > > ConstPtr
Convenience smart pointer typedef.
Definition: DataHeader.h:185
TimeSpan operator*(const TimeSpan &span, double divisor)
Definition: TimeSpan.h:216
boost::shared_ptr< const StampedBase > ConstPtr
Definition: DataHeader.h:107
static std::ostream & print(std::ostream &os, const T &obj)
Definition: DataHeader.h:151
~DataHeader()
Destructor.
Definition: DataHeader.h:82
std::size_t dsin
Definition: DataHeader.h:96
uint32_t sequence_number
A sequence number to distinguish data with identical timestamps.
Definition: DataHeader.h:90
boost::posix_time::ptime timestamp
A timestamp, e.g. when data was recorded / has to be considered.
Definition: DataHeader.h:88


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58