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_ |
(...skipping 19 matching lines...) Expand all Loading... |
30 // A macro to disallow all the implicit constructors, namely the | 30 // A macro to disallow all the implicit constructors, namely the |
31 // default constructor, copy constructor and operator= functions. | 31 // default constructor, copy constructor and operator= functions. |
32 // | 32 // |
33 // This should be used in the private: declarations for a class | 33 // This should be used in the private: declarations for a class |
34 // that wants to prevent anyone from instantiating it. This is | 34 // that wants to prevent anyone from instantiating it. This is |
35 // especially useful for classes containing only static methods. | 35 // especially useful for classes containing only static methods. |
36 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 36 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
37 TypeName() = delete; \ | 37 TypeName() = delete; \ |
38 DISALLOW_COPY_AND_ASSIGN(TypeName) | 38 DISALLOW_COPY_AND_ASSIGN(TypeName) |
39 | 39 |
40 // The arraysize(arr) macro returns the # of elements in an array arr. | 40 // The arraysize(arr) macro returns the # of elements in an array arr. The |
41 // The expression is a compile-time constant, and therefore can be | 41 // expression is a compile-time constant, and therefore can be used in defining |
42 // used in defining new arrays, for example. If you use arraysize on | 42 // new arrays, for example. If you use arraysize on a pointer by mistake, you |
43 // a pointer by mistake, you will get a compile-time error. | 43 // 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. |
44 | 45 |
45 // This template function declaration is used in defining arraysize. | 46 // This template function declaration is used in defining arraysize. |
46 // Note that the function doesn't need an implementation, as we only | 47 // Note that the function doesn't need an implementation, as we only |
47 // use its type. | 48 // use its type. |
48 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; | 49 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; |
49 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 50 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
50 | 51 |
51 // bit_cast<Dest,Source> is a template function that implements the | 52 // bit_cast<Dest,Source> is a template function that implements the |
52 // equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in | 53 // equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in |
53 // very low-level functions like the protobuf library and fast math | 54 // very low-level functions like the protobuf library and fast math |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 143 |
143 // Use these to declare and define a static local variable (static T;) so that | 144 // Use these to declare and define a static local variable (static T;) so that |
144 // it is leaked so that its destructors are not called at exit. If you need | 145 // it is leaked so that its destructors are not called at exit. If you need |
145 // thread-safe initialization, use base/lazy_instance.h instead. | 146 // thread-safe initialization, use base/lazy_instance.h instead. |
146 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 147 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
147 static type& name = *new type arguments | 148 static type& name = *new type arguments |
148 | 149 |
149 } // base | 150 } // base |
150 | 151 |
151 #endif // BASE_MACROS_H_ | 152 #endif // BASE_MACROS_H_ |
OLD | NEW |