summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-03-12 14:13:17 +0100
committerTor Egge <Tor.Egge@broadpark.no>2019-03-12 14:18:02 +0100
commit589ba257c6bc459e1882d78e3744f2f99b5074a6 (patch)
tree547549b05937a3891836e9ab72d0eede135561b2 /vespalib
parent5229f5f855342b20f9e5880abd6ff716a89ba406 (diff)
Use fundamental types in vespalib::asciistream operators.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/stllike/asciistream_test.cpp20
-rw-r--r--vespalib/src/vespa/vespalib/stllike/asciistream.cpp80
-rw-r--r--vespalib/src/vespa/vespalib/stllike/asciistream.h28
3 files changed, 74 insertions, 54 deletions
diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp
index 2c89bab75fa..1742b7244a6 100644
--- a/vespalib/src/tests/stllike/asciistream_test.cpp
+++ b/vespalib/src/tests/stllike/asciistream_test.cpp
@@ -69,33 +69,33 @@ AsciistreamTest::testIllegalNumbers()
{
asciistream is("777777777777");
uint16_t s(0);
- EXPECT_EXCEPTION(is >> s, IllegalArgumentException, "An uint16_t can not represent '777777777777'");
+ EXPECT_EXCEPTION(is >> s, IllegalArgumentException, "An unsigned short can not represent '777777777777'");
EXPECT_EQUAL(12u, is.size());
uint32_t i(0);
- EXPECT_EXCEPTION(is >> i, IllegalArgumentException, "An uint32_t can not represent '777777777777'");
+ EXPECT_EXCEPTION(is >> i, IllegalArgumentException, "An unsigned int can not represent '777777777777'");
EXPECT_EQUAL(12u, is.size());
int16_t si(0);
- EXPECT_EXCEPTION(is >> si, IllegalArgumentException, "An int16_t can not represent '777777777777'");
+ EXPECT_EXCEPTION(is >> si, IllegalArgumentException, "A short can not represent '777777777777'");
EXPECT_EQUAL(12u, is.size());
int32_t ii(0);
- EXPECT_EXCEPTION(is >> ii, IllegalArgumentException, "An int32_t can not represent '777777777777'");
+ EXPECT_EXCEPTION(is >> ii, IllegalArgumentException, "An int can not represent '777777777777'");
EXPECT_EQUAL(12u, is.size());
is << "777777777777";
EXPECT_EQUAL(24u, is.size());
uint64_t l(0);
- EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "uint64_t value is outside of range '777777777777777777777777'");
+ EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "value is outside of range '777777777777777777777777'");
EXPECT_EQUAL(24u, is.size());
int64_t li(0);
- EXPECT_EXCEPTION(is >> li, IllegalArgumentException, "int64_t value is outside of range '777777777777777777777777'");
+ EXPECT_EXCEPTION(is >> li, IllegalArgumentException, "value is outside of range '777777777777777777777777'");
EXPECT_EQUAL(24u, is.size());
}
{
asciistream is("-77");
uint16_t s(0);
- EXPECT_EXCEPTION(is >> s, IllegalArgumentException, "An uint16_t can not represent '-77'");
+ EXPECT_EXCEPTION(is >> s, IllegalArgumentException, "An unsigned short can not represent '-77'");
EXPECT_EQUAL(3u, is.size());
uint32_t i(0);
- EXPECT_EXCEPTION(is >> i, IllegalArgumentException, "An uint32_t can not represent '-77'");
+ EXPECT_EXCEPTION(is >> i, IllegalArgumentException, "An unsigned int can not represent '-77'");
EXPECT_EQUAL(3u, is.size());
}
{
@@ -128,12 +128,12 @@ AsciistreamTest::testIllegalNumbers()
EXPECT_TRUE(is.empty());
{
uint32_t l(0);
- EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "Failed decoding a uint64_t from ''.");
+ EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "Failed decoding a unsigned long long from ''.");
EXPECT_TRUE(is.empty());
}
{
int32_t l(0);
- EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "Failed decoding a int64_t from ''.");
+ EXPECT_EXCEPTION(is >> l, IllegalArgumentException, "Failed decoding a long long from ''.");
EXPECT_TRUE(is.empty());
}
{
diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
index 78c8f9a9bda..c141d35e80e 100644
--- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
+++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
@@ -144,8 +144,8 @@ namespace {
int getValue(double & val, const char *buf) __attribute__((noinline));
int getValue(float & val, const char *buf) __attribute__((noinline));
-int getValue(uint64_t & val, const char *buf) __attribute__((noinline));
-int getValue(int64_t & val, const char *buf) __attribute__((noinline));
+int getValue(unsigned long long & val, const char *buf) __attribute__((noinline));
+int getValue(long long & val, const char *buf) __attribute__((noinline));
void throwInputError(int e, const char * t, const char * buf) __attribute__((noinline));
void throwUnderflow(size_t pos) __attribute__((noinline));
@@ -189,24 +189,24 @@ int getValue(float & val, const char *buf)
return ebuf - buf;
}
-int getValue(uint64_t & val, const char *buf)
+int getValue(unsigned long long & val, const char *buf)
{
char *ebuf;
errno = 0;
- val = strtoul(buf, &ebuf, 0);
+ val = strtoull(buf, &ebuf, 0);
if ((errno != 0) || (buf == ebuf)) {
- throwInputError(errno, "uint64_t", buf);
+ throwInputError(errno, "unsigned long long", buf);
}
return ebuf - buf;
}
-int getValue(int64_t & val, const char *buf)
+int getValue(long long & val, const char *buf)
{
char *ebuf;
errno = 0;
- val = strtol(buf, &ebuf, 0);
+ val = strtoll(buf, &ebuf, 0);
if ((errno != 0) || (buf == ebuf)) {
- throwInputError(errno, "int64_t", buf);
+ throwInputError(errno, "long long", buf);
}
return ebuf - buf;
}
@@ -246,65 +246,81 @@ asciistream & asciistream::operator >> (unsigned char & v)
return *this;
}
-asciistream & asciistream::operator >> (uint16_t & v)
+asciistream & asciistream::operator >> (unsigned short & v)
{
- uint64_t l(0);
+ unsigned long long l(0);
size_t r = getValue(l, &_rbuf[_rPos]);
- if (l > std::numeric_limits<uint16_t>::max()) {
- throw IllegalArgumentException(make_string("An uint16_t can not represent '%ld'.", l), VESPA_STRLOC);
+ if (l > std::numeric_limits<unsigned short>::max()) {
+ throw IllegalArgumentException(make_string("An unsigned short can not represent '%lld'.", l), VESPA_STRLOC);
}
_rPos += r;
v = l;
return *this;
}
-asciistream & asciistream::operator >> (uint32_t & v)
+asciistream & asciistream::operator >> (unsigned int & v)
{
- uint64_t l(0);
+ unsigned long long l(0);
size_t r = getValue(l, &_rbuf[_rPos]);
- if (l > std::numeric_limits<uint32_t>::max()) {
- throw IllegalArgumentException(make_string("An uint32_t can not represent '%ld'.", l), VESPA_STRLOC);
+ if (l > std::numeric_limits<unsigned int>::max()) {
+ throw IllegalArgumentException(make_string("An unsigned int can not represent '%lld'.", l), VESPA_STRLOC);
}
_rPos += r;
v = l;
return *this;
}
-asciistream & asciistream::operator >> (uint64_t & v)
+asciistream & asciistream::operator >> (unsigned long & v)
{
- uint64_t l(0);
+ unsigned long long l(0);
_rPos += getValue(l, &_rbuf[_rPos]);
v = l;
return *this;
}
-asciistream & asciistream::operator >> (int16_t & v)
+asciistream & asciistream::operator >> (unsigned long long & v)
{
- int64_t l(0);
+ unsigned long long l(0);
+ _rPos += getValue(l, &_rbuf[_rPos]);
+ v = l;
+ return *this;
+}
+
+asciistream & asciistream::operator >> (short & v)
+{
+ long long l(0);
size_t r = getValue(l, &_rbuf[_rPos]);
- if ((l < std::numeric_limits<int16_t>::min()) || (l > std::numeric_limits<int16_t>::max())) {
- throw IllegalArgumentException(make_string("An int16_t can not represent '%ld'.", l), VESPA_STRLOC);
+ if ((l < std::numeric_limits<short>::min()) || (l > std::numeric_limits<short>::max())) {
+ throw IllegalArgumentException(make_string("A short can not represent '%lld'.", l), VESPA_STRLOC);
}
_rPos += r;
v = l;
return *this;
}
-asciistream & asciistream::operator >> (int32_t & v)
+asciistream & asciistream::operator >> (int & v)
{
- int64_t l(0);
+ long long l(0);
size_t r = getValue(l, &_rbuf[_rPos]);
- if ((l < std::numeric_limits<int32_t>::min()) || (l > std::numeric_limits<int32_t>::max())) {
- throw IllegalArgumentException(make_string("An int32_t can not represent '%ld'.", l), VESPA_STRLOC);
+ if ((l < std::numeric_limits<int>::min()) || (l > std::numeric_limits<int>::max())) {
+ throw IllegalArgumentException(make_string("An int can not represent '%lld'.", l), VESPA_STRLOC);
}
_rPos += r;
v = l;
return *this;
}
-asciistream & asciistream::operator >> (int64_t & v)
+asciistream & asciistream::operator >> (long & v)
+{
+ long long l(0);
+ _rPos += getValue(l, &_rbuf[_rPos]);
+ v = l;
+ return *this;
+}
+
+asciistream & asciistream::operator >> (long long & v)
{
- int64_t l(0);
+ long long l(0);
_rPos += getValue(l, &_rbuf[_rPos]);
v = l;
return *this;
@@ -378,10 +394,10 @@ char * prependSign(bool sign, char * tmp)
}
template <uint8_t base>
-uint8_t printInt(uint64_t r, char * tmp, uint8_t i) __attribute__((noinline));
+uint8_t printInt(unsigned long long r, char * tmp, uint8_t i) __attribute__((noinline));
template <uint8_t base>
-uint8_t printInt(uint64_t r, char * tmp, uint8_t i)
+uint8_t printInt(unsigned long long r, char * tmp, uint8_t i)
{
for(; r; i--, r/=base) {
uint8_t d = r%base;
@@ -393,7 +409,7 @@ uint8_t printInt(uint64_t r, char * tmp, uint8_t i)
}
-asciistream & asciistream::operator << (int64_t v)
+asciistream & asciistream::operator << (long long v)
{
char tmp[72];
uint8_t i(sizeof(tmp));
@@ -431,7 +447,7 @@ void asciistream::doReallyFill(size_t currWidth)
}
}
-asciistream & asciistream::operator << (uint64_t v)
+asciistream & asciistream::operator << (unsigned long long v)
{
char tmp[72];
uint8_t i(sizeof(tmp));
diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.h b/vespalib/src/vespa/vespalib/stllike/asciistream.h
index 428ed983e16..88c3e1f7fc8 100644
--- a/vespalib/src/vespa/vespalib/stllike/asciistream.h
+++ b/vespalib/src/vespa/vespalib/stllike/asciistream.h
@@ -45,13 +45,15 @@ public:
asciistream & operator << (const string & v) { doFill(v.size()); write(v.data(), v.size()); return *this; }
asciistream & operator << (stringref v) { doFill(v.size()); write(v.data(), v.size()); return *this; }
asciistream & operator << (const std::string & v) { doFill(v.size()); write(v.data(), v.size()); return *this; }
- asciistream & operator << (int16_t v) { return *this << static_cast<int64_t>(v); }
- asciistream & operator << (uint16_t v) { return *this << static_cast<uint64_t>(v); }
- asciistream & operator << (int32_t v) { return *this << static_cast<int64_t>(v); }
- asciistream & operator << (uint32_t v) { return *this << static_cast<uint64_t>(v); }
+ asciistream & operator << (short v) { return *this << static_cast<long long>(v); }
+ asciistream & operator << (unsigned short v) { return *this << static_cast<unsigned long long>(v); }
+ asciistream & operator << (int v) { return *this << static_cast<long long>(v); }
+ asciistream & operator << (unsigned int v) { return *this << static_cast<unsigned long long>(v); }
asciistream & operator << (const void* p);
- asciistream & operator << (int64_t v);
- asciistream & operator << (uint64_t v);
+ asciistream & operator << (long v) { return *this << static_cast<long long>(v); }
+ asciistream & operator << (unsigned long v) { return *this << static_cast<unsigned long long>(v); }
+ asciistream & operator << (long long v);
+ asciistream & operator << (unsigned long long v);
asciistream & operator << (float v);
asciistream & operator << (double v);
asciistream & operator << (Base v) { _base = v; return *this; }
@@ -65,12 +67,14 @@ public:
asciistream & operator >> (unsigned char & v);
asciistream & operator >> (std::string & v);
asciistream & operator >> (string & v);
- asciistream & operator >> (uint16_t & v);
- asciistream & operator >> (int16_t & v);
- asciistream & operator >> (int32_t & v);
- asciistream & operator >> (uint32_t & v);
- asciistream & operator >> (int64_t & v);
- asciistream & operator >> (uint64_t & v);
+ asciistream & operator >> (short & v);
+ asciistream & operator >> (unsigned short & v);
+ asciistream & operator >> (int & v);
+ asciistream & operator >> (unsigned int & v);
+ asciistream & operator >> (long & v);
+ asciistream & operator >> (unsigned long & v);
+ asciistream & operator >> (long long & v);
+ asciistream & operator >> (unsigned long long & v);
asciistream & operator >> (float & v);
asciistream & operator >> (double & v);
stringref str() const { return stringref(c_str(), size()); }