ovr_sdk

diff LibOVR/Src/Kernel/OVR_Nullptr.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_Nullptr.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,150 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   OVR_Kernel.h
     1.7 +Filename    :   OVR_Nullptr.h
     1.8 +Content     :   Implements C++11 nullptr for the case that the compiler doesn't.
     1.9 +Created     :   June 19, 2014
    1.10 +Notes       : 
    1.11 +
    1.12 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.13 +
    1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.16 +which is provided at the time of installation or download, or which 
    1.17 +otherwise accompanies this software in either electronic or hard copy form.
    1.18 +
    1.19 +You may obtain a copy of the License at
    1.20 +
    1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.22 +
    1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.24 +distributed under the License is distributed on an "AS IS" BASIS,
    1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.26 +See the License for the specific language governing permissions and
    1.27 +limitations under the License.
    1.28 +
    1.29 +************************************************************************************/
    1.30 +
    1.31 +#ifndef OVR_Nullptr_h
    1.32 +#define OVR_Nullptr_h
    1.33 +
    1.34 +#pragma once
    1.35 +
    1.36 +#include "OVR_Types.h"
    1.37 +
    1.38 +
    1.39 +//-----------------------------------------------------------------------------------
    1.40 +// ***** OVR_HAVE_std_nullptr_t
    1.41 +//
    1.42 +// Identifies if <cstddef.h> includes std::nullptr_t. 
    1.43 +//
    1.44 +#if !defined(OVR_HAVE_std_nullptr_t) && defined(OVR_CPP11_ENABLED)
    1.45 +    #if defined(OVR_STDLIB_LIBCPP)
    1.46 +        #define OVR_HAVE_std_nullptr_t 1
    1.47 +    #elif defined(OVR_STDLIB_LIBSTDCPP)
    1.48 +        #if (__GLIBCXX__ >= 20110325) && (__GLIBCXX__ != 20110428) && (__GLIBCXX__ != 20120702)
    1.49 +            #define OVR_HAVE_std_nullptr_t 1
    1.50 +        #endif
    1.51 +    #elif defined(_MSC_VER) && (_MSC_VER >= 1600) // VS2010+
    1.52 +        #define OVR_HAVE_std_nullptr_t 1
    1.53 +    #elif defined(__clang__)
    1.54 +        #define OVR_HAVE_std_nullptr_t 1
    1.55 +    #elif defined(OVR_CPP_GNUC) && (OVR_CC_VERSION >= 406) // GCC 4.6+
    1.56 +        #define OVR_HAVE_std_nullptr_t 1
    1.57 +    #endif
    1.58 +#endif
    1.59 +
    1.60 +
    1.61 +//-----------------------------------------------------------------------------------
    1.62 +// ***** nullptr / std::nullptr_t
    1.63 +//
    1.64 +// Declares and defines nullptr and related types.
    1.65 +//
    1.66 +#if defined(OVR_CPP_NO_NULLPTR)
    1.67 +    namespace std
    1.68 +    {
    1.69 +        class nullptr_t
    1.70 +        {
    1.71 +        public:
    1.72 +            template <typename T>
    1.73 +            operator T*() const
    1.74 +                { return 0; }
    1.75 +         
    1.76 +            template <typename C, typename T>
    1.77 +            operator T C::*() const
    1.78 +                { return 0; }
    1.79 +
    1.80 +            #if OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS
    1.81 +                typedef void* (nullptr_t::*bool_)() const;  // 4.12,p1. We can't portably use operator bool(){ return false; } because bool 
    1.82 +                operator bool_() const                      // is convertable to int which breaks other required functionality.
    1.83 +                    { return false; }
    1.84 +            #else
    1.85 +                operator bool() const
    1.86 +                    { return false; }
    1.87 +            #endif
    1.88 +
    1.89 +        private:
    1.90 +            void operator&() const; // 5.2.10,p9
    1.91 +        };
    1.92 +
    1.93 +        inline nullptr_t nullptr_get()
    1.94 +        {
    1.95 +            nullptr_t n = { };
    1.96 +            return n;
    1.97 +        }
    1.98 +
    1.99 +        #if !defined(nullptr)
   1.100 +            #define nullptr nullptr_get()
   1.101 +        #endif
   1.102 +
   1.103 +    } // namespace std
   1.104 +
   1.105 +
   1.106 +    // 5.9,p2 p4
   1.107 +    // 13.6, p13
   1.108 +    template <typename T>
   1.109 +    inline bool operator==(T* pT, const std::nullptr_t)
   1.110 +        { return pT == 0; }
   1.111 +
   1.112 +    template <typename T>
   1.113 +    inline bool operator==(const std::nullptr_t, T* pT)
   1.114 +        { return pT == 0; }
   1.115 +
   1.116 +    template <typename T, typename U>
   1.117 +    inline bool operator==(const std::nullptr_t, T U::* pU)
   1.118 +        { return pU == 0; }
   1.119 +
   1.120 +    template <typename T, typename U>
   1.121 +    inline bool operator==(T U::* pTU, const std::nullptr_t)
   1.122 +        { return pTU == 0; }
   1.123 +
   1.124 +    inline bool operator==(const std::nullptr_t, const std::nullptr_t)
   1.125 +        { return true; }
   1.126 +
   1.127 +    inline bool operator!=(const std::nullptr_t, const std::nullptr_t)
   1.128 +        { return false; }
   1.129 +
   1.130 +    inline bool operator<(const std::nullptr_t, const std::nullptr_t)
   1.131 +        { return false; }
   1.132 +
   1.133 +    inline bool operator<=(const std::nullptr_t, const std::nullptr_t)
   1.134 +        { return true; }
   1.135 +
   1.136 +    inline bool operator>(const std::nullptr_t, const std::nullptr_t)
   1.137 +        { return false; }
   1.138 +
   1.139 +    inline bool operator>=(const std::nullptr_t, const std::nullptr_t)
   1.140 +        { return true; }
   1.141 +
   1.142 +    using std::nullptr_t;
   1.143 +    using std::nullptr_get;
   1.144 +
   1.145 +// Some compilers natively support C++11 nullptr but the standard library being used 
   1.146 +// doesn't declare std::nullptr_t, in which case we provide one ourselves.
   1.147 +#elif !defined(OVR_HAVE_std_nullptr_t) && !defined(OVR_CPP_NO_DECLTYPE)
   1.148 +    namespace std { typedef decltype(nullptr) nullptr_t; }
   1.149 +#endif
   1.150 +
   1.151 +
   1.152 +#endif
   1.153 +