henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_BASE_CONSTRUCTORMAGIC_H_ |
| 12 | #define WEBRTC_BASE_CONSTRUCTORMAGIC_H_ |
| 13 | |
henrike@webrtc.org | 680555f | 2014-06-27 15:49:02 +0000 | [diff] [blame] | 14 | // Undefine macros first, just in case. Some third-party includes have their own |
| 15 | // version. |
| 16 | |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 17 | // Put this in the declarations for a class to be unassignable. |
henrike@webrtc.org | 680555f | 2014-06-27 15:49:02 +0000 | [diff] [blame] | 18 | #undef DISALLOW_ASSIGN |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 19 | #define DISALLOW_ASSIGN(TypeName) \ |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 20 | void operator=(const TypeName&) = delete |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 21 | |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 22 | // A macro to disallow the copy constructor and operator= functions. This should |
| 23 | // be used in the declarations for a class. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 24 | #undef DISALLOW_COPY_AND_ASSIGN |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 25 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
| 26 | TypeName(const TypeName&) = delete; \ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 27 | DISALLOW_ASSIGN(TypeName) |
| 28 | |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 29 | // A macro to disallow all the implicit constructors, namely the default |
| 30 | // constructor, copy constructor and operator= functions. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 31 | // |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 32 | // This should be used in the declarations for a class that wants to prevent |
| 33 | // anyone from instantiating it. This is especially useful for classes |
| 34 | // containing only static methods. |
henrike@webrtc.org | 680555f | 2014-06-27 15:49:02 +0000 | [diff] [blame] | 35 | #undef DISALLOW_IMPLICIT_CONSTRUCTORS |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 36 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
henrikg | 0de8ff4 | 2015-09-09 23:43:40 -0700 | [diff] [blame^] | 37 | TypeName() = delete; \ |
Thiago Farina | ae0f0ee | 2015-04-04 23:56:53 +0000 | [diff] [blame] | 38 | DISALLOW_COPY_AND_ASSIGN(TypeName) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 39 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 40 | #endif // WEBRTC_BASE_CONSTRUCTORMAGIC_H_ |