1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/Exception.hpp" 12 namespace hmbdc {
namespace text {
13 struct TypedStringHash;
14 template <
char const NAME[], u
int16_t SIZE>
20 friend struct std::hash<TypedString<NAME, SIZE>>;
23 using rawType =
char[SIZE];
24 enum{capacity = SIZE,};
26 TypedString(){v_[0] = 0;}
27 explicit TypedString(
char const* s,
size_t len = SIZE) {strncpy(v_, s, SIZE);}
28 explicit TypedString(std::string
const& s) {strncpy(v_, s.c_str(), SIZE);}
29 static char const* typeName() {
return NAME; }
30 char const* c_str()
const {
return v_; }
31 bool operator == (
ThisT const& other)
const {
32 return strncmp(v_, other.v_, SIZE) == 0;
34 bool operator != (
ThisT const& other)
const {
35 return strncmp(v_, other.v_, SIZE) != 0;
37 bool operator < (
ThisT const& other)
const {
38 return strncmp(v_, other.v_, SIZE) < 0;
41 std::ostream& operator << (std::ostream& os,
ThisT const& s) {
43 strncpy(tmp, s.v_, SIZE);
49 std::istream& operator >> (std::istream& is,
ThisT& s) {
52 strncpy(s.v_, tmp.c_str(), SIZE);
56 void clear() { v_[0] = 0; }
59 return std::find(b, b + SIZE,
'\x00') - b;
62 size_t copyTo(
char* to)
const {
65 for (; p != to + capacity && *b;) {
75 template <
char const NAME[], u
int16_t SIZE>
76 struct hash<
hmbdc::text::TypedString<NAME, SIZE>> {
79 for(hash = i = 0; i < SIZE && x.v_[i]; ++i)
Definition: TypedString.hpp:74
Definition: TypedString.hpp:15