JayBeams  0.1
Another project to have fun coding.
seconds_field.hpp
Go to the documentation of this file.
1 #ifndef jb_itch5_seconds_field_hpp
2 #define jb_itch5_seconds_field_hpp
3 
5 #include <chrono>
6 #include <iosfwd>
7 
8 namespace jb {
9 namespace itch5 {
10 
11 /**
12  * Represent a ITCH-5.0 seconds_field
13  *
14  * ITCH-5.0 uses seconds since midnight for some of its fields.
15  */
17 public:
18  /// Constructor
19  explicit seconds_field(int c = 0)
20  : count_(c) {
21  }
22 
23  /// Constructor from std::chrono::seconds
24  explicit seconds_field(std::chrono::seconds const& s)
25  : count_(s.count()) {
26  }
27 
28  //@{
29  /**
30  * @name Accessors
31  */
32  int int_seconds() const {
33  return count_;
34  }
35 
36  std::chrono::seconds seconds() const {
37  return std::chrono::seconds(count_);
38  }
39  //@}
40 
41 private:
42  int count_;
43 };
44 
45 /**
46  * Validate the a seconds_field value.
47  *
48  * In ITCH-5.0 messages the seconds_field represents nanoseconds since
49  * midnight. The protocol is designed to start new sessions at the
50  * beginning of each day, so seconds_fields cannot ever be more than 24
51  * hours in nanoseconds.
52  *
53  * @tparam validate unless it is true the function is a no-op.
54  *
55  * @throws std::runtime_error if @a tparam is true and the seconds_field
56  * is out of the expected range.
57  */
58 template <bool validate>
60 }
61 
62 /**
63  * Provide an active implementation of
64  * jb::itch5::check_seconds_field_range<>
65  */
66 template <>
68 
69 /// Specialize jb::itch5::decoder<> for a seconds_field
70 template <bool validate>
71 struct decoder<validate, seconds_field> {
72  /// Please see the generic documentation for jb::itch5::decoder<>::r()
73  static seconds_field
74  r(std::size_t size, void const* buf, std::size_t offset) {
75  std::uint64_t ts = decoder<validate, std::uint32_t>::r(size, buf, offset);
76  seconds_field tmp(ts);
77  check_seconds_field_range<validate>(tmp);
78 
79  return tmp;
80  }
81 };
82 
83 /// Streaming operator for jb::itch5::seconds_field.
84 std::ostream& operator<<(std::ostream& os, seconds_field const& x);
85 
86 } // namespace itch5
87 } // namespace jb
88 
89 #endif // jb_itch5_seconds_field_hpp
seconds_field(int c=0)
Constructor.
static T r(std::size_t size, void const *msg, std::size_t offset)
Read a single message or field.
Represent a ITCH-5.0 seconds_field.
void check_seconds_field_range< true >(seconds_field const &t)
Provide an active implementation of jb::itch5::check_seconds_field_range<>
Define the interface to decode ITCH-5.0 messages and message fields.
Definition: decoder.hpp:24
std::chrono::seconds seconds() const
static seconds_field r(std::size_t size, void const *buf, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
std::ostream & operator<<(std::ostream &os, add_order_message const &x)
Streaming operator for jb::itch5::add_order_message.
void check_seconds_field_range(seconds_field const &t)
Validate the a seconds_field value.
seconds_field(std::chrono::seconds const &s)
Constructor from std::chrono::seconds.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7