Skip to content

Commit

Permalink
Merge pull request #672 from cldellow/bug-671
Browse files Browse the repository at this point in the history
AttributePair: use uint, not char
  • Loading branch information
systemed authored Feb 10, 2024
2 parents 6e335ef + 6951cd7 commit c7fe91b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions include/attribute_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class AttributeKeyStore {
std::map<const std::string*, uint16_t, string_ptr_less_than> keys2index;
};

enum class AttributePairType: char { Bool = 0, Float = 1, String = 2 };
enum class AttributePairType: uint8_t { Bool = 0, Float = 1, String = 2 };
// AttributePair is a key/value pair (with minzoom)
#pragma pack(push, 1)
struct AttributePair {
short keyIndex : 9;
AttributePairType valueType : 3;
char minzoom : 4;
AttributePairType valueType : 2;
uint8_t minzoom : 5; // Support zooms from 0..31. In practice, we expect z16 to be the biggest minzoom.
union {
float floatValue_;
PooledString stringValue_;
Expand Down
6 changes: 4 additions & 2 deletions test/attribute_store.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ MU_TEST(test_attribute_store) {

AttributeSet s1;
store.addAttribute(s1, "str1", std::string("someval"), 0);
store.addAttribute(s1, "str2", std::string("a very long string"), 0);
store.addAttribute(s1, "str2", std::string("a very long string"), 14);
store.addAttribute(s1, "bool1", false, 0);
store.addAttribute(s1, "bool2", true, 0);
store.addAttribute(s1, "float1", (float)42.0, 0);
store.addAttribute(s1, "float1", (float)42.0, 4);

const auto s1Index = store.add(s1);

Expand All @@ -35,6 +35,7 @@ MU_TEST(test_attribute_store) {
mu_check(str2 != s1Pairs.end());
mu_check((*str2)->hasStringValue());
mu_check((*str2)->stringValue() == "a very long string");
mu_check((*str2)->minzoom == 14);

const auto bool1 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
return ap->keyIndex == store.keyStore.key2index("bool1");
Expand All @@ -56,6 +57,7 @@ MU_TEST(test_attribute_store) {
mu_check(float1 != s1Pairs.end());
mu_check((*float1)->hasFloatValue());
mu_check((*float1)->floatValue() == 42);
mu_check((*float1)->minzoom == 4);
}

MU_TEST(test_attribute_store_reuses) {
Expand Down

0 comments on commit c7fe91b

Please sign in to comment.