Commit 32c8b501 authored by neverlord's avatar neverlord

atom tweaks

parent 129e05ad
...@@ -42,11 +42,11 @@ enum class atom_value : std::uint64_t { dirty_little_hack = 37337 }; ...@@ -42,11 +42,11 @@ enum class atom_value : std::uint64_t { dirty_little_hack = 37337 };
std::string to_string(atom_value const& a); std::string to_string(atom_value const& a);
template<size_t Size> template<size_t Size>
constexpr atom_value atom(const char (&str) [Size]) constexpr atom_value atom(char const (&str) [Size])
{ {
// last character is the NULL terminator // last character is the NULL terminator
static_assert(Size <= 11, "only 10 characters are allowed"); static_assert(Size <= 11, "only 10 characters are allowed");
return static_cast<atom_value>(detail::atom_val(str, 0)); return static_cast<atom_value>(detail::atom_val(str, 0xF));
} }
} // namespace cppa } // namespace cppa
......
...@@ -32,17 +32,27 @@ ...@@ -32,17 +32,27 @@
namespace cppa { namespace cppa {
std::string to_string(const atom_value& a) std::string to_string(atom_value const& what)
{ {
auto x = static_cast<std::uint64_t>(what);
std::string result; std::string result;
result.reserve(11); result.reserve(11);
for (auto x = static_cast<std::uint64_t>(a); x != 0; x >>= 6) // don't read characters before we found the leading 0xF
// first four bits set?
bool read_chars = ((x & 0xF000000000000000) >> 60) == 0xF;
std::uint64_t mask = 0x0FC0000000000000;
for (int bitshift = 54; bitshift >= 0; bitshift -= 6, mask >>= 6)
{ {
// decode 6 bit characters to ASCII if (read_chars)
result += detail::decoding_table[static_cast<size_t>(x & 0x3F)]; {
result += detail::decoding_table[(x & mask) >> bitshift];
}
else if (((x & mask) >> bitshift) == 0xF)
{
read_chars = true;
}
} }
// result is reversed, since we read from right-to-left return std::move(result);
return std::string(result.rbegin(), result.rend());
} }
} // namespace cppa } // namespace cppa
...@@ -33,7 +33,9 @@ size_t test__atom() ...@@ -33,7 +33,9 @@ size_t test__atom()
CPPA_TEST(test__atom); CPPA_TEST(test__atom);
CPPA_CHECK_NOT_EQUAL(atom("zzz"), atom("000 ")); CPPA_CHECK_NOT_EQUAL(atom("zzz"), atom("000 "));
CPPA_CHECK_EQUAL(atom(" "), atom("@!?")); CPPA_CHECK_EQUAL(atom(" "), atom("@!?"));
CPPA_CHECK_NOT_EQUAL(atom("abc"), atom(" abc"));
CPPA_CHECK_EQUAL(to_string(s_foo), "FooBar"); CPPA_CHECK_EQUAL(to_string(s_foo), "FooBar");
cout << to_string(s_foo) << endl;
self << make_tuple(atom("foo"), static_cast<std::uint32_t>(42)) self << make_tuple(atom("foo"), static_cast<std::uint32_t>(42))
<< make_tuple(atom(":Attach"), atom(":Baz"), "cstring") << make_tuple(atom(":Attach"), atom(":Baz"), "cstring")
<< make_tuple(atom("b"), atom("a"), atom("c"), 23.f) << make_tuple(atom("b"), atom("a"), atom("c"), 23.f)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment