if (gmx_debug_at)
{
-#if BITMASK_SIZE <= 64 //move into bitmask when it is C++
- std::string flags = gmx::formatString("%" PRIx64, *mask);
-#else
- std::string flags = gmx::formatAndJoin(*mask,
- "", gmx::StringFormatter("%x"));
-#endif
fprintf(debug, "block %d flags %s count %d\n",
- b, flags.c_str(), c);
+ b, to_hex_string(*mask).c_str(), c);
}
}
}
#include <string.h>
+#include <algorithm>
#include <array>
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/stringutil.h"
/*! \brief Size of bitmask. Has to be 32 or multiple of 64. */
#ifndef BITMASK_SIZE
}
}
#endif
+//In bitmask.h because only current use is for bitmask.
+
+//! Convert uint32_t to hex string
+inline static std::string to_hex_string(uint32_t m)
+{
+ return gmx::formatString("%08" PRIx32, m);
+}
+//! Convert uint64_t to hex string
+inline static std::string to_hex_string(uint64_t m)
+{
+ return gmx::formatString("%016" PRIx64, m);
+}
+//! Convert container of intergers to hex string
+template <typename C>
+inline static std::string to_hex_string(C m)
+{
+ std::string ret;
+ for (auto it = m.rbegin(); it < m.rend(); ++it)
+ {
+ ret += to_hex_string(*it);
+ }
+ return ret;
+}
#endif
bitmask_union(&m1, m2);
EXPECT_TRUE(bitmask_is_equal(m1, m2));
}
+BITMASK_TEST_P(ToHex) //NOLINT(misc-definitions-in-headers)
+{
+ gmx_bitmask_t m;
+ bitmask_clear(&m);
+ bitmask_set_bit(&m, BITMASK_SIZE-1);
+ EXPECT_EQ(to_hex_string(m), "8" + std::string(BITMASK_SIZE/4-1, '0'));
+}