1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/Exception.hpp" 11 namespace hmbdc {
namespace text {
12 struct TypedStringHash;
13 template <
char const NAME[], u
int16_t SIZE>
19 friend struct std::hash<TypedString<NAME, SIZE>>;
22 using rawType =
char[SIZE];
23 enum{capacity = SIZE,};
25 TypedString(){v_[0] = 0;}
26 explicit TypedString(
char const* s,
size_t len = SIZE) {strncpy(v_, s, SIZE);}
27 explicit TypedString(std::string
const& s) {strncpy(v_, s.c_str(), SIZE);}
28 static char const* typeName() {
return NAME; }
29 char const* c_str()
const {
return v_; }
30 bool operator == (
ThisT const& other)
const {
31 return strncmp(v_, other.v_, SIZE) == 0;
33 bool operator != (
ThisT const& other)
const {
34 return strncmp(v_, other.v_, SIZE) != 0;
36 bool operator < (
ThisT const& other)
const {
37 return strncmp(v_, other.v_, SIZE) < 0;
40 std::ostream& operator << (std::ostream& os,
ThisT const& s) {
42 strncpy(tmp, s.v_, SIZE);
48 std::istream& operator >> (std::istream& is,
ThisT& s) {
51 strncpy(s.v_, tmp.c_str(), SIZE - 1);
52 if (tmp.size() >= SIZE) {
53 s.v_[SIZE - 1] = tmp[SIZE-1];
58 void clear() { v_[0] = 0; }
61 return std::find(b, b + SIZE,
'\x00') - b;
64 size_t copyTo(
char* to)
const {
67 for (; p != to + capacity && *b;) {
77 template <
char const NAME[], u
int16_t SIZE>
78 struct hash<
hmbdc::text::TypedString<NAME, SIZE>> {
81 for(hash = i = 0; i < SIZE && x.v_[i]; ++i)
Definition: TypedString.hpp:76
Definition: TypedString.hpp:14