LCOV - code coverage report
Current view: top level - toolkit/components/protobuf/src/google/protobuf/stubs - common.h (source / functions) Hit Total Coverage
Test: output.info Lines: 11 65 16.9 %
Date: 2017-07-14 16:53:18 Functions: 6 164 3.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Protocol Buffers - Google's data interchange format
       2             : // Copyright 2008 Google Inc.  All rights reserved.
       3             : // https://developers.google.com/protocol-buffers/
       4             : //
       5             : // Redistribution and use in source and binary forms, with or without
       6             : // modification, are permitted provided that the following conditions are
       7             : // met:
       8             : //
       9             : //     * Redistributions of source code must retain the above copyright
      10             : // notice, this list of conditions and the following disclaimer.
      11             : //     * Redistributions in binary form must reproduce the above
      12             : // copyright notice, this list of conditions and the following disclaimer
      13             : // in the documentation and/or other materials provided with the
      14             : // distribution.
      15             : //     * Neither the name of Google Inc. nor the names of its
      16             : // contributors may be used to endorse or promote products derived from
      17             : // this software without specific prior written permission.
      18             : //
      19             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      20             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      21             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      22             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      23             : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      24             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      25             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      29             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30             : 
      31             : // Author: kenton@google.com (Kenton Varda) and others
      32             : //
      33             : // Contains basic types and utilities used by the rest of the library.
      34             : 
      35             : #ifndef GOOGLE_PROTOBUF_COMMON_H__
      36             : #define GOOGLE_PROTOBUF_COMMON_H__
      37             : 
      38             : #include <assert.h>
      39             : #include <stdlib.h>
      40             : #include <cstddef>
      41             : #include <string>
      42             : #include <string.h>
      43             : #if defined(__osf__)
      44             : // Tru64 lacks stdint.h, but has inttypes.h which defines a superset of
      45             : // what stdint.h would define.
      46             : #include <inttypes.h>
      47             : #elif !defined(_MSC_VER)
      48             : #include <stdint.h>
      49             : #endif
      50             : 
      51             : #ifndef PROTOBUF_USE_EXCEPTIONS
      52             : #if defined(_MSC_VER) && defined(_CPPUNWIND)
      53             :   #define PROTOBUF_USE_EXCEPTIONS 1
      54             : #elif defined(__EXCEPTIONS)
      55             :   #define PROTOBUF_USE_EXCEPTIONS 1
      56             : #else
      57             :   #define PROTOBUF_USE_EXCEPTIONS 0
      58             : #endif
      59             : #endif
      60             : 
      61             : #if PROTOBUF_USE_EXCEPTIONS
      62             : #include <exception>
      63             : #endif
      64             : 
      65             : #if defined(_WIN32) && defined(GetMessage)
      66             : // Allow GetMessage to be used as a valid method name in protobuf classes.
      67             : // windows.h defines GetMessage() as a macro.  Let's re-define it as an inline
      68             : // function.  The inline function should be equivalent for C++ users.
      69             : inline BOOL GetMessage_Win32(
      70             :     LPMSG lpMsg, HWND hWnd,
      71             :     UINT wMsgFilterMin, UINT wMsgFilterMax) {
      72             :   return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
      73             : }
      74             : #undef GetMessage
      75             : inline BOOL GetMessage(
      76             :     LPMSG lpMsg, HWND hWnd,
      77             :     UINT wMsgFilterMin, UINT wMsgFilterMax) {
      78             :   return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
      79             : }
      80             : #endif
      81             : 
      82             : 
      83             : namespace std {}
      84             : 
      85             : namespace google {
      86             : namespace protobuf {
      87             : 
      88             : #undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
      89             : #define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)    \
      90             :   TypeName(const TypeName&);                           \
      91             :   void operator=(const TypeName&)
      92             : 
      93             : #if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
      94             :   #ifdef LIBPROTOBUF_EXPORTS
      95             :     #define LIBPROTOBUF_EXPORT __declspec(dllexport)
      96             :   #else
      97             :     #define LIBPROTOBUF_EXPORT __declspec(dllimport)
      98             :   #endif
      99             :   #ifdef LIBPROTOC_EXPORTS
     100             :     #define LIBPROTOC_EXPORT   __declspec(dllexport)
     101             :   #else
     102             :     #define LIBPROTOC_EXPORT   __declspec(dllimport)
     103             :   #endif
     104             : #else
     105             :   #define LIBPROTOBUF_EXPORT
     106             :   #define LIBPROTOC_EXPORT
     107             : #endif
     108             : 
     109             : namespace internal {
     110             : 
     111             : // Some of these constants are macros rather than const ints so that they can
     112             : // be used in #if directives.
     113             : 
     114             : // The current version, represented as a single integer to make comparison
     115             : // easier:  major * 10^6 + minor * 10^3 + micro
     116             : #define GOOGLE_PROTOBUF_VERSION 2006001
     117             : 
     118             : // The minimum library version which works with the current version of the
     119             : // headers.
     120             : #define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2006000
     121             : 
     122             : // The minimum header version which works with the current version of
     123             : // the library.  This constant should only be used by protoc's C++ code
     124             : // generator.
     125             : static const int kMinHeaderVersionForLibrary = 2006000;
     126             : 
     127             : // The minimum protoc version which works with the current version of the
     128             : // headers.
     129             : #define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2006000
     130             : 
     131             : // The minimum header version which works with the current version of
     132             : // protoc.  This constant should only be used in VerifyVersion().
     133             : static const int kMinHeaderVersionForProtoc = 2006000;
     134             : 
     135             : // Verifies that the headers and libraries are compatible.  Use the macro
     136             : // below to call this.
     137             : void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
     138             :                                       const char* filename);
     139             : 
     140             : // Converts a numeric version number to a string.
     141             : std::string LIBPROTOBUF_EXPORT VersionString(int version);
     142             : 
     143             : }  // namespace internal
     144             : 
     145             : // Place this macro in your main() function (or somewhere before you attempt
     146             : // to use the protobuf library) to verify that the version you link against
     147             : // matches the headers you compiled against.  If a version mismatch is
     148             : // detected, the process will abort.
     149             : #define GOOGLE_PROTOBUF_VERIFY_VERSION                                    \
     150             :   ::google::protobuf::internal::VerifyVersion(                            \
     151             :     GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION,         \
     152             :     __FILE__)
     153             : 
     154             : // ===================================================================
     155             : // from google3/base/port.h
     156             : 
     157             : typedef unsigned int uint;
     158             : 
     159             : #ifdef _MSC_VER
     160             : typedef __int8  int8;
     161             : typedef __int16 int16;
     162             : typedef __int32 int32;
     163             : typedef __int64 int64;
     164             : 
     165             : typedef unsigned __int8  uint8;
     166             : typedef unsigned __int16 uint16;
     167             : typedef unsigned __int32 uint32;
     168             : typedef unsigned __int64 uint64;
     169             : #else
     170             : typedef int8_t  int8;
     171             : typedef int16_t int16;
     172             : typedef int32_t int32;
     173             : typedef int64_t int64;
     174             : 
     175             : typedef uint8_t  uint8;
     176             : typedef uint16_t uint16;
     177             : typedef uint32_t uint32;
     178             : typedef uint64_t uint64;
     179             : #endif
     180             : 
     181             : // long long macros to be used because gcc and vc++ use different suffixes,
     182             : // and different size specifiers in format strings
     183             : #undef GOOGLE_LONGLONG
     184             : #undef GOOGLE_ULONGLONG
     185             : #undef GOOGLE_LL_FORMAT
     186             : 
     187             : #ifdef _MSC_VER
     188             : #define GOOGLE_LONGLONG(x) x##I64
     189             : #define GOOGLE_ULONGLONG(x) x##UI64
     190             : #define GOOGLE_LL_FORMAT "I64"  // As in printf("%I64d", ...)
     191             : #else
     192             : #define GOOGLE_LONGLONG(x) x##LL
     193             : #define GOOGLE_ULONGLONG(x) x##ULL
     194             : #define GOOGLE_LL_FORMAT "ll"  // As in "%lld". Note that "q" is poor form also.
     195             : #endif
     196             : 
     197             : static const int32 kint32max = 0x7FFFFFFF;
     198             : static const int32 kint32min = -kint32max - 1;
     199             : static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF);
     200             : static const int64 kint64min = -kint64max - 1;
     201             : static const uint32 kuint32max = 0xFFFFFFFFu;
     202             : static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF);
     203             : 
     204             : // -------------------------------------------------------------------
     205             : // Annotations:  Some parts of the code have been annotated in ways that might
     206             : //   be useful to some compilers or tools, but are not supported universally.
     207             : //   You can #define these annotations yourself if the default implementation
     208             : //   is not right for you.
     209             : 
     210             : #ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE
     211             : #if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
     212             : // For functions we want to force inline.
     213             : // Introduced in gcc 3.1.
     214             : #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
     215             : #else
     216             : // Other compilers will have to figure it out for themselves.
     217             : #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE
     218             : #endif
     219             : #endif
     220             : 
     221             : #ifndef GOOGLE_ATTRIBUTE_DEPRECATED
     222             : #ifdef __GNUC__
     223             : // If the method/variable/type is used anywhere, produce a warning.
     224             : #define GOOGLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
     225             : #else
     226             : #define GOOGLE_ATTRIBUTE_DEPRECATED
     227             : #endif
     228             : #endif
     229             : 
     230             : #ifndef GOOGLE_PREDICT_TRUE
     231             : #ifdef __GNUC__
     232             : // Provided at least since GCC 3.0.
     233             : #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
     234             : #else
     235             : #define GOOGLE_PREDICT_TRUE
     236             : #endif
     237             : #endif
     238             : 
     239             : // Delimits a block of code which may write to memory which is simultaneously
     240             : // written by other threads, but which has been determined to be thread-safe
     241             : // (e.g. because it is an idempotent write).
     242             : #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
     243             : #define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN()
     244             : #endif
     245             : #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END
     246             : #define GOOGLE_SAFE_CONCURRENT_WRITES_END()
     247             : #endif
     248             : 
     249             : // ===================================================================
     250             : // from google3/base/basictypes.h
     251             : 
     252             : // The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr.
     253             : // The expression is a compile-time constant, and therefore can be
     254             : // used in defining new arrays, for example.
     255             : //
     256             : // GOOGLE_ARRAYSIZE catches a few type errors.  If you see a compiler error
     257             : //
     258             : //   "warning: division by zero in ..."
     259             : //
     260             : // when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer.
     261             : // You should only use GOOGLE_ARRAYSIZE on statically allocated arrays.
     262             : //
     263             : // The following comments are on the implementation details, and can
     264             : // be ignored by the users.
     265             : //
     266             : // ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in
     267             : // the array) and sizeof(*(arr)) (the # of bytes in one array
     268             : // element).  If the former is divisible by the latter, perhaps arr is
     269             : // indeed an array, in which case the division result is the # of
     270             : // elements in the array.  Otherwise, arr cannot possibly be an array,
     271             : // and we generate a compiler error to prevent the code from
     272             : // compiling.
     273             : //
     274             : // Since the size of bool is implementation-defined, we need to cast
     275             : // !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
     276             : // result has type size_t.
     277             : //
     278             : // This macro is not perfect as it wrongfully accepts certain
     279             : // pointers, namely where the pointer size is divisible by the pointee
     280             : // size.  Since all our code has to go through a 32-bit compiler,
     281             : // where a pointer is 4 bytes, this means all pointers to a type whose
     282             : // size is 3 or greater than 4 will be (righteously) rejected.
     283             : //
     284             : // Kudos to Jorg Brown for this simple and elegant implementation.
     285             : 
     286             : #undef GOOGLE_ARRAYSIZE
     287             : #define GOOGLE_ARRAYSIZE(a) \
     288             :   ((sizeof(a) / sizeof(*(a))) / \
     289             :    static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
     290             : 
     291             : namespace internal {
     292             : 
     293             : // Use implicit_cast as a safe version of static_cast or const_cast
     294             : // for upcasting in the type hierarchy (i.e. casting a pointer to Foo
     295             : // to a pointer to SuperclassOfFoo or casting a pointer to Foo to
     296             : // a const pointer to Foo).
     297             : // When you use implicit_cast, the compiler checks that the cast is safe.
     298             : // Such explicit implicit_casts are necessary in surprisingly many
     299             : // situations where C++ demands an exact type match instead of an
     300             : // argument type convertable to a target type.
     301             : //
     302             : // The From type can be inferred, so the preferred syntax for using
     303             : // implicit_cast is the same as for static_cast etc.:
     304             : //
     305             : //   implicit_cast<ToType>(expr)
     306             : //
     307             : // implicit_cast would have been part of the C++ standard library,
     308             : // but the proposal was submitted too late.  It will probably make
     309             : // its way into the language in the future.
     310             : template<typename To, typename From>
     311           0 : inline To implicit_cast(From const &f) {
     312           0 :   return f;
     313             : }
     314             : 
     315             : // When you upcast (that is, cast a pointer from type Foo to type
     316             : // SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
     317             : // always succeed.  When you downcast (that is, cast a pointer from
     318             : // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
     319             : // how do you know the pointer is really of type SubclassOfFoo?  It
     320             : // could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,
     321             : // when you downcast, you should use this macro.  In debug mode, we
     322             : // use dynamic_cast<> to double-check the downcast is legal (we die
     323             : // if it's not).  In normal mode, we do the efficient static_cast<>
     324             : // instead.  Thus, it's important to test in debug mode to make sure
     325             : // the cast is legal!
     326             : //    This is the only place in the code we should use dynamic_cast<>.
     327             : // In particular, you SHOULDN'T be using dynamic_cast<> in order to
     328             : // do RTTI (eg code like this:
     329             : //    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
     330             : //    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
     331             : // You should design the code some other way not to need this.
     332             : 
     333             : template<typename To, typename From>     // use like this: down_cast<T*>(foo);
     334           0 : inline To down_cast(From* f) {                   // so we only accept pointers
     335             :   // Ensures that To is a sub-type of From *.  This test is here only
     336             :   // for compile-time type checking, and has no overhead in an
     337             :   // optimized build at run-time, as it will be optimized away
     338             :   // completely.
     339             :   if (false) {
     340             :     implicit_cast<From*, To>(0);
     341             :   }
     342             : 
     343             : #if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI)
     344             :   assert(f == NULL || dynamic_cast<To>(f) != NULL);  // RTTI: debug mode only!
     345             : #endif
     346           0 :   return static_cast<To>(f);
     347             : }
     348             : 
     349             : }  // namespace internal
     350             : 
     351             : // We made these internal so that they would show up as such in the docs,
     352             : // but we don't want to stick "internal::" in front of them everywhere.
     353             : using internal::implicit_cast;
     354             : using internal::down_cast;
     355             : 
     356             : // The COMPILE_ASSERT macro can be used to verify that a compile time
     357             : // expression is true. For example, you could use it to verify the
     358             : // size of a static array:
     359             : //
     360             : //   COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
     361             : //                  content_type_names_incorrect_size);
     362             : //
     363             : // or to make sure a struct is smaller than a certain size:
     364             : //
     365             : //   COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large);
     366             : //
     367             : // The second argument to the macro is the name of the variable. If
     368             : // the expression is false, most compilers will issue a warning/error
     369             : // containing the name of the variable.
     370             : 
     371             : #define GOOGLE_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
     372             : 
     373             : 
     374             : 
     375             : // ===================================================================
     376             : // from google3/base/scoped_ptr.h
     377             : 
     378             : namespace internal {
     379             : 
     380             : //  This is an implementation designed to match the anticipated future TR2
     381             : //  implementation of the scoped_ptr class, and its closely-related brethren,
     382             : //  scoped_array, scoped_ptr_malloc, and make_scoped_ptr.
     383             : 
     384             : template <class C> class scoped_ptr;
     385             : template <class C> class scoped_array;
     386             : 
     387             : // A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T>
     388             : // automatically deletes the pointer it holds (if any).
     389             : // That is, scoped_ptr<T> owns the T object that it points to.
     390             : // Like a T*, a scoped_ptr<T> may hold either NULL or a pointer to a T object.
     391             : //
     392             : // The size of a scoped_ptr is small:
     393             : // sizeof(scoped_ptr<C>) == sizeof(C*)
     394             : template <class C>
     395             : class scoped_ptr {
     396             :  public:
     397             : 
     398             :   // The element type
     399             :   typedef C element_type;
     400             : 
     401             :   // Constructor.  Defaults to intializing with NULL.
     402             :   // There is no way to create an uninitialized scoped_ptr.
     403             :   // The input parameter must be allocated with new.
     404           3 :   explicit scoped_ptr(C* p = NULL) : ptr_(p) { }
     405             : 
     406             :   // Destructor.  If there is a C object, delete it.
     407             :   // We don't need to test ptr_ == NULL because C++ does that for us.
     408           0 :   ~scoped_ptr() {
     409             :     enum { type_must_be_complete = sizeof(C) };
     410           0 :     delete ptr_;
     411           0 :   }
     412             : 
     413             :   // Reset.  Deletes the current owned object, if any.
     414             :   // Then takes ownership of a new object, if given.
     415             :   // this->reset(this->get()) works.
     416           0 :   void reset(C* p = NULL) {
     417           0 :     if (p != ptr_) {
     418             :       enum { type_must_be_complete = sizeof(C) };
     419           0 :       delete ptr_;
     420           0 :       ptr_ = p;
     421             :     }
     422           0 :   }
     423             : 
     424             :   // Accessors to get the owned object.
     425             :   // operator* and operator-> will assert() if there is no current object.
     426           0 :   C& operator*() const {
     427           0 :     assert(ptr_ != NULL);
     428           0 :     return *ptr_;
     429             :   }
     430           0 :   C* operator->() const  {
     431           0 :     assert(ptr_ != NULL);
     432           0 :     return ptr_;
     433             :   }
     434           0 :   C* get() const { return ptr_; }
     435             : 
     436             :   // Comparison operators.
     437             :   // These return whether two scoped_ptr refer to the same object, not just to
     438             :   // two different but equal objects.
     439             :   bool operator==(C* p) const { return ptr_ == p; }
     440             :   bool operator!=(C* p) const { return ptr_ != p; }
     441             : 
     442             :   // Swap two scoped pointers.
     443             :   void swap(scoped_ptr& p2) {
     444             :     C* tmp = ptr_;
     445             :     ptr_ = p2.ptr_;
     446             :     p2.ptr_ = tmp;
     447             :   }
     448             : 
     449             :   // Release a pointer.
     450             :   // The return value is the current pointer held by this object.
     451             :   // If this object holds a NULL pointer, the return value is NULL.
     452             :   // After this operation, this object will hold a NULL pointer,
     453             :   // and will not own the object any more.
     454           0 :   C* release() {
     455           0 :     C* retVal = ptr_;
     456           0 :     ptr_ = NULL;
     457           0 :     return retVal;
     458             :   }
     459             : 
     460             :  private:
     461             :   C* ptr_;
     462             : 
     463             :   // Forbid comparison of scoped_ptr types.  If C2 != C, it totally doesn't
     464             :   // make sense, and if C2 == C, it still doesn't make sense because you should
     465             :   // never have the same object owned by two different scoped_ptrs.
     466             :   template <class C2> bool operator==(scoped_ptr<C2> const& p2) const;
     467             :   template <class C2> bool operator!=(scoped_ptr<C2> const& p2) const;
     468             : 
     469             :   // Disallow evil constructors
     470             :   scoped_ptr(const scoped_ptr&);
     471             :   void operator=(const scoped_ptr&);
     472             : };
     473             : 
     474             : // scoped_array<C> is like scoped_ptr<C>, except that the caller must allocate
     475             : // with new [] and the destructor deletes objects with delete [].
     476             : //
     477             : // As with scoped_ptr<C>, a scoped_array<C> either points to an object
     478             : // or is NULL.  A scoped_array<C> owns the object that it points to.
     479             : //
     480             : // Size: sizeof(scoped_array<C>) == sizeof(C*)
     481             : template <class C>
     482             : class scoped_array {
     483             :  public:
     484             : 
     485             :   // The element type
     486             :   typedef C element_type;
     487             : 
     488             :   // Constructor.  Defaults to intializing with NULL.
     489             :   // There is no way to create an uninitialized scoped_array.
     490             :   // The input parameter must be allocated with new [].
     491           0 :   explicit scoped_array(C* p = NULL) : array_(p) { }
     492             : 
     493             :   // Destructor.  If there is a C object, delete it.
     494             :   // We don't need to test ptr_ == NULL because C++ does that for us.
     495           0 :   ~scoped_array() {
     496             :     enum { type_must_be_complete = sizeof(C) };
     497           0 :     delete[] array_;
     498           0 :   }
     499             : 
     500             :   // Reset.  Deletes the current owned object, if any.
     501             :   // Then takes ownership of a new object, if given.
     502             :   // this->reset(this->get()) works.
     503           0 :   void reset(C* p = NULL) {
     504           0 :     if (p != array_) {
     505             :       enum { type_must_be_complete = sizeof(C) };
     506           0 :       delete[] array_;
     507           0 :       array_ = p;
     508             :     }
     509           0 :   }
     510             : 
     511             :   // Get one element of the current object.
     512             :   // Will assert() if there is no current object, or index i is negative.
     513           0 :   C& operator[](std::ptrdiff_t i) const {
     514           0 :     assert(i >= 0);
     515           0 :     assert(array_ != NULL);
     516           0 :     return array_[i];
     517             :   }
     518             : 
     519             :   // Get a pointer to the zeroth element of the current object.
     520             :   // If there is no current object, return NULL.
     521           0 :   C* get() const {
     522           0 :     return array_;
     523             :   }
     524             : 
     525             :   // Comparison operators.
     526             :   // These return whether two scoped_array refer to the same object, not just to
     527             :   // two different but equal objects.
     528           0 :   bool operator==(C* p) const { return array_ == p; }
     529             :   bool operator!=(C* p) const { return array_ != p; }
     530             : 
     531             :   // Swap two scoped arrays.
     532             :   void swap(scoped_array& p2) {
     533             :     C* tmp = array_;
     534             :     array_ = p2.array_;
     535             :     p2.array_ = tmp;
     536             :   }
     537             : 
     538             :   // Release an array.
     539             :   // The return value is the current pointer held by this object.
     540             :   // If this object holds a NULL pointer, the return value is NULL.
     541             :   // After this operation, this object will hold a NULL pointer,
     542             :   // and will not own the object any more.
     543             :   C* release() {
     544             :     C* retVal = array_;
     545             :     array_ = NULL;
     546             :     return retVal;
     547             :   }
     548             : 
     549             :  private:
     550             :   C* array_;
     551             : 
     552             :   // Forbid comparison of different scoped_array types.
     553             :   template <class C2> bool operator==(scoped_array<C2> const& p2) const;
     554             :   template <class C2> bool operator!=(scoped_array<C2> const& p2) const;
     555             : 
     556             :   // Disallow evil constructors
     557             :   scoped_array(const scoped_array&);
     558             :   void operator=(const scoped_array&);
     559             : };
     560             : 
     561             : }  // namespace internal
     562             : 
     563             : // We made these internal so that they would show up as such in the docs,
     564             : // but we don't want to stick "internal::" in front of them everywhere.
     565             : using internal::scoped_ptr;
     566             : using internal::scoped_array;
     567             : 
     568             : // ===================================================================
     569             : // emulates google3/base/logging.h
     570             : 
     571             : enum LogLevel {
     572             :   LOGLEVEL_INFO,     // Informational.  This is never actually used by
     573             :                      // libprotobuf.
     574             :   LOGLEVEL_WARNING,  // Warns about issues that, although not technically a
     575             :                      // problem now, could cause problems in the future.  For
     576             :                      // example, a // warning will be printed when parsing a
     577             :                      // message that is near the message size limit.
     578             :   LOGLEVEL_ERROR,    // An error occurred which should never happen during
     579             :                      // normal use.
     580             :   LOGLEVEL_FATAL,    // An error occurred from which the library cannot
     581             :                      // recover.  This usually indicates a programming error
     582             :                      // in the code which calls the library, especially when
     583             :                      // compiled in debug mode.
     584             : 
     585             : #ifdef NDEBUG
     586             :   LOGLEVEL_DFATAL = LOGLEVEL_ERROR
     587             : #else
     588             :   LOGLEVEL_DFATAL = LOGLEVEL_FATAL
     589             : #endif
     590             : 
     591             : #ifdef _WIN32
     592             :   // ERROR is defined as 0 on some windows builds, so `GOOGLE_LOG(ERROR, ...)`
     593             :   // expands into `GOOGLE_LOG(0, ...)` which then expands into
     594             :   // `someGoogleLogging(LOGLEVEL_0, ...)`. This is not ideal, because the
     595             :   // GOOGLE_LOG macro expects to expand itself into
     596             :   // `someGoogleLogging(LOGLEVEL_ERROR, ...)` instead. The workaround to get
     597             :   // everything building is to simply define LOGLEVEL_0 as LOGLEVEL_ERROR and
     598             :   // move on with our lives.
     599             :   //
     600             :   // We also define ERROR the same way that the Windows SDK does for
     601             :   // consistency.
     602             : #define ERROR 0
     603             :   , LOGLEVEL_0 = LOGLEVEL_ERROR
     604             : #endif
     605             : };
     606             : 
     607             : namespace internal {
     608             : 
     609             : class LogFinisher;
     610             : 
     611             : class LIBPROTOBUF_EXPORT LogMessage {
     612             :  public:
     613             :   LogMessage(LogLevel level, const char* filename, int line);
     614             :   ~LogMessage();
     615             : 
     616             :   LogMessage& operator<<(const std::string& value);
     617             :   LogMessage& operator<<(const char* value);
     618             :   LogMessage& operator<<(char value);
     619             :   LogMessage& operator<<(int value);
     620             :   LogMessage& operator<<(uint value);
     621             :   LogMessage& operator<<(long value);
     622             :   LogMessage& operator<<(unsigned long value);
     623             :   LogMessage& operator<<(double value);
     624             : 
     625             :  private:
     626             :   friend class LogFinisher;
     627             :   void Finish();
     628             : 
     629             :   LogLevel level_;
     630             :   const char* filename_;
     631             :   int line_;
     632             :   std::string message_;
     633             : };
     634             : 
     635             : // Used to make the entire "LOG(BLAH) << etc." expression have a void return
     636             : // type and print a newline after each message.
     637             : class LIBPROTOBUF_EXPORT LogFinisher {
     638             :  public:
     639             :   void operator=(LogMessage& other);
     640             : };
     641             : 
     642             : }  // namespace internal
     643             : 
     644             : // Undef everything in case we're being mixed with some other Google library
     645             : // which already defined them itself.  Presumably all Google libraries will
     646             : // support the same syntax for these so it should not be a big deal if they
     647             : // end up using our definitions instead.
     648             : #undef GOOGLE_LOG
     649             : #undef GOOGLE_LOG_IF
     650             : 
     651             : #undef GOOGLE_CHECK
     652             : #undef GOOGLE_CHECK_OK
     653             : #undef GOOGLE_CHECK_EQ
     654             : #undef GOOGLE_CHECK_NE
     655             : #undef GOOGLE_CHECK_LT
     656             : #undef GOOGLE_CHECK_LE
     657             : #undef GOOGLE_CHECK_GT
     658             : #undef GOOGLE_CHECK_GE
     659             : #undef GOOGLE_CHECK_NOTNULL
     660             : 
     661             : #undef GOOGLE_DLOG
     662             : #undef GOOGLE_DCHECK
     663             : #undef GOOGLE_DCHECK_EQ
     664             : #undef GOOGLE_DCHECK_NE
     665             : #undef GOOGLE_DCHECK_LT
     666             : #undef GOOGLE_DCHECK_LE
     667             : #undef GOOGLE_DCHECK_GT
     668             : #undef GOOGLE_DCHECK_GE
     669             : 
     670             : #define GOOGLE_LOG(LEVEL)                                                 \
     671             :   ::google::protobuf::internal::LogFinisher() =                           \
     672             :     ::google::protobuf::internal::LogMessage(                             \
     673             :       ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__)
     674             : #define GOOGLE_LOG_IF(LEVEL, CONDITION) \
     675             :   !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL)
     676             : 
     677             : #define GOOGLE_CHECK(EXPRESSION) \
     678             :   GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": "
     679             : #define GOOGLE_CHECK_OK(A) GOOGLE_CHECK(A)
     680             : #define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B))
     681             : #define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B))
     682             : #define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) <  (B))
     683             : #define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B))
     684             : #define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) >  (B))
     685             : #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B))
     686             : 
     687             : namespace internal {
     688             : template<typename T>
     689           0 : T* CheckNotNull(const char* /* file */, int /* line */,
     690             :                 const char* name, T* val) {
     691           0 :   if (val == NULL) {
     692           0 :     GOOGLE_LOG(FATAL) << name;
     693             :   }
     694           0 :   return val;
     695             : }
     696             : }  // namespace internal
     697             : #define GOOGLE_CHECK_NOTNULL(A) \
     698             :   internal::CheckNotNull(__FILE__, __LINE__, "'" #A "' must not be NULL", (A))
     699             : 
     700             : #ifdef NDEBUG
     701             : 
     702             : #define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false)
     703             : 
     704             : #define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION)
     705             : #define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B))
     706             : #define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B))
     707             : #define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) <  (B))
     708             : #define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B))
     709             : #define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) >  (B))
     710             : #define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B))
     711             : 
     712             : #else  // NDEBUG
     713             : 
     714             : #define GOOGLE_DLOG GOOGLE_LOG
     715             : 
     716             : #define GOOGLE_DCHECK    GOOGLE_CHECK
     717             : #define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ
     718             : #define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE
     719             : #define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT
     720             : #define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE
     721             : #define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT
     722             : #define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE
     723             : 
     724             : #endif  // !NDEBUG
     725             : 
     726             : typedef void LogHandler(LogLevel level, const char* filename, int line,
     727             :                         const std::string& message);
     728             : 
     729             : // The protobuf library sometimes writes warning and error messages to
     730             : // stderr.  These messages are primarily useful for developers, but may
     731             : // also help end users figure out a problem.  If you would prefer that
     732             : // these messages be sent somewhere other than stderr, call SetLogHandler()
     733             : // to set your own handler.  This returns the old handler.  Set the handler
     734             : // to NULL to ignore log messages (but see also LogSilencer, below).
     735             : //
     736             : // Obviously, SetLogHandler is not thread-safe.  You should only call it
     737             : // at initialization time, and probably not from library code.  If you
     738             : // simply want to suppress log messages temporarily (e.g. because you
     739             : // have some code that tends to trigger them frequently and you know
     740             : // the warnings are not important to you), use the LogSilencer class
     741             : // below.
     742             : LIBPROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func);
     743             : 
     744             : // Create a LogSilencer if you want to temporarily suppress all log
     745             : // messages.  As long as any LogSilencer objects exist, non-fatal
     746             : // log messages will be discarded (the current LogHandler will *not*
     747             : // be called).  Constructing a LogSilencer is thread-safe.  You may
     748             : // accidentally suppress log messages occurring in another thread, but
     749             : // since messages are generally for debugging purposes only, this isn't
     750             : // a big deal.  If you want to intercept log messages, use SetLogHandler().
     751             : class LIBPROTOBUF_EXPORT LogSilencer {
     752             :  public:
     753             :   LogSilencer();
     754             :   ~LogSilencer();
     755             : };
     756             : 
     757             : // ===================================================================
     758             : // emulates google3/base/callback.h
     759             : 
     760             : // Abstract interface for a callback.  When calling an RPC, you must provide
     761             : // a Closure to call when the procedure completes.  See the Service interface
     762             : // in service.h.
     763             : //
     764             : // To automatically construct a Closure which calls a particular function or
     765             : // method with a particular set of parameters, use the NewCallback() function.
     766             : // Example:
     767             : //   void FooDone(const FooResponse* response) {
     768             : //     ...
     769             : //   }
     770             : //
     771             : //   void CallFoo() {
     772             : //     ...
     773             : //     // When done, call FooDone() and pass it a pointer to the response.
     774             : //     Closure* callback = NewCallback(&FooDone, response);
     775             : //     // Make the call.
     776             : //     service->Foo(controller, request, response, callback);
     777             : //   }
     778             : //
     779             : // Example that calls a method:
     780             : //   class Handler {
     781             : //    public:
     782             : //     ...
     783             : //
     784             : //     void FooDone(const FooResponse* response) {
     785             : //       ...
     786             : //     }
     787             : //
     788             : //     void CallFoo() {
     789             : //       ...
     790             : //       // When done, call FooDone() and pass it a pointer to the response.
     791             : //       Closure* callback = NewCallback(this, &Handler::FooDone, response);
     792             : //       // Make the call.
     793             : //       service->Foo(controller, request, response, callback);
     794             : //     }
     795             : //   };
     796             : //
     797             : // Currently NewCallback() supports binding zero, one, or two arguments.
     798             : //
     799             : // Callbacks created with NewCallback() automatically delete themselves when
     800             : // executed.  They should be used when a callback is to be called exactly
     801             : // once (usually the case with RPC callbacks).  If a callback may be called
     802             : // a different number of times (including zero), create it with
     803             : // NewPermanentCallback() instead.  You are then responsible for deleting the
     804             : // callback (using the "delete" keyword as normal).
     805             : //
     806             : // Note that NewCallback() is a bit touchy regarding argument types.  Generally,
     807             : // the values you provide for the parameter bindings must exactly match the
     808             : // types accepted by the callback function.  For example:
     809             : //   void Foo(string s);
     810             : //   NewCallback(&Foo, "foo");          // WON'T WORK:  const char* != string
     811             : //   NewCallback(&Foo, string("foo"));  // WORKS
     812             : // Also note that the arguments cannot be references:
     813             : //   void Foo(const string& s);
     814             : //   string my_str;
     815             : //   NewCallback(&Foo, my_str);  // WON'T WORK:  Can't use referecnes.
     816             : // However, correctly-typed pointers will work just fine.
     817             : class LIBPROTOBUF_EXPORT Closure {
     818             :  public:
     819          12 :   Closure() {}
     820             :   virtual ~Closure();
     821             : 
     822             :   virtual void Run() = 0;
     823             : 
     824             :  private:
     825             :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure);
     826             : };
     827             : 
     828             : namespace internal {
     829             : 
     830             : class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure {
     831             :  public:
     832             :   typedef void (*FunctionType)();
     833             : 
     834          12 :   FunctionClosure0(FunctionType function, bool self_deleting)
     835          12 :     : function_(function), self_deleting_(self_deleting) {}
     836             :   ~FunctionClosure0();
     837             : 
     838          12 :   void Run() {
     839          12 :     bool needs_delete = self_deleting_;  // read in case callback deletes
     840          12 :     function_();
     841          12 :     if (needs_delete) delete this;
     842          12 :   }
     843             : 
     844             :  private:
     845             :   FunctionType function_;
     846             :   bool self_deleting_;
     847             : };
     848             : 
     849             : template <typename Class>
     850             : class MethodClosure0 : public Closure {
     851             :  public:
     852             :   typedef void (Class::*MethodType)();
     853             : 
     854             :   MethodClosure0(Class* object, MethodType method, bool self_deleting)
     855             :     : object_(object), method_(method), self_deleting_(self_deleting) {}
     856             :   ~MethodClosure0() {}
     857             : 
     858             :   void Run() {
     859             :     bool needs_delete = self_deleting_;  // read in case callback deletes
     860             :     (object_->*method_)();
     861             :     if (needs_delete) delete this;
     862             :   }
     863             : 
     864             :  private:
     865             :   Class* object_;
     866             :   MethodType method_;
     867             :   bool self_deleting_;
     868             : };
     869             : 
     870             : template <typename Arg1>
     871             : class FunctionClosure1 : public Closure {
     872             :  public:
     873             :   typedef void (*FunctionType)(Arg1 arg1);
     874             : 
     875           0 :   FunctionClosure1(FunctionType function, bool self_deleting,
     876             :                    Arg1 arg1)
     877             :     : function_(function), self_deleting_(self_deleting),
     878           0 :       arg1_(arg1) {}
     879           0 :   ~FunctionClosure1() {}
     880             : 
     881           0 :   void Run() {
     882           0 :     bool needs_delete = self_deleting_;  // read in case callback deletes
     883           0 :     function_(arg1_);
     884           0 :     if (needs_delete) delete this;
     885           0 :   }
     886             : 
     887             :  private:
     888             :   FunctionType function_;
     889             :   bool self_deleting_;
     890             :   Arg1 arg1_;
     891             : };
     892             : 
     893             : template <typename Class, typename Arg1>
     894             : class MethodClosure1 : public Closure {
     895             :  public:
     896             :   typedef void (Class::*MethodType)(Arg1 arg1);
     897             : 
     898             :   MethodClosure1(Class* object, MethodType method, bool self_deleting,
     899             :                  Arg1 arg1)
     900             :     : object_(object), method_(method), self_deleting_(self_deleting),
     901             :       arg1_(arg1) {}
     902             :   ~MethodClosure1() {}
     903             : 
     904             :   void Run() {
     905             :     bool needs_delete = self_deleting_;  // read in case callback deletes
     906             :     (object_->*method_)(arg1_);
     907             :     if (needs_delete) delete this;
     908             :   }
     909             : 
     910             :  private:
     911             :   Class* object_;
     912             :   MethodType method_;
     913             :   bool self_deleting_;
     914             :   Arg1 arg1_;
     915             : };
     916             : 
     917             : template <typename Arg1, typename Arg2>
     918             : class FunctionClosure2 : public Closure {
     919             :  public:
     920             :   typedef void (*FunctionType)(Arg1 arg1, Arg2 arg2);
     921             : 
     922             :   FunctionClosure2(FunctionType function, bool self_deleting,
     923             :                    Arg1 arg1, Arg2 arg2)
     924             :     : function_(function), self_deleting_(self_deleting),
     925             :       arg1_(arg1), arg2_(arg2) {}
     926             :   ~FunctionClosure2() {}
     927             : 
     928             :   void Run() {
     929             :     bool needs_delete = self_deleting_;  // read in case callback deletes
     930             :     function_(arg1_, arg2_);
     931             :     if (needs_delete) delete this;
     932             :   }
     933             : 
     934             :  private:
     935             :   FunctionType function_;
     936             :   bool self_deleting_;
     937             :   Arg1 arg1_;
     938             :   Arg2 arg2_;
     939             : };
     940             : 
     941             : template <typename Class, typename Arg1, typename Arg2>
     942             : class MethodClosure2 : public Closure {
     943             :  public:
     944             :   typedef void (Class::*MethodType)(Arg1 arg1, Arg2 arg2);
     945             : 
     946             :   MethodClosure2(Class* object, MethodType method, bool self_deleting,
     947             :                  Arg1 arg1, Arg2 arg2)
     948             :     : object_(object), method_(method), self_deleting_(self_deleting),
     949             :       arg1_(arg1), arg2_(arg2) {}
     950             :   ~MethodClosure2() {}
     951             : 
     952             :   void Run() {
     953             :     bool needs_delete = self_deleting_;  // read in case callback deletes
     954             :     (object_->*method_)(arg1_, arg2_);
     955             :     if (needs_delete) delete this;
     956             :   }
     957             : 
     958             :  private:
     959             :   Class* object_;
     960             :   MethodType method_;
     961             :   bool self_deleting_;
     962             :   Arg1 arg1_;
     963             :   Arg2 arg2_;
     964             : };
     965             : 
     966             : }  // namespace internal
     967             : 
     968             : // See Closure.
     969             : inline Closure* NewCallback(void (*function)()) {
     970             :   return new internal::FunctionClosure0(function, true);
     971             : }
     972             : 
     973             : // See Closure.
     974             : inline Closure* NewPermanentCallback(void (*function)()) {
     975             :   return new internal::FunctionClosure0(function, false);
     976             : }
     977             : 
     978             : // See Closure.
     979             : template <typename Class>
     980             : inline Closure* NewCallback(Class* object, void (Class::*method)()) {
     981             :   return new internal::MethodClosure0<Class>(object, method, true);
     982             : }
     983             : 
     984             : // See Closure.
     985             : template <typename Class>
     986             : inline Closure* NewPermanentCallback(Class* object, void (Class::*method)()) {
     987             :   return new internal::MethodClosure0<Class>(object, method, false);
     988             : }
     989             : 
     990             : // See Closure.
     991             : template <typename Arg1>
     992             : inline Closure* NewCallback(void (*function)(Arg1),
     993             :                             Arg1 arg1) {
     994             :   return new internal::FunctionClosure1<Arg1>(function, true, arg1);
     995             : }
     996             : 
     997             : // See Closure.
     998             : template <typename Arg1>
     999             : inline Closure* NewPermanentCallback(void (*function)(Arg1),
    1000             :                                      Arg1 arg1) {
    1001             :   return new internal::FunctionClosure1<Arg1>(function, false, arg1);
    1002             : }
    1003             : 
    1004             : // See Closure.
    1005             : template <typename Class, typename Arg1>
    1006             : inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1),
    1007             :                             Arg1 arg1) {
    1008             :   return new internal::MethodClosure1<Class, Arg1>(object, method, true, arg1);
    1009             : }
    1010             : 
    1011             : // See Closure.
    1012             : template <typename Class, typename Arg1>
    1013             : inline Closure* NewPermanentCallback(Class* object, void (Class::*method)(Arg1),
    1014             :                                      Arg1 arg1) {
    1015             :   return new internal::MethodClosure1<Class, Arg1>(object, method, false, arg1);
    1016             : }
    1017             : 
    1018             : // See Closure.
    1019             : template <typename Arg1, typename Arg2>
    1020             : inline Closure* NewCallback(void (*function)(Arg1, Arg2),
    1021             :                             Arg1 arg1, Arg2 arg2) {
    1022             :   return new internal::FunctionClosure2<Arg1, Arg2>(
    1023             :     function, true, arg1, arg2);
    1024             : }
    1025             : 
    1026             : // See Closure.
    1027             : template <typename Arg1, typename Arg2>
    1028             : inline Closure* NewPermanentCallback(void (*function)(Arg1, Arg2),
    1029             :                                      Arg1 arg1, Arg2 arg2) {
    1030             :   return new internal::FunctionClosure2<Arg1, Arg2>(
    1031             :     function, false, arg1, arg2);
    1032             : }
    1033             : 
    1034             : // See Closure.
    1035             : template <typename Class, typename Arg1, typename Arg2>
    1036             : inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1, Arg2),
    1037             :                             Arg1 arg1, Arg2 arg2) {
    1038             :   return new internal::MethodClosure2<Class, Arg1, Arg2>(
    1039             :     object, method, true, arg1, arg2);
    1040             : }
    1041             : 
    1042             : // See Closure.
    1043             : template <typename Class, typename Arg1, typename Arg2>
    1044             : inline Closure* NewPermanentCallback(
    1045             :     Class* object, void (Class::*method)(Arg1, Arg2),
    1046             :     Arg1 arg1, Arg2 arg2) {
    1047             :   return new internal::MethodClosure2<Class, Arg1, Arg2>(
    1048             :     object, method, false, arg1, arg2);
    1049             : }
    1050             : 
    1051             : // A function which does nothing.  Useful for creating no-op callbacks, e.g.:
    1052             : //   Closure* nothing = NewCallback(&DoNothing);
    1053             : void LIBPROTOBUF_EXPORT DoNothing();
    1054             : 
    1055             : // ===================================================================
    1056             : // emulates google3/base/mutex.h
    1057             : 
    1058             : namespace internal {
    1059             : 
    1060             : // A Mutex is a non-reentrant (aka non-recursive) mutex.  At most one thread T
    1061             : // may hold a mutex at a given time.  If T attempts to Lock() the same Mutex
    1062             : // while holding it, T will deadlock.
    1063             : class LIBPROTOBUF_EXPORT Mutex {
    1064             :  public:
    1065             :   // Create a Mutex that is not held by anybody.
    1066             :   Mutex();
    1067             : 
    1068             :   // Destructor
    1069             :   ~Mutex();
    1070             : 
    1071             :   // Block if necessary until this Mutex is free, then acquire it exclusively.
    1072             :   void Lock();
    1073             : 
    1074             :   // Release this Mutex.  Caller must hold it exclusively.
    1075             :   void Unlock();
    1076             : 
    1077             :   // Crash if this Mutex is not held exclusively by this thread.
    1078             :   // May fail to crash when it should; will never crash when it should not.
    1079             :   void AssertHeld();
    1080             : 
    1081             :  private:
    1082             :   struct Internal;
    1083             :   Internal* mInternal;
    1084             : 
    1085             :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex);
    1086             : };
    1087             : 
    1088             : // MutexLock(mu) acquires mu when constructed and releases it when destroyed.
    1089             : class LIBPROTOBUF_EXPORT MutexLock {
    1090             :  public:
    1091          24 :   explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); }
    1092          24 :   ~MutexLock() { this->mu_->Unlock(); }
    1093             :  private:
    1094             :   Mutex *const mu_;
    1095             :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock);
    1096             : };
    1097             : 
    1098             : // TODO(kenton):  Implement these?  Hard to implement portably.
    1099             : typedef MutexLock ReaderMutexLock;
    1100             : typedef MutexLock WriterMutexLock;
    1101             : 
    1102             : // MutexLockMaybe is like MutexLock, but is a no-op when mu is NULL.
    1103             : class LIBPROTOBUF_EXPORT MutexLockMaybe {
    1104             :  public:
    1105           0 :   explicit MutexLockMaybe(Mutex *mu) :
    1106           0 :     mu_(mu) { if (this->mu_ != NULL) { this->mu_->Lock(); } }
    1107           0 :   ~MutexLockMaybe() { if (this->mu_ != NULL) { this->mu_->Unlock(); } }
    1108             :  private:
    1109             :   Mutex *const mu_;
    1110             :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe);
    1111             : };
    1112             : 
    1113             : }  // namespace internal
    1114             : 
    1115             : // We made these internal so that they would show up as such in the docs,
    1116             : // but we don't want to stick "internal::" in front of them everywhere.
    1117             : using internal::Mutex;
    1118             : using internal::MutexLock;
    1119             : using internal::ReaderMutexLock;
    1120             : using internal::WriterMutexLock;
    1121             : using internal::MutexLockMaybe;
    1122             : 
    1123             : // ===================================================================
    1124             : // from google3/util/utf8/public/unilib.h
    1125             : 
    1126             : namespace internal {
    1127             : 
    1128             : // Checks if the buffer contains structurally-valid UTF-8.  Implemented in
    1129             : // structurally_valid.cc.
    1130             : LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len);
    1131             : 
    1132             : }  // namespace internal
    1133             : 
    1134             : // ===================================================================
    1135             : // from google3/util/endian/endian.h
    1136             : LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x);
    1137             : 
    1138             : // ===================================================================
    1139             : // Shutdown support.
    1140             : 
    1141             : // Shut down the entire protocol buffers library, deleting all static-duration
    1142             : // objects allocated by the library or by generated .pb.cc files.
    1143             : //
    1144             : // There are two reasons you might want to call this:
    1145             : // * You use a draconian definition of "memory leak" in which you expect
    1146             : //   every single malloc() to have a corresponding free(), even for objects
    1147             : //   which live until program exit.
    1148             : // * You are writing a dynamically-loaded library which needs to clean up
    1149             : //   after itself when the library is unloaded.
    1150             : //
    1151             : // It is safe to call this multiple times.  However, it is not safe to use
    1152             : // any other part of the protocol buffers library after
    1153             : // ShutdownProtobufLibrary() has been called.
    1154             : LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary();
    1155             : 
    1156             : namespace internal {
    1157             : 
    1158             : // Register a function to be called when ShutdownProtocolBuffers() is called.
    1159             : LIBPROTOBUF_EXPORT void OnShutdown(void (*func)());
    1160             : 
    1161             : }  // namespace internal
    1162             : 
    1163             : #if PROTOBUF_USE_EXCEPTIONS
    1164             : class FatalException : public std::exception {
    1165             :  public:
    1166             :   FatalException(const char* filename, int line, const std::string& message)
    1167             :       : filename_(filename), line_(line), message_(message) {}
    1168             :   virtual ~FatalException() throw();
    1169             : 
    1170             :   virtual const char* what() const throw();
    1171             : 
    1172             :   const char* filename() const { return filename_; }
    1173             :   int line() const { return line_; }
    1174             :   const std::string& message() const { return message_; }
    1175             : 
    1176             :  private:
    1177             :   const char* filename_;
    1178             :   const int line_;
    1179             :   const std::string message_;
    1180             : };
    1181             : #endif
    1182             : 
    1183             : // This is at the end of the file instead of the beginning to work around a bug
    1184             : // in some versions of MSVC.
    1185             : using namespace std;  // Don't do this at home, kids.
    1186             : 
    1187             : }  // namespace protobuf
    1188             : }  // namespace google
    1189             : 
    1190             : #endif  // GOOGLE_PROTOBUF_COMMON_H__

Generated by: LCOV version 1.13