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>
22 friend struct std::hash<TypedString<NAME, SIZE>>;
25 using rawType =
char[SIZE];
26 enum{capacity = SIZE,};
28 TypedString(){v_[0] = 0;}
29 explicit TypedString(
char const* s,
size_t len = SIZE) {
30 snprintf(v_, std::min((
size_t)SIZE, len),
"%s", s);
32 explicit TypedString(std::string
const& s) {
33 snprintf(v_, SIZE,
"%s", s.c_str());
36 static char const* typeName() {
return NAME; }
37 char const* c_str()
const {
return v_; }
38 bool operator == (
ThisT const& other)
const {
39 return strncmp(v_, other.v_, SIZE) == 0;
41 bool operator != (
ThisT const& other)
const {
42 return strncmp(v_, other.v_, SIZE) != 0;
44 bool operator < (
ThisT const& other)
const {
45 return strncmp(v_, other.v_, SIZE) < 0;
48 std::ostream& operator << (std::ostream& os,
ThisT const& s) {
53 std::istream& operator >> (std::istream& is,
ThisT& s) {
60 void clear() { v_[0] = 0; }
63 return std::find(b, b + SIZE,
'\x00') - b;
66 size_t copyTo(
char* to)
const {
69 for (; p != to + capacity && *b;) {
79 template <
char const NAME[], u
int16_t SIZE>
80 struct hash<
hmbdc::text::TypedString<NAME, SIZE>> {
83 for(hash = i = 0; i < SIZE && x.v_[i]; ++i)
Definition: TypedString.hpp:17