1 #ifndef jb_fixed_string_hpp 2 #define jb_fixed_string_hpp 4 #include <boost/functional/hash.hpp> 5 #include <boost/operators.hpp> 10 #include <type_traits> 31 template <std::
size_t wire_size_value>
33 :
public boost::totally_ordered<fixed_string<wire_size_value>>,
34 public boost::totally_ordered<
35 fixed_string<wire_size_value>, std::string> {
38 constexpr
static std::size_t
wire_size = wire_size_value;
47 "fixed_string must be a PODType.");
49 std::strncpy(
buffer_, rhs.c_str(), std::min(wire_size, rhs.length()));
55 std::strncpy(
buffer_, rhs.c_str(), std::min(wire_size, rhs.length()));
60 std::string
str()
const {
61 return std::string(
buffer_, wire_size);
103 template <std::
size_t size>
104 std::ostream& operator<<(std::ostream& os, fixed_string<size>
const& x) {
105 return os << x.str();
109 template <std::
size_t size>
112 return boost::hash_range(tmp.begin(), tmp.end());
116 template <std::
size_t size>
121 #endif // jb_fixed_string_hpp fixed_string & operator=(std::string const &rhs)
Assingment from std::string.
A helper type to define short (and fixed sized) string fields.
bool operator<(fixed_string const &rhs) const
compare vs another fixed_string
bool operator<(std::string const &rhs) const
compare vs a std::string
std::size_t hash_value(fixed_string< size > const &x)
Implement a hash function and integrate with boost::hash.
fixed_string(std::string const &rhs)
Constructor from a std::string.
char buffer_[wire_size]
The in-memory representation.
fixed_string()=default
Default constructor.
bool operator==(fixed_string const &rhs) const
compare vs another fixed_string
std::string str() const
Return a representation as a std::string.
static constexpr std::size_t wire_size
The size of the field on the wire.
bool operator==(std::string const &rhs) const
compare vs a std::string
The top-level namespace for the JayBeams library.