diff options
author | Michi Henning <michi@zeroc.com> | 2002-07-08 23:32:45 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2002-07-08 23:32:45 +0000 |
commit | 88579ad4eb268f08fd6d6383899a4c7a8ac1cb83 (patch) | |
tree | 183a51911661ac13b85a4f0295f124377af0d677 /cpp | |
parent | Use istringstream >> operator instead of atoi and check for errors where (diff) | |
download | ice-88579ad4eb268f08fd6d6383899a4c7a8ac1cb83.tar.bz2 ice-88579ad4eb268f08fd6d6383899a4c7a8ac1cb83.tar.xz ice-88579ad4eb268f08fd6d6383899a4c7a8ac1cb83.zip |
Style fixes: Changed INT64MIN and INT64MAX to Int64Min and Int64Max.
Moved the definitions of Int64, Int64Min, and Int64Max into
IceUtil/Config.h.
Updated scanner and parser to use the new constant names. Also applied
style fixes to parser: INT16MIN -> Int16Min, BYTEMIN -> ByteMin, etc.
Changed Time.h and Time.cpp to use the Int64 type from IceUtil/Config.h.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/IceUtil/Config.h | 13 | ||||
-rw-r--r-- | cpp/include/IceUtil/InputUtil.h | 12 | ||||
-rw-r--r-- | cpp/include/IceUtil/Time.h | 10 | ||||
-rw-r--r-- | cpp/include/Slice/Parser.h | 16 | ||||
-rw-r--r-- | cpp/src/IceUtil/Time.cpp | 12 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Slice/Scanner.l | 2 | ||||
-rw-r--r-- | cpp/test/IceUtil/inputUtil/Client.cpp | 14 |
8 files changed, 40 insertions, 45 deletions
diff --git a/cpp/include/IceUtil/Config.h b/cpp/include/IceUtil/Config.h index 1250469e08a..6f14abcf7ff 100644 --- a/cpp/include/IceUtil/Config.h +++ b/cpp/include/IceUtil/Config.h @@ -119,6 +119,19 @@ private: noncopyable(const noncopyable&); const noncopyable& operator=(const noncopyable&); }; +// +// +// Some definitions for 64-bit integers +// +#if defined(_WIN32) + typedef __int64 Int64; + const Int64 Int64Min = -9223372036854775808i64; + const Int64 Int64Max = 9223372036854775807i64; +#elif defined(__linux__) && defined(i386) + typedef long long Int64; + const Int64 Int64Min = LONGLONG_MIN; + const Int64 Int64Max = LONGLONG_MAX; +#endif } diff --git a/cpp/include/IceUtil/InputUtil.h b/cpp/include/IceUtil/InputUtil.h index 442206c2e5f..f38888780d2 100644 --- a/cpp/include/IceUtil/InputUtil.h +++ b/cpp/include/IceUtil/InputUtil.h @@ -18,18 +18,6 @@ namespace IceUtil { -#if defined(_WIN32) - typedef __int64 Int64; - const Int64 INT64MIN = -9223372036854775808i64; - const Int64 INT64MAX = 9223372036854775807i64; -#elif defined(__linux__) && defined(i386) - typedef long long Int64; - const Int64 INT64MIN = LONGLONG_MIN; - const Int64 INT64MAX = LONGLONG_MAX; -#else -# error "Unsupported operating system or platform!" -#endif - // // strToInt64() is drop-in replacement for UNIX strtoll() // diff --git a/cpp/include/IceUtil/Time.h b/cpp/include/IceUtil/Time.h index cd58ecd4ae0..1e711984f5a 100644 --- a/cpp/include/IceUtil/Time.h +++ b/cpp/include/IceUtil/Time.h @@ -53,15 +53,9 @@ public: private: -#ifdef _WIN32 -typedef __int64 LongLong; -#else -typedef long long LongLong; -#endif - - Time(LongLong); + Time(Int64); - LongLong _usec; + Int64 _usec; }; } // End namespace IceUtil diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index 18b9ab58a27..d238a01ef06 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -36,20 +36,20 @@ namespace Slice #if defined(_WIN32) typedef double Double; - const IceUtil::Int64 INT32MAX = 0x7fffffffi64; - const IceUtil::Int64 INT32MIN = -INT32MAX - 1i64; + const IceUtil::Int64 Int32Max = 0x7fffffffi64; + const IceUtil::Int64 Int32Min = -Int32Max - 1i64; #elif(__linux__) && defined(i386) typedef double Double; - const IceUtil::Int64 INT32MAX = 0x7fffffffLL; - const IceUtil::Int64 INT32MIN = -INT32MAX - 1LL; + const IceUtil::Int64 Int32Max = 0x7fffffffLL; + const IceUtil::Int64 Int32Min = -Int32Max - 1LL; #else # error "Unsupported operating system or platform!" #endif -const IceUtil::Int64 INT16MAX = 0x7fff; -const IceUtil::Int64 INT16MIN = -INT16MAX - 1; -const IceUtil::Int64 BYTEMAX = 0xff; -const IceUtil::Int64 BYTEMIN = 0x00; +const IceUtil::Int64 Int16Max = 0x7fff; +const IceUtil::Int64 Int16Min = -Int16Max - 1; +const IceUtil::Int64 ByteMax = 0xff; +const IceUtil::Int64 ByteMin = 0x00; class GrammarBase; class SyntaxTreeBase; diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp index d52916af3be..125051b71d0 100644 --- a/cpp/src/IceUtil/Time.cpp +++ b/cpp/src/IceUtil/Time.cpp @@ -29,28 +29,28 @@ IceUtil::Time::now() #ifdef WIN32 struct _timeb tb; _ftime(&tb); - return Time(tb.time * static_cast<LongLong>(1000000) + tb.millitm * static_cast<LongLong>(1000)); + return Time(tb.time * static_cast<Int64>(1000000) + tb.millitm * static_cast<Int64>(1000)); #else struct timeval tv; gettimeofday(&tv, 0); - return Time(tv.tv_sec * static_cast<LongLong>(1000000) + tv.tv_usec); + return Time(tv.tv_sec * static_cast<Int64>(1000000) + tv.tv_usec); #endif } Time IceUtil::Time::seconds(long t) { - return Time(t * static_cast<LongLong>(1000000)); + return Time(t * static_cast<Int64>(1000000)); } Time IceUtil::Time::milliSeconds(long t) { - return Time(t * static_cast<LongLong>(1000)); + return Time(t * static_cast<Int64>(1000)); } Time -IceUtil::Time::microSeconds(LongLong t) +IceUtil::Time::microSeconds(Int64 t) { return Time(t); } @@ -136,7 +136,7 @@ IceUtil::Time::operator double() const return _usec / 1000000.0L; } -Time::Time(LongLong usec) : +Time::Time(Int64 usec) : _usec(usec) { } diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 206a2c0b486..ed00a9e2b48 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1595,7 +1595,7 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const case Builtin::KindByte: { IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); - if(l < BYTEMIN || l > BYTEMAX) + if(l < ByteMin || l > ByteMax) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type byte"; _unit->error(msg); @@ -1606,7 +1606,7 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const case Builtin::KindShort: { IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); - if(l < INT16MIN || l > INT16MAX) + if(l < Int16Min || l > Int16Max) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type short"; _unit->error(msg); @@ -1617,7 +1617,7 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const case Builtin::KindInt: { IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); - if(l < INT32MIN || l > INT32MAX) + if(l < Int32Min || l > Int32Max) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type int"; _unit->error(msg); diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index c92ea37b5ec..4a5cb2cfdcb 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -303,7 +303,7 @@ floating_literal (({fractional_constant}{exponent_part}?)|([[:digit:]]+{exponent *yylvalp = itp; errno = 0; itp->v = IceUtil::strToInt64(yytext, 0, 0); - if(errno == ERANGE && (itp->v == IceUtil::INT64MIN || itp->v == IceUtil::INT64MAX)) + if(errno == ERANGE && (itp->v == IceUtil::Int64Min || itp->v == IceUtil::Int64Max)) { string msg = "integer constant `"; msg += yytext; diff --git a/cpp/test/IceUtil/inputUtil/Client.cpp b/cpp/test/IceUtil/inputUtil/Client.cpp index 40a5a09a5a9..7e5f19ed155 100644 --- a/cpp/test/IceUtil/inputUtil/Client.cpp +++ b/cpp/test/IceUtil/inputUtil/Client.cpp @@ -76,26 +76,26 @@ main(int, char**) b = stringToInt64("-9223372036854775807", result, pos); test(b && result == -9223372036854775807 && pos == string::npos); b = stringToInt64("-9223372036854775808", result, pos); - test(b && result == INT64MIN && pos == string::npos); + test(b && result == Int64Min && pos == string::npos); b = stringToInt64("-9223372036854775809", result, pos); - test(!b && result == INT64MIN && pos == string::npos); + test(!b && result == Int64Min && pos == string::npos); b = stringToInt64("9223372036854775806", result, pos); test(b && result == 9223372036854775806 && pos == string::npos); b = stringToInt64("9223372036854775807", result, pos); - test(b && result == INT64MAX && pos == string::npos); + test(b && result == Int64Max && pos == string::npos); b = stringToInt64("9223372036854775808", result, pos); - test(!b && result == INT64MAX && pos == string::npos); + test(!b && result == Int64Max && pos == string::npos); b = stringToInt64("-9223372036854775807Q", result, pos); test(b && result == -9223372036854775807 && pos == 20); b = stringToInt64("-9223372036854775808Q", result, pos); - test(b && result == INT64MIN && pos == 20); + test(b && result == Int64Min && pos == 20); b = stringToInt64("-9223372036854775809Q", result, pos); - test(!b && result == INT64MIN && pos == 20); + test(!b && result == Int64Min && pos == 20); b = stringToInt64("-9223372036854775809999Q", result, pos); - test(!b && result == INT64MIN && pos == 23); + test(!b && result == Int64Min && pos == 23); cout << "ok" << endl; |