OLD | NEW |
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 // This file contains macros and macro-like constructs (e.g., templates) that | 5 // This file contains macros and macro-like constructs (e.g., templates) that |
6 // are commonly used throughout Chromium source. (It may also contain things | 6 // are commonly used throughout Chromium source. (It may also contain things |
7 // that are closely related to things that are commonly used that belong in this | 7 // that are closely related to things that are commonly used that belong in this |
8 // file.) | 8 // file.) |
9 | 9 |
10 #ifndef BASE_MACROS_H_ | 10 #ifndef BASE_MACROS_H_ |
11 #define BASE_MACROS_H_ | 11 #define BASE_MACROS_H_ |
12 | 12 |
13 #include <stddef.h> // For size_t. | 13 #include <stddef.h> // For size_t. |
14 | 14 |
15 // Put this in the declarations for a class to be uncopyable. | 15 // Put this in the declarations for a class to be uncopyable. |
16 #define DISALLOW_COPY(TypeName) \ | 16 #define DISALLOW_COPY(TypeName) \ |
17 TypeName(const TypeName&) = delete | 17 TypeName(const TypeName&) = delete |
18 | 18 |
19 // Put this in the declarations for a class to be unassignable. | 19 // Put this in the declarations for a class to be unassignable. |
20 #define DISALLOW_ASSIGN(TypeName) \ | 20 #define DISALLOW_ASSIGN(TypeName) \ |
21 void operator=(const TypeName&) = delete | 21 void operator=(const TypeName&) = delete |
22 | 22 |
23 // A macro to disallow the copy constructor and operator= functions. | 23 // A macro to disallow the copy constructor and operator= functions. |
24 // This should be used in the private: declarations for a class. | 24 // This should be used in the private: declarations for a class. |
25 // TODO(pkasting): Using "= delete" is non-branded-build-specific initially to | |
26 // limit the rollout to reduce the chance of build breakage. Remove the ifdef | |
27 // here and use "= delete" always. | |
28 #if defined(CHROMIUM_BUILD) | |
29 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
30 TypeName(const TypeName&) = delete; \ | 26 TypeName(const TypeName&) = delete; \ |
31 void operator=(const TypeName&) = delete | 27 void operator=(const TypeName&) = delete |
32 #else | |
33 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
34 TypeName(const TypeName&); \ | |
35 void operator=(const TypeName&) | |
36 #endif | |
37 | 28 |
38 // A macro to disallow all the implicit constructors, namely the | 29 // A macro to disallow all the implicit constructors, namely the |
39 // default constructor, copy constructor and operator= functions. | 30 // default constructor, copy constructor and operator= functions. |
40 // | 31 // |
41 // This should be used in the private: declarations for a class | 32 // This should be used in the private: declarations for a class |
42 // that wants to prevent anyone from instantiating it. This is | 33 // that wants to prevent anyone from instantiating it. This is |
43 // especially useful for classes containing only static methods. | 34 // especially useful for classes containing only static methods. |
44 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 35 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
45 TypeName() = delete; \ | 36 TypeName() = delete; \ |
46 DISALLOW_COPY_AND_ASSIGN(TypeName) | 37 DISALLOW_COPY_AND_ASSIGN(TypeName) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 78 |
88 // Use these to declare and define a static local variable (static T;) so that | 79 // Use these to declare and define a static local variable (static T;) so that |
89 // it is leaked so that its destructors are not called at exit. If you need | 80 // it is leaked so that its destructors are not called at exit. If you need |
90 // thread-safe initialization, use base/lazy_instance.h instead. | 81 // thread-safe initialization, use base/lazy_instance.h instead. |
91 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 82 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
92 static type& name = *new type arguments | 83 static type& name = *new type arguments |
93 | 84 |
94 } // base | 85 } // base |
95 | 86 |
96 #endif // BASE_MACROS_H_ | 87 #endif // BASE_MACROS_H_ |
OLD | NEW |