diff options
Diffstat (limited to 'src/google/protobuf/stubs/common.h')
-rw-r--r-- | src/google/protobuf/stubs/common.h | 129 |
1 files changed, 29 insertions, 100 deletions
diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index f096fa9..551ee4a 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// http://code.google.com/p/protobuf/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -48,43 +48,13 @@ #include <stdint.h> #endif -#ifndef PROTOBUF_USE_EXCEPTIONS -#if defined(_MSC_VER) && defined(_CPPUNWIND) - #define PROTOBUF_USE_EXCEPTIONS 1 -#elif defined(__EXCEPTIONS) - #define PROTOBUF_USE_EXCEPTIONS 1 -#else - #define PROTOBUF_USE_EXCEPTIONS 0 -#endif -#endif - -#if PROTOBUF_USE_EXCEPTIONS -#include <exception> -#endif - -#if defined(_WIN32) && defined(GetMessage) -// Allow GetMessage to be used as a valid method name in protobuf classes. -// windows.h defines GetMessage() as a macro. Let's re-define it as an inline -// function. The inline function should be equivalent for C++ users. -inline BOOL GetMessage_Win32( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#undef GetMessage -inline BOOL GetMessage( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#endif - - namespace std {} namespace google { namespace protobuf { +using namespace std; // Don't do this at home, kids. + #undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS #define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ TypeName(const TypeName&); \ @@ -113,24 +83,24 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 2006001 +#define GOOGLE_PROTOBUF_VERSION 2003000 // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2006000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2003000 // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 2006000; +static const int kMinHeaderVersionForLibrary = 2003000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2006000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2003000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 2006000; +static const int kMinHeaderVersionForProtoc = 2003000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. @@ -138,7 +108,7 @@ void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, const char* filename); // Converts a numeric version number to a string. -std::string LIBPROTOBUF_EXPORT VersionString(int version); +string LIBPROTOBUF_EXPORT VersionString(int version); } // namespace internal @@ -381,7 +351,6 @@ struct CompileAssert { typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \ msg[bool(expr) ? 1 : -1] - // Implementation details of COMPILE_ASSERT: // // - COMPILE_ASSERT works by defining an array type that has -1 @@ -649,7 +618,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogMessage(LogLevel level, const char* filename, int line); ~LogMessage(); - LogMessage& operator<<(const std::string& value); + LogMessage& operator<<(const string& value); LogMessage& operator<<(const char* value); LogMessage& operator<<(char value); LogMessage& operator<<(int value); @@ -665,7 +634,7 @@ class LIBPROTOBUF_EXPORT LogMessage { LogLevel level_; const char* filename_; int line_; - std::string message_; + string message_; }; // Used to make the entire "LOG(BLAH) << etc." expression have a void return @@ -685,14 +654,12 @@ class LIBPROTOBUF_EXPORT LogFinisher { #undef GOOGLE_LOG_IF #undef GOOGLE_CHECK -#undef GOOGLE_CHECK_OK #undef GOOGLE_CHECK_EQ #undef GOOGLE_CHECK_NE #undef GOOGLE_CHECK_LT #undef GOOGLE_CHECK_LE #undef GOOGLE_CHECK_GT #undef GOOGLE_CHECK_GE -#undef GOOGLE_CHECK_NOTNULL #undef GOOGLE_DLOG #undef GOOGLE_DCHECK @@ -712,7 +679,6 @@ class LIBPROTOBUF_EXPORT LogFinisher { #define GOOGLE_CHECK(EXPRESSION) \ GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": " -#define GOOGLE_CHECK_OK(A) GOOGLE_CHECK(A) #define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B)) #define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B)) #define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B)) @@ -720,19 +686,6 @@ class LIBPROTOBUF_EXPORT LogFinisher { #define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B)) #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) -namespace internal { -template<typename T> -T* CheckNotNull(const char* /* file */, int /* line */, - const char* name, T* val) { - if (val == NULL) { - GOOGLE_LOG(FATAL) << name; - } - return val; -} -} // namespace internal -#define GOOGLE_CHECK_NOTNULL(A) \ - internal::CheckNotNull(__FILE__, __LINE__, "'" #A "' must not be NULL", (A)) - #ifdef NDEBUG #define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false) @@ -760,7 +713,7 @@ T* CheckNotNull(const char* /* file */, int /* line */, #endif // !NDEBUG typedef void LogHandler(LogLevel level, const char* filename, int line, - const std::string& message); + const string& message); // The protobuf library sometimes writes warning and error messages to // stderr. These messages are primarily useful for developers, but may @@ -872,9 +825,8 @@ class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure { ~FunctionClosure0(); void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes function_(); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -892,9 +844,8 @@ class MethodClosure0 : public Closure { ~MethodClosure0() {} void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -915,9 +866,8 @@ class FunctionClosure1 : public Closure { ~FunctionClosure1() {} void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes function_(arg1_); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -938,9 +888,8 @@ class MethodClosure1 : public Closure { ~MethodClosure1() {} void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(arg1_); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -962,9 +911,8 @@ class FunctionClosure2 : public Closure { ~FunctionClosure2() {} void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes function_(arg1_, arg2_); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -986,9 +934,8 @@ class MethodClosure2 : public Closure { ~MethodClosure2() {} void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes (object_->*method_)(arg1_, arg2_); - if (needs_delete) delete this; + if (self_deleting_) delete this; } private: @@ -1157,10 +1104,20 @@ using internal::WriterMutexLock; using internal::MutexLockMaybe; // =================================================================== -// from google3/util/utf8/public/unilib.h +// from google3/base/type_traits.h namespace internal { +// Specified by TR1 [4.7.4] Pointer modifications. +template<typename T> struct remove_pointer { typedef T type; }; +template<typename T> struct remove_pointer<T*> { typedef T type; }; +template<typename T> struct remove_pointer<T* const> { typedef T type; }; +template<typename T> struct remove_pointer<T* volatile> { typedef T type; }; +template<typename T> struct remove_pointer<T* const volatile> { + typedef T type; }; + +// =================================================================== + // Checks if the buffer contains structurally-valid UTF-8. Implemented in // structurally_valid.cc. LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); @@ -1168,10 +1125,6 @@ LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); } // namespace internal // =================================================================== -// from google3/util/endian/endian.h -LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x); - -// =================================================================== // Shutdown support. // Shut down the entire protocol buffers library, deleting all static-duration @@ -1196,30 +1149,6 @@ LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); } // namespace internal -#if PROTOBUF_USE_EXCEPTIONS -class FatalException : public std::exception { - public: - FatalException(const char* filename, int line, const std::string& message) - : filename_(filename), line_(line), message_(message) {} - virtual ~FatalException() throw(); - - virtual const char* what() const throw(); - - const char* filename() const { return filename_; } - int line() const { return line_; } - const std::string& message() const { return message_; } - - private: - const char* filename_; - const int line_; - const std::string message_; -}; -#endif - -// This is at the end of the file instead of the beginning to work around a bug -// in some versions of MSVC. -using namespace std; // Don't do this at home, kids. - } // namespace protobuf } // namespace google |