DataHeader.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00036 //----------------------------------------------------------------------
00037 #ifndef ICL_CORE_DATA_HEADER_H_INCLUDED
00038 #define ICL_CORE_DATA_HEADER_H_INCLUDED
00039 
00040 #include <string>
00041 #include <boost/shared_ptr.hpp>
00042 #include <boost/date_time.hpp>
00043 #include <boost/version.hpp>
00044 #if (BOOST_VERSION >= 104800)
00045 # include <boost/type_traits/has_left_shift.hpp>
00046 #endif
00047 #include <icl_core/ImportExport.h>
00048 #include <icl_core/BaseTypes.h>
00049 
00050 #ifdef _IC_BUILDER_EIGEN_
00051 #include <Eigen/Core>
00052 #endif
00053 
00054 namespace icl_core {
00055 
00061 struct DataHeader
00062 {
00066   DataHeader()
00067     : coordinate_system(),
00068       timestamp(),
00069       sequence_number(0)
00070   { }
00071 
00073   DataHeader(const std::string& coordinate_system,
00074              const boost::posix_time::ptime& timestamp,
00075              uint32_t sequence_number = 0)
00076     : coordinate_system(coordinate_system),
00077       timestamp(timestamp),
00078       sequence_number(sequence_number)
00079   { }
00080 
00082   ~DataHeader()
00083   { }
00084 
00086   std::string coordinate_system;
00088   boost::posix_time::ptime timestamp;
00090   uint32_t sequence_number;
00096   std::size_t dsin;
00097 };
00098 
00099 
00103 struct StampedBase
00104 {
00106   typedef boost::shared_ptr<StampedBase> Ptr;
00107   typedef boost::shared_ptr<const StampedBase> ConstPtr;
00108 
00110   StampedBase()
00111   {}
00112 
00113   virtual ~StampedBase()
00114   {}
00115 
00119   virtual void print(std::ostream& os) const = 0;
00120 
00122   virtual DataHeader& header() = 0;
00124   virtual const DataHeader& header() const = 0;
00125 };
00126 
00127 namespace internal {
00128 
00136 template <typename T, bool has_left_shift>
00137 struct ToStream;
00138 
00139 template <typename T>
00140 struct ToStream<T, false>
00141 {
00142   static std::ostream& print(std::ostream& os, const T& obj)
00143   {
00144     return os << sizeof(T) << " data bytes";
00145   }
00146 };
00147 
00148 template <typename T>
00149 struct ToStream<T, true>
00150 {
00151   static std::ostream& print(std::ostream& os, const T& obj)
00152   {
00153     return os << obj;
00154   }
00155 };
00156 
00157 }
00158 
00162 template <class DataType>
00163 struct Stamped : public StampedBase
00164 {
00165 private:
00166   // IMPORTANT: Do not change the order (data -> header) as it is
00167   // important for memory alignment!
00168 
00170   DataType m_data;
00172   DataHeader m_header;
00173 
00174 public:
00175   /* If we build against Eigen it is possible that the DataType depends on
00176    * Eigen. Then the Stamped should be aligned.
00177    */
00178 #ifdef _IC_BUILDER_EIGEN_
00179   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00180 #endif
00181 
00183   typedef boost::shared_ptr<Stamped<DataType> > Ptr;
00185   typedef boost::shared_ptr<const Stamped<DataType> > ConstPtr;
00186 
00188   Stamped()
00189     : m_header()
00190   { }
00191 
00193   Stamped(const DataType& data)
00194     : m_data(data),
00195       m_header()
00196   { }
00197 
00199   Stamped(const DataHeader& header)
00200     : m_header(header)
00201   { }
00202 
00204   Stamped(const DataType& data, const DataHeader& header)
00205     : m_data(data),
00206       m_header(header)
00207   { }
00208 
00210   inline operator DataType () const { return m_data; }
00211 
00213   virtual DataHeader& header() { return m_header; }
00215   virtual const DataHeader& header() const  { return m_header; }
00216 
00220   inline DataType& get() { return m_data; }
00224   inline const DataType& get() const { return m_data; }
00229   inline const DataType& cget() const { return m_data; }
00230 
00232   inline DataType& operator * () { return m_data; }
00234   inline const DataType& operator * () const { return m_data; }
00235 
00237   inline DataType *operator -> () { return &m_data; }
00239   inline const DataType *operator -> () const { return &m_data; }
00240 
00262   virtual void print(std::ostream& os) const
00263   {
00264     os << "[seq: " << this->m_header.sequence_number
00265        << ", timestamp: " << boost::posix_time::to_simple_string(this->m_header.timestamp)
00266        << ", DSIN: " << this->m_header.dsin
00267        << ", Frame: " << m_header.coordinate_system
00268        << "; ";
00269 #if (BOOST_VERSION >= 104800)
00270     internal::ToStream<DataType, boost::has_left_shift<std::ostream, DataType>::value>::print(os, m_data);
00271 #else
00272     // Boost versions prior to 1.48 do not have the has_left_shift
00273     // type trait.
00274     internal::ToStream<DataType, false>::print(os, m_data);
00275 #endif
00276     os << "]";
00277   }
00278 };
00279 
00284 ICL_CORE_IMPORT_EXPORT std::ostream& operator << (std::ostream& os, StampedBase const& stamped);
00285 
00286 }
00287 
00288 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03