Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include "HAL/cpp/make_unique.h" |
| 11 | |
| 12 | // MSVC 2013 doesn't allow "= default" on move constructors, but since we are |
| 13 | // (currently) only actually using the move constructors in non-MSVC situations |
| 14 | // (ie, wpilibC++Devices), we can just ignore it in MSVC. |
| 15 | #if !defined(_MSC_VER) |
| 16 | #define DEFAULT_MOVE_CONSTRUCTOR(ClassName) ClassName(ClassName&&) = default |
| 17 | #else |
| 18 | #define DEFAULT_MOVE_CONSTRUCTOR(ClassName) |
| 19 | #endif |
| 20 | |
| 21 | #if (__cplusplus < 201103L) |
| 22 | #if !defined(_MSC_VER) |
| 23 | #define nullptr NULL |
| 24 | #endif |
| 25 | #define constexpr const |
| 26 | #endif |
| 27 | |
| 28 | #if defined(_MSC_VER) |
| 29 | #define noexcept throw() |
| 30 | #endif |
| 31 | |
| 32 | // Provide std::decay_t when using GCC < 4.9 |
| 33 | #if defined(__GNUC__) |
| 34 | #if __GNUC__ == 4 && __GNUC_MINOR__ < 9 |
| 35 | #include <type_traits> |
| 36 | namespace std { |
| 37 | template <class T> |
| 38 | using decay_t = typename decay<T>::type; |
| 39 | } |
| 40 | #endif |
| 41 | #endif |
| 42 | |
| 43 | namespace frc { |
| 44 | |
| 45 | // A struct to use as a deleter when a std::shared_ptr must wrap a raw pointer |
| 46 | // that is being deleted by someone else. |
| 47 | template <class T> |
| 48 | struct NullDeleter { |
| 49 | void operator()(T*) const noexcept {}; |
| 50 | }; |
| 51 | |
| 52 | } // namespace frc |
| 53 | |
| 54 | #include <atomic> |
| 55 | |
| 56 | namespace frc { |
| 57 | |
| 58 | // Use this for determining whether the default move constructor has been |
| 59 | // called on a containing object. This serves the purpose of allowing us to |
| 60 | // use the default move constructor of an object for moving all the data around |
| 61 | // while being able to use this to, for instance, chose not to de-allocate |
| 62 | // a PWM port in a destructor. |
| 63 | struct HasBeenMoved { |
| 64 | HasBeenMoved(HasBeenMoved&& other) { |
| 65 | other.moved = true; |
| 66 | moved = false; |
| 67 | } |
| 68 | HasBeenMoved() = default; |
| 69 | std::atomic<bool> moved{false}; |
| 70 | operator bool() const { return moved; } |
| 71 | }; |
| 72 | |
| 73 | } // namespace frc |
| 74 | |
| 75 | // For backwards compatibility |
| 76 | #ifndef NAMESPACED_WPILIB |
| 77 | using namespace frc; // NOLINT |
| 78 | #endif |