1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/Exception.hpp" 4 #include "hmbdc/Compile.hpp" 14 namespace hmbdc {
namespace text {
15 struct TypedStringHash;
16 template <
char const NAME[], u
int16_t SIZE>
25 using rawType =
char[SIZE];
26 enum{capacity = SIZE,};
29 explicit TypedString(
char const* s,
size_t len = SIZE) {
31 #pragma GCC diagnostic push 32 #pragma GCC diagnostic ignored "-Wformat-truncation" 34 snprintf(v_, std::min((
size_t)SIZE, len + 1),
"%s", s);
37 snprintf(v_, SIZE,
"%s", s.c_str());
40 #pragma GCC diagnostic pop 42 static constexpr
char const* typeName() {
return NAME; }
43 char const* c_str()
const {
return v_; }
44 bool operator == (
ThisT const& other)
const {
45 return strncmp(v_, other.v_, SIZE) == 0;
47 bool operator != (
ThisT const& other)
const {
48 return strncmp(v_, other.v_, SIZE) != 0;
50 bool operator < (
ThisT const& other)
const {
51 return strncmp(v_, other.v_, SIZE) < 0;
54 std::ostream& operator << (std::ostream& os,
ThisT const& s) {
59 std::istream& operator >> (std::istream& is,
ThisT& s) {
66 void clear() { v_[0] = 0; }
69 return std::find(b, b + SIZE,
'\x00') - b;
72 size_t copyTo(
char* to)
const {
75 for (; p != to + capacity && *b;) {
85 template <
char const NAME[], u
int16_t SIZE>
86 struct hash<
hmbdc::text::TypedString<NAME, SIZE>> {
89 for(hash = i = 0; i < SIZE && x.v_[i]; ++i)
Definition: TypedString.hpp:84
Definition: TypedString.hpp:17