Falaise  4.0.1
SuperNEMO Software Toolkit
timestamp.h
Go to the documentation of this file.
1 // -*- mode: c++ ; -*-
2 /// \file falaise/snemo/datamodels/timestamp.h
3 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
4  * Creation date: 2010-03-15
5  * Last modified: 2014-01-27
6  *
7  * License:
8  *
9  * Description:
10  *
11  * High resolution timestamp
12  *
13  * History:
14  *
15  */
16 
17 #ifndef FALAISE_SNEMO_DATAMODELS_TIMESTAMP_H
18 #define FALAISE_SNEMO_DATAMODELS_TIMESTAMP_H 1
19 
20 // Third party:
21 // - Boost:
22 #include <boost/cstdint.hpp>
23 #include <boost/serialization/access.hpp>
24 // - Bayeux/datatools :
26 
27 namespace snemo {
28 
29 namespace datamodel {
30 
31 /// \brief A class to handle time stamp
33  public:
34  static const int64_t INVALID_SECONDS;
35  static const int64_t INVALID_PICOSECONDS;
36  static const char IO_FORMAT_OPEN;
37  static const char IO_FORMAT_SEP;
38  static const char IO_FORMAT_CLOSE;
39  static const char IO_FORMAT_INVALID;
40 
41  /// Return the number of seconds
42  int64_t get_seconds() const;
43 
44  /// Set the number of seconds
45  void set_seconds(int64_t);
46 
47  /// Return the number of picoseconds
48  int64_t get_picoseconds() const;
49 
50  /// Set the number of picoseconds
51  void set_picoseconds(int64_t);
52 
53  /// Constructor
54  timestamp();
55 
56  /// Overloaded constructor
57  timestamp(int64_t sec_, int64_t picosec_);
58 
59  /// Destructor
60  virtual ~timestamp();
61 
62  /// Check if the timestamp object is valid
63  bool is_valid() const;
64 
65  /// Invalidate the timestamp object
66  void invalidate();
67 
68  /// Compare with another timestamp
69  int compare(const timestamp &) const;
70 
71  /// Convert timestamp to real value (explicit time unit)
72  double to_real() const;
73 
74  /// Format time stamp as string object and return it
75  std::string to_string() const;
76 
77  /// Format time stamp as string object and return it as reference
78  void to_string(std::string &) const;
79 
80  /// Parse time from string object and set the timestamp object accordingly
81  void from_string(const std::string &);
82 
83  friend bool operator==(const timestamp &, const timestamp &);
84  friend bool operator<(const timestamp &, const timestamp &);
85  friend bool operator>(const timestamp &, const timestamp &);
86  friend bool operator<=(const timestamp &, const timestamp &);
87  friend bool operator>=(const timestamp &, const timestamp &);
88  friend std::ostream &operator<<(std::ostream &, const timestamp &);
89  friend std::istream &operator>>(std::istream &, timestamp &);
90 
91  private:
92  int64_t _seconds_; //!< Number of seconds
93  int64_t _picoseconds_; //!< Number of picoseconds
94 
96 };
97 
98 } // end of namespace datamodel
99 
100 } // end of namespace snemo
101 
102 #include <boost/serialization/version.hpp>
103 BOOST_CLASS_VERSION(snemo::datamodel::timestamp, 1)
104 
105 #endif // FALAISE_SNEMO_DATAMODELS_TIMESTAMP_H
int compare(const timestamp &) const
Compare with another timestamp.
static const char IO_FORMAT_INVALID
Definition: timestamp.h:39
friend std::istream & operator>>(std::istream &, timestamp &)
static const char IO_FORMAT_SEP
Definition: timestamp.h:37
friend bool operator>(const timestamp &, const timestamp &)
virtual ~timestamp()
Destructor.
static const int64_t INVALID_PICOSECONDS
Definition: timestamp.h:35
void set_picoseconds(int64_t)
Set the number of picoseconds.
static const char IO_FORMAT_OPEN
Definition: timestamp.h:36
friend bool operator>=(const timestamp &, const timestamp &)
#define DATATOOLS_SERIALIZATION_DECLARATION()
A class to handle time stamp.
Definition: timestamp.h:32
friend bool operator==(const timestamp &, const timestamp &)
int64_t get_picoseconds() const
Return the number of picoseconds.
std::string to_string() const
Format time stamp as string object and return it.
int64_t get_seconds() const
Return the number of seconds.
static const int64_t INVALID_SECONDS
Definition: timestamp.h:34
Definition: calo_tapered_scin_box_model.h:54
friend std::ostream & operator<<(std::ostream &, const timestamp &)
friend bool operator<(const timestamp &, const timestamp &)
bool is_valid() const
Check if the timestamp object is valid.
void from_string(const std::string &)
Parse time from string object and set the timestamp object accordingly.
static const char IO_FORMAT_CLOSE
Definition: timestamp.h:38
void invalidate()
Invalidate the timestamp object.
friend bool operator<=(const timestamp &, const timestamp &)
double to_real() const
Convert timestamp to real value (explicit time unit)
void set_seconds(int64_t)
Set the number of seconds.