snark
timestamped.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_APPLICATIONS_TIMESTAMPEDPOSITION_H_
20 #define SNARK_APPLICATIONS_TIMESTAMPEDPOSITION_H_
21 
22 #include <snark/timing/time.h>
23 #include <comma/visiting/traits.h>
24 
25 namespace snark{ namespace applications {
26 
28 template < typename T, typename TimeType = boost::posix_time::ptime >
30 {
31  TimeType t;
32  T value;
33 };
34 
35 namespace detail {
36 
37 inline std::string toString( const boost::posix_time::ptime& t ) { return boost::posix_time::to_iso_string( t ); }
38 
39 } // namespace detail {
40 
41 } } // namespace snark{ namespace applications {
42 
43 template < typename T, typename S >
44 inline std::ostream& operator<<( std::ostream& os, const snark::applications::timestamped< T, S >& rhs ) { os << snark::applications::detail::toString( rhs.t ) << "," << rhs.value; return os; }
45 
46 namespace comma { namespace visiting {
47 
48 template < typename T, typename S > struct traits< snark::applications::timestamped< T, S > >
49 {
50  template < typename Key, class Visitor >
51  static void visit( Key, const snark::applications::timestamped< T, S >& p, Visitor& v )
52  {
53  v.apply( "t", p.t );
54  v.apply( "value", p.value );
55  }
56 
57  template < typename Key, class Visitor >
58  static void visit( Key, snark::applications::timestamped< T, S >& p, Visitor& v )
59  {
60  v.apply( "t", p.t );
61  v.apply( "value", p.value );
62  }
63 };
64 
65 } } // namespace comma { namespace visiting {
66 
67 #endif /*SNARK_APPLICATIONS_TIMESTAMPEDPOSITION_H_*/