snark
stream_traits.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_SENSORS_VELODYNE_IMPL_STREAMTRAITS_H_
20 #define SNARK_SENSORS_VELODYNE_IMPL_STREAMTRAITS_H_
21 
22 #include <boost/date_time/posix_time/posix_time.hpp>
23 #include "./pcap_reader.h"
24 #include "./proprietary_reader.h"
25 
26 namespace snark { namespace velodyne { namespace impl {
27 
28 template < typename S >
29 struct stream_traits
30 {
31  //static const char* read( S& s, std::size_t size ) { return s.read( size ); }
32  static const char* read( S& s, std::size_t size ) { return s.read(); }
33 
34  //static boost::posix_time::ptime timestamp( const S& ) { return boost::posix_time::microsec_clock::local_time(); }
35  static boost::posix_time::ptime timestamp( const S& s ) { return s.timestamp(); }
36 
37  static void close( S& s ) { s.close(); }
38 };
39 
40 template <>
41 struct stream_traits< proprietary_reader >
42 {
43  static const char* read( proprietary_reader& s, std::size_t ) { return s.read(); }
44 
45  static boost::posix_time::ptime timestamp( const proprietary_reader& s ) { return s.timestamp(); }
46 
47  static void close( proprietary_reader& s ) { s.close(); }
48 };
49 
50 template <>
51 struct stream_traits< pcap_reader >
52 {
53  static const char* read( pcap_reader& s, std::size_t size )
54  {
55  const char* r = s.read();
56  if( r == NULL ) { return NULL; }
57  return r + 42; // skip UDP header
58  }
59 
60  static boost::posix_time::ptime timestamp( const pcap_reader& s ) { return s.timestamp(); }
61 
62  static void close( pcap_reader& s ) { s.close(); }
63 };
64 
65 } } } // namespace snark { namespace velodyne { namespace impl {
66 
67 #endif // SNARK_SENSORS_VELODYNE_IMPL_STREAMTRAITS_H_