Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: mojo/public/c/system/macros.h

Issue 216073002: Mojo: Split off the C++ parts of mojo/public/c/system macros.h to their own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_
6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 // Annotate a variable indicating it's okay if it's unused. 10 // Annotate a variable indicating it's okay if it's unused.
11 // Use like: 11 // Use like:
12 // int x MOJO_ALLOW_UNUSED = ...; 12 // int x MOJO_ALLOW_UNUSED = ...;
13 #if defined(__GNUC__) 13 #if defined(__GNUC__)
14 #define MOJO_ALLOW_UNUSED __attribute__((unused)) 14 #define MOJO_ALLOW_UNUSED __attribute__((unused))
15 #else 15 #else
16 #define MOJO_ALLOW_UNUSED 16 #define MOJO_ALLOW_UNUSED
17 #endif 17 #endif
18 18
19 // Annotate a function indicating that the caller must examine the return value. 19 // Annotate a function indicating that the caller must examine the return value.
20 // Use like: 20 // Use like:
21 // int foo() MOJO_WARN_UNUSED_RESULT; 21 // int foo() MOJO_WARN_UNUSED_RESULT;
22 // Note that it can only be used on the prototype, and not the definition. 22 // Note that it can only be used on the prototype, and not the definition.
23 #if defined(__GNUC__) 23 #if defined(__GNUC__)
24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
25 #else 25 #else
26 #define MOJO_WARN_UNUSED_RESULT 26 #define MOJO_WARN_UNUSED_RESULT
27 #endif 27 #endif
28 28
29 // C++-only macros ------------------------------------------------------------- 29 // This macro is currently C++-only, but we want to use it in the C core.h.
30
31 #ifdef __cplusplus 30 #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. 31 // Used to assert things at compile time.
49 namespace mojo { template <bool> struct CompileAssert {}; } 32 namespace mojo { template <bool> struct CompileAssert {}; }
50 #define MOJO_COMPILE_ASSERT(expr, msg) \ 33 #define MOJO_COMPILE_ASSERT(expr, msg) \
51 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] 34 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
52 35 #else
53 // Used to calculate the number of elements in an array. 36 #define MOJO_COMPILE_ASSERT(expr, msg)
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 37 #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 38
83 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 39 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
OLDNEW
« no previous file with comments | « mojo/public/bindings/tests/router_unittest.cc ('k') | mojo/public/c/tests/system/core_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698