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 #include "build/build_config.h" // For OS_XXX. TODO(pkasting): Remove. | |
16 | |
15 // Put this in the declarations for a class to be uncopyable. | 17 // Put this in the declarations for a class to be uncopyable. |
16 #define DISALLOW_COPY(TypeName) \ | 18 #define DISALLOW_COPY(TypeName) \ |
17 TypeName(const TypeName&) = delete | 19 TypeName(const TypeName&) = delete |
18 | 20 |
19 // Put this in the declarations for a class to be unassignable. | 21 // Put this in the declarations for a class to be unassignable. |
20 #define DISALLOW_ASSIGN(TypeName) \ | 22 #define DISALLOW_ASSIGN(TypeName) \ |
21 void operator=(const TypeName&) = delete | 23 void operator=(const TypeName&) = delete |
22 | 24 |
23 // A macro to disallow the copy constructor and operator= functions | 25 // A macro to disallow the copy constructor and operator= functions. |
24 // This should be used in the private: declarations for a class | 26 // This should be used in the private: declarations for a class. |
27 // TODO(pkasting): Using "= delete" is Linux-specific initially to prevent | |
28 // cross-platform code from regressing while other platforms are fixed. Remove | |
29 // the ifdefs here and use "= delete" on all platforms. | |
30 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
Nico
2016/05/26 00:40:10
if you want you can add defined(CHROMIUM_BUILD) to
| |
31 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
32 TypeName(const TypeName&) = delete; \ | |
33 void operator=(const TypeName&) = delete | |
34 #else | |
25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 35 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
26 TypeName(const TypeName&); \ | 36 TypeName(const TypeName&); \ |
27 void operator=(const TypeName&) | 37 void operator=(const TypeName&) |
38 #endif | |
28 | 39 |
29 // A macro to disallow all the implicit constructors, namely the | 40 // A macro to disallow all the implicit constructors, namely the |
30 // default constructor, copy constructor and operator= functions. | 41 // default constructor, copy constructor and operator= functions. |
31 // | 42 // |
32 // This should be used in the private: declarations for a class | 43 // This should be used in the private: declarations for a class |
33 // that wants to prevent anyone from instantiating it. This is | 44 // that wants to prevent anyone from instantiating it. This is |
34 // especially useful for classes containing only static methods. | 45 // especially useful for classes containing only static methods. |
35 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 46 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
36 TypeName() = delete; \ | 47 TypeName() = delete; \ |
37 DISALLOW_COPY_AND_ASSIGN(TypeName) | 48 DISALLOW_COPY_AND_ASSIGN(TypeName) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 | 89 |
79 // Use these to declare and define a static local variable (static T;) so that | 90 // Use these to declare and define a static local variable (static T;) so that |
80 // it is leaked so that its destructors are not called at exit. If you need | 91 // it is leaked so that its destructors are not called at exit. If you need |
81 // thread-safe initialization, use base/lazy_instance.h instead. | 92 // thread-safe initialization, use base/lazy_instance.h instead. |
82 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 93 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
83 static type& name = *new type arguments | 94 static type& name = *new type arguments |
84 | 95 |
85 } // base | 96 } // base |
86 | 97 |
87 #endif // BASE_MACROS_H_ | 98 #endif // BASE_MACROS_H_ |
OLD | NEW |