| 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 #if defined(OS_LINUX) |
| 25 // A macro to disallow the copy constructor and operator= functions. |
| 26 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
| 27 TypeName(const TypeName&) = delete; \ |
| 28 void operator=(const TypeName&) = delete |
| 29 #else |
| 24 // A macro to disallow the copy constructor and operator= functions | 30 // A macro to disallow the copy constructor and operator= functions |
| 25 // This should be used in the private: declarations for a class | 31 // This should be used in the private: declarations for a class |
| 26 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 32 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
| 27 TypeName(const TypeName&); \ | 33 TypeName(const TypeName&); \ |
| 28 void operator=(const TypeName&) | 34 void operator=(const TypeName&) |
| 35 #endif |
| 29 | 36 |
| 30 // A macro to disallow all the implicit constructors, namely the | 37 // A macro to disallow all the implicit constructors, namely the |
| 31 // default constructor, copy constructor and operator= functions. | 38 // default constructor, copy constructor and operator= functions. |
| 32 // | |
| 33 // This should be used in the private: declarations for a class | |
| 34 // that wants to prevent anyone from instantiating it. This is | |
| 35 // especially useful for classes containing only static methods. | |
| 36 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 39 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
| 37 TypeName() = delete; \ | 40 TypeName() = delete; \ |
| 38 DISALLOW_COPY_AND_ASSIGN(TypeName) | 41 DISALLOW_COPY_AND_ASSIGN(TypeName) |
| 39 | 42 |
| 40 // The arraysize(arr) macro returns the # of elements in an array arr. The | 43 // The arraysize(arr) macro returns the # of elements in an array arr. The |
| 41 // expression is a compile-time constant, and therefore can be used in defining | 44 // expression is a compile-time constant, and therefore can be used in defining |
| 42 // new arrays, for example. If you use arraysize on a pointer by mistake, you | 45 // new arrays, for example. If you use arraysize on a pointer by mistake, you |
| 43 // will get a compile-time error. For the technical details, refer to | 46 // will get a compile-time error. For the technical details, refer to |
| 44 // http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx. | 47 // http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx. |
| 45 | 48 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 146 |
| 144 // Use these to declare and define a static local variable (static T;) so that | 147 // Use these to declare and define a static local variable (static T;) so that |
| 145 // it is leaked so that its destructors are not called at exit. If you need | 148 // it is leaked so that its destructors are not called at exit. If you need |
| 146 // thread-safe initialization, use base/lazy_instance.h instead. | 149 // thread-safe initialization, use base/lazy_instance.h instead. |
| 147 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 150 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
| 148 static type& name = *new type arguments | 151 static type& name = *new type arguments |
| 149 | 152 |
| 150 } // base | 153 } // base |
| 151 | 154 |
| 152 #endif // BASE_MACROS_H_ | 155 #endif // BASE_MACROS_H_ |
| OLD | NEW |