| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_SYSTEM_MACROS_H_ | |
| 6 #define MOJO_PUBLIC_SYSTEM_MACROS_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 // Annotate a variable indicating it's okay if it's unused. | |
| 11 // Use like: | |
| 12 // int x MOJO_ALLOW_UNUSED = ...; | |
| 13 #if defined(__GNUC__) | |
| 14 #define MOJO_ALLOW_UNUSED __attribute__((unused)) | |
| 15 #else | |
| 16 #define MOJO_ALLOW_UNUSED | |
| 17 #endif | |
| 18 | |
| 19 // Annotate a function indicating that the caller must examine the return value. | |
| 20 // Use like: | |
| 21 // int foo() MOJO_WARN_UNUSED_RESULT; | |
| 22 // Note that it can only be used on the prototype, and not the definition. | |
| 23 #if defined(__GNUC__) | |
| 24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) | |
| 25 #else | |
| 26 #define MOJO_WARN_UNUSED_RESULT | |
| 27 #endif | |
| 28 | |
| 29 // C++-only macros ------------------------------------------------------------- | |
| 30 | |
| 31 #ifdef __cplusplus | |
| 32 | |
| 33 // Annotate a virtual method indicating it must be overriding a virtual method | |
| 34 // in the parent class. Use like: | |
| 35 // virtual void foo() OVERRIDE; | |
| 36 #if defined(_MSC_VER) || defined(__clang__) | |
| 37 #define MOJO_OVERRIDE override | |
| 38 #else | |
| 39 #define MOJO_OVERRIDE | |
| 40 #endif | |
| 41 | |
| 42 // A macro to disallow the copy constructor and operator= functions. | |
| 43 // This should be used in the private: declarations for a class. | |
| 44 #define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
| 45 TypeName(const TypeName&); \ | |
| 46 void operator=(const TypeName&) | |
| 47 | |
| 48 // Used to assert things at compile time. | |
| 49 namespace mojo { template <bool> struct CompileAssert {}; } | |
| 50 #define MOJO_COMPILE_ASSERT(expr, msg) \ | |
| 51 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] | |
| 52 | |
| 53 // Used to calculate the number of elements in an array. | |
| 54 // (See |arraysize()| in Chromium's base/basictypes.h for more details.) | |
| 55 namespace mojo { | |
| 56 template <typename T, size_t N> | |
| 57 char (&ArraySizeHelper(T (&array)[N]))[N]; | |
| 58 #if !defined(_MSC_VER) | |
| 59 template <typename T, size_t N> | |
| 60 char (&ArraySizeHelper(const T (&array)[N]))[N]; | |
| 61 #endif | |
| 62 } // namespace mojo | |
| 63 #define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array))) | |
| 64 | |
| 65 // Used to make a type move-only in C++03. See Chromium's base/move.h for more | |
| 66 // details. | |
| 67 #define MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \ | |
| 68 private: \ | |
| 69 struct rvalue_type { \ | |
| 70 explicit rvalue_type(type* object) : object(object) {} \ | |
| 71 type* object; \ | |
| 72 }; \ | |
| 73 type(type&); \ | |
| 74 void operator=(type&); \ | |
| 75 public: \ | |
| 76 operator rvalue_type() { return rvalue_type(this); } \ | |
| 77 type Pass() { return type(rvalue_type(this)); } \ | |
| 78 typedef void MoveOnlyTypeForCPP03; \ | |
| 79 private: | |
| 80 | |
| 81 #endif // __cplusplus | |
| 82 | |
| 83 #endif // MOJO_PUBLIC_SYSTEM_MACROS_H_ | |
| OLD | NEW |