1 #ifndef jb_itch5_short_string_field_hpp 2 #define jb_itch5_short_string_field_hpp 8 #include <boost/functional/hash.hpp> 9 #include <boost/operators.hpp> 37 std::size_t wire_size_value,
38 typename value_validator = noop_validator<char const*>>
40 :
public boost::less_than_comparable<
41 short_string_field<wire_size_value, value_validator>>,
42 public boost::less_than_comparable<
43 short_string_field<wire_size_value, value_validator>, char const*>,
44 public boost::equality_comparable<
45 short_string_field<wire_size_value, value_validator>>,
46 public boost::equality_comparable<
47 short_string_field<wire_size_value, value_validator>, char const*> {
50 constexpr
static std::size_t
wire_size = wire_size_value;
67 std::string
const& rhs,
96 return std::strncmp(
buffer_, rhs, buffer_size) == 0;
101 return std::strncmp(
buffer_, rhs, buffer_size) == 0;
118 std::memcpy(
buffer_, buf, wire_size);
132 char* p = std::strchr(
buffer_, u
' ');
159 template <
bool val
idate, std::
size_t wsize,
typename F>
163 r(std::size_t
size,
void const* buffer, std::size_t offset) {
164 jb::itch5::check_offset<validate>(
165 "short_string_field<>",
size, offset, wsize);
168 tmp.
assign(static_cast<char const*>(buffer) + offset);
177 template <std::
size_t size,
typename F>
179 operator<<(std::ostream& os, short_string_field<size, F>
const& x) {
180 return os << x.c_str();
184 template <std::
size_t size,
typename F>
192 #endif // jb_itch5_short_string_field_hpp bool operator<(short_string_field const &rhs) const
compare vs another short_string_field
bool operator<(char const *rhs) const
compare vs a C string
char const * c_str() const
Return the C-string representation.
bool operator==(short_string_field const &rhs) const
compare vs another short_string_field
short_string_field(value_validator_t const &validator=value_validator_t())
Constructor.
void raise_validation_failed(char const *where, char const *what)
Convenience function to raise an exception upon a validation error.
static constexpr std::size_t wire_size
The size of the field on the wire.
value_validator_t value_validator_
The validator.
short_string_field(std::string const &rhs, value_validator_t const &validator=value_validator_t())
Constructor from a std::string.
static short_string_field< wsize, F > r(std::size_t size, void const *buffer, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
std::size_t hash_value(short_string_field< size, F > const &x)
Implement a hash function and integrate with boost::hash.
bool operator==(char const *rhs) const
compare vs a C string
void assign(char const *buf)
Assignment from a character buffer.
static constexpr std::size_t buffer_size
The size of the field in memory.
Define the interface to decode ITCH-5.0 messages and message fields.
char buffer_[buffer_size]
The in-memory representation.
void validate() const
Validate the value using the functor.
short_string_field & operator=(short_string_field const &rhs)=default
value_validator value_validator_t
The type of validator.
A helper type to define short (and fixed sized) string fields.
void nul_terminate()
NUL terminate the string.
constexpr std::uint64_t p2ceil(std::uint64_t n)
Find the smallest power of 2 larger than n for a 64-bit integer.
The top-level namespace for the JayBeams library.