diff options
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/util/statebuf/statebuf_test.cpp | 12 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/util/statebuf.cpp | 28 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/util/statebuf.h | 6 |
3 files changed, 37 insertions, 9 deletions
diff --git a/searchlib/src/tests/util/statebuf/statebuf_test.cpp b/searchlib/src/tests/util/statebuf/statebuf_test.cpp index 61f1194bcb6..40abf942fa1 100644 --- a/searchlib/src/tests/util/statebuf/statebuf_test.cpp +++ b/searchlib/src/tests/util/statebuf/statebuf_test.cpp @@ -52,10 +52,16 @@ TEST_F("keys can be appended to stream", Fixture) } -TEST_F("integers can be appended to stream", Fixture) +TEST_F("positive integers can be appended to stream", Fixture) { - f << (UINT64_C(1) << 63) << " " << -42l << " " << 0l; - EXPECT_EQUAL("9223372036854775808 -42 0", f.str()); + f << (1ull << 63) << " " << 42l << " " << 21 << " " << 0; + EXPECT_EQUAL("9223372036854775808 42 21 0", f.str()); +} + +TEST_F("negative integers can be appended to stream", Fixture) +{ + f << (1ll << 63) << " " << -42l << " " << -21; + EXPECT_EQUAL("-9223372036854775808 -42 -21", f.str()); } TEST_F("struct timespec can be appended to stream", Fixture) diff --git a/searchlib/src/vespa/searchlib/util/statebuf.cpp b/searchlib/src/vespa/searchlib/util/statebuf.cpp index 12d18599a41..af1c7dda30d 100644 --- a/searchlib/src/vespa/searchlib/util/statebuf.cpp +++ b/searchlib/src/vespa/searchlib/util/statebuf.cpp @@ -72,7 +72,7 @@ StateBuf::appendKey(const char *s) noexcept StateBuf & -StateBuf::operator<<(unsigned long val) noexcept +StateBuf::operator<<(unsigned long long val) noexcept { char buf[22]; char *p = buf; @@ -92,21 +92,37 @@ StateBuf::operator<<(unsigned long val) noexcept StateBuf & -StateBuf::operator<<(long val) noexcept +StateBuf::operator<<(long long val) noexcept { if (val < 0) { - *this << '-' << static_cast<unsigned long>(- val); + *this << '-' << static_cast<unsigned long long>(- val); } else { - *this << static_cast<unsigned long>(val); + *this << static_cast<unsigned long long>(val); } return *this; } StateBuf & +StateBuf::operator<<(unsigned long val) noexcept +{ + *this << static_cast<unsigned long long>(val); + return *this; +} + + +StateBuf & +StateBuf::operator<<(long val) noexcept +{ + *this << static_cast<long long>(val); + return *this; +} + + +StateBuf & StateBuf::operator<<(unsigned int val) noexcept { - *this << static_cast<unsigned long>(val); + *this << static_cast<unsigned long long>(val); return *this; } @@ -114,7 +130,7 @@ StateBuf::operator<<(unsigned int val) noexcept StateBuf & StateBuf::operator<<(int val) noexcept { - *this << static_cast<long>(val); + *this << static_cast<long long>(val); return *this; } diff --git a/searchlib/src/vespa/searchlib/util/statebuf.h b/searchlib/src/vespa/searchlib/util/statebuf.h index 6f847e82c66..3dbf8beaf16 100644 --- a/searchlib/src/vespa/searchlib/util/statebuf.h +++ b/searchlib/src/vespa/searchlib/util/statebuf.h @@ -59,6 +59,12 @@ public: appendAddr(void *addr) noexcept; StateBuf & + operator<<(unsigned long long val) noexcept; + + StateBuf & + operator<<(long long val) noexcept; + + StateBuf & operator<<(unsigned long val) noexcept; StateBuf & |