Home | History | Annotate | Download | only in base
      1 /*
      2  * libjingle
      3  * Copyright 2011, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef TALK_BASE_BASICTYPES_H__
     29 #define TALK_BASE_BASICTYPES_H__
     30 
     31 #ifndef WIN32
     32 #include <stdint.h>  // for uintptr_t
     33 #endif
     34 
     35 #ifdef HAVE_CONFIG_H
     36 #include "config.h"
     37 #endif
     38 
     39 #include "talk/base/constructormagic.h"
     40 
     41 #ifndef INT_TYPES_DEFINED
     42 #define INT_TYPES_DEFINED
     43 #ifdef COMPILER_MSVC
     44 typedef __int64 int64;
     45 #else
     46 typedef long long int64;
     47 #endif /* COMPILER_MSVC */
     48 typedef int int32;
     49 typedef short int16;
     50 typedef char int8;
     51 
     52 #ifdef COMPILER_MSVC
     53 typedef unsigned __int64 uint64;
     54 typedef __int64 int64;
     55 #ifndef INT64_C
     56 #define INT64_C(x) x ## I64
     57 #endif
     58 #ifndef UINT64_C
     59 #define UINT64_C(x) x ## UI64
     60 #endif
     61 #define INT64_F "I64"
     62 #else
     63 typedef unsigned long long uint64;
     64 typedef long long int64;
     65 #ifndef INT64_C
     66 #define INT64_C(x) x ## LL
     67 #endif
     68 #ifndef UINT64_C
     69 #define UINT64_C(x) x ## ULL
     70 #endif
     71 #define INT64_F "ll"
     72 #endif /* COMPILER_MSVC */
     73 typedef unsigned int uint32;
     74 typedef unsigned short uint16;
     75 typedef unsigned char uint8;
     76 #endif  // INT_TYPES_DEFINED
     77 
     78 #ifdef WIN32
     79 typedef int socklen_t;
     80 #endif
     81 
     82 namespace talk_base {
     83   template<class T> inline T _min(T a, T b) { return (a > b) ? b : a; }
     84   template<class T> inline T _max(T a, T b) { return (a < b) ? b : a; }
     85 
     86   // For wait functions that take a number of milliseconds, kForever indicates
     87   // unlimited time.
     88   const int kForever = -1;
     89 }
     90 
     91 // Detect compiler is for x86 or x64.
     92 #if defined(__x86_64__) || defined(_M_X64) || \
     93     defined(__i386__) || defined(_M_IX86)
     94 #define CPU_X86 1
     95 #endif
     96 
     97 #ifdef WIN32
     98 #define alignof(t) __alignof(t)
     99 #else  // !WIN32
    100 #define alignof(t) __alignof__(t)
    101 #endif  // !WIN32
    102 #define IS_ALIGNED(p, a) (0==(reinterpret_cast<uintptr_t>(p) & ((a)-1)))
    103 #define ALIGNP(p, t) \
    104   (reinterpret_cast<uint8*>(((reinterpret_cast<uintptr_t>(p) + \
    105   ((t)-1)) & ~((t)-1))))
    106 
    107 #ifndef UNUSED
    108 #define UNUSED(x) Unused(static_cast<const void *>(&x))
    109 #define UNUSED2(x,y) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y))
    110 #define UNUSED3(x,y,z) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z))
    111 #define UNUSED4(x,y,z,a) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a))
    112 #define UNUSED5(x,y,z,a,b) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a)); Unused(static_cast<const void *>(&b))
    113 inline void Unused(const void *) { }
    114 #endif // UNUSED
    115 
    116 #if defined(__GNUC__)
    117 #define GCC_ATTR(x) __attribute__ ((x))
    118 #else  // !__GNUC__
    119 #define GCC_ATTR(x)
    120 #endif  // !__GNUC__
    121 
    122 #endif // TALK_BASE_BASICTYPES_H__
    123