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 #include <string.h> // For memcpy. | 14 #include <string.h> // For memcpy. |
15 | 15 |
16 // Put this in the declarations for a class to be uncopyable. | 16 // Put this in the declarations for a class to be uncopyable. |
17 #define DISALLOW_COPY(TypeName) \ | 17 #define DISALLOW_COPY(TypeName) \ |
18 TypeName(const TypeName&) = delete | 18 TypeName(const TypeName&) = delete |
19 | 19 |
20 // Put this in the declarations for a class to be unassignable. | 20 // Put this in the declarations for a class to be unassignable. |
21 #define DISALLOW_ASSIGN(TypeName) \ | 21 #define DISALLOW_ASSIGN(TypeName) \ |
22 void operator=(const TypeName&) = delete | 22 void operator=(const TypeName&) = delete |
23 | 23 |
24 // A macro to disallow the copy constructor and operator= functions | 24 // A macro to disallow the copy constructor and operator= functions |
25 // This should be used in the private: declarations for a class | 25 // This should be used in the private: declarations for a class |
26 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 26 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
27 TypeName(const TypeName&); \ | 27 TypeName(const TypeName&); \ |
28 void operator=(const TypeName&) | 28 void operator=(const TypeName&) |
29 | 29 |
30 // An older, deprecated, politically incorrect name for the above. | |
31 // NOTE: The usage of this macro was banned from our code base, but some | |
32 // third_party libraries are yet using it. | |
33 // TODO(tfarina): Figure out how to fix the usage of this macro in the | |
34 // third_party libraries and get rid of it. | |
35 #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) | |
36 | |
37 // A macro to disallow all the implicit constructors, namely the | 30 // A macro to disallow all the implicit constructors, namely the |
38 // default constructor, copy constructor and operator= functions. | 31 // default constructor, copy constructor and operator= functions. |
39 // | 32 // |
40 // This should be used in the private: declarations for a class | 33 // This should be used in the private: declarations for a class |
41 // that wants to prevent anyone from instantiating it. This is | 34 // that wants to prevent anyone from instantiating it. This is |
42 // especially useful for classes containing only static methods. | 35 // especially useful for classes containing only static methods. |
43 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 36 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
44 TypeName() = delete; \ | 37 TypeName() = delete; \ |
45 DISALLOW_COPY_AND_ASSIGN(TypeName) | 38 DISALLOW_COPY_AND_ASSIGN(TypeName) |
46 | 39 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 142 |
150 // Use these to declare and define a static local variable (static T;) so that | 143 // Use these to declare and define a static local variable (static T;) so that |
151 // it is leaked so that its destructors are not called at exit. If you need | 144 // it is leaked so that its destructors are not called at exit. If you need |
152 // thread-safe initialization, use base/lazy_instance.h instead. | 145 // thread-safe initialization, use base/lazy_instance.h instead. |
153 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 146 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
154 static type& name = *new type arguments | 147 static type& name = *new type arguments |
155 | 148 |
156 } // base | 149 } // base |
157 | 150 |
158 #endif // BASE_MACROS_H_ | 151 #endif // BASE_MACROS_H_ |
OLD | NEW |