capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

windows-sanity.h (3142B)


      1 // Copyright (c) 2013-2018 Sandstorm Development Group, Inc. and contributors
      2 // Licensed under the MIT License:
      3 //
      4 // Permission is hereby granted, free of charge, to any person obtaining a copy
      5 // of this software and associated documentation files (the "Software"), to deal
      6 // in the Software without restriction, including without limitation the rights
      7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      8 // copies of the Software, and to permit persons to whom the Software is
      9 // furnished to do so, subject to the following conditions:
     10 //
     11 // The above copyright notice and this permission notice shall be included in
     12 // all copies or substantial portions of the Software.
     13 //
     14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     20 // THE SOFTWARE.
     21 
     22 // This file replaces poorly-named #defines from windows.h with properly-namespaced versions, so
     23 // that they no longer conflict with similarly-named identifiers in other namespaces.
     24 //
     25 // This file must be #included some time after windows.h has been #included but before any attempt
     26 // to use the names for other purposes. However, this can be difficult to determine in header
     27 // files. Typically KJ / Cap'n Proto headers avoid including windows.h at all, but may use
     28 // conflicting identifiers. In order to relieve application developers from the need to include
     29 // windows-sanity.h themselves, we would like these headers to conditionally apply the fixes if
     30 // and only if windows.h was already included. Therefore, this header checks if windows.h has been
     31 // included and only applies fixups if this is the case. Furthermore, this header is designed such
     32 // that it can be included multiple times, and the fixups will be applied the first time it is
     33 // included *after* windows.h.
     34 //
     35 // Now, as long as any headers which need to use conflicting identifier names be sure to #include
     36 // windows-sanity.h, we can be sure that no conflicts will occur regardless of in what order the
     37 // application chooses to include these headers vs. windows.h.
     38 
     39 #if !_WIN32 && !__CYGWIN__
     40 
     41 // Not on Windows. Tell the compiler never to try to include this again.
     42 #pragma once
     43 
     44 #elif defined(_INC_WINDOWS)
     45 
     46 // We're on Windows and windows.h has been included. We need to fixup the namespace. We only need
     47 // to do this once, but we can't do it until windows.h has been included. Since that has happened
     48 // now, we use `#pragma once` to tell the compiler never to include this file again.
     49 #pragma once
     50 
     51 namespace win32 {
     52   const auto ERROR_ = ERROR;
     53 
     54 #ifdef ERROR  // This could be absent if e.g. NOGDI was used.
     55 #undef ERROR
     56   const auto ERROR = ERROR_;
     57 #endif
     58 
     59   typedef VOID VOID_;
     60 #undef VOID
     61   typedef VOID_ VOID;
     62 }
     63 
     64 using win32::ERROR;
     65 using win32::VOID;
     66 
     67 #endif