blob: 6971580507c0b6475e31075fb419f434beac8fb7 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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.org680555f2014-06-27 15:49:02 +000014// Undefine macros first, just in case. Some third-party includes have their own
15// version.
16
henrikg0de8ff42015-09-09 23:43:40 -070017// Put this in the declarations for a class to be unassignable.
henrike@webrtc.org680555f2014-06-27 15:49:02 +000018#undef DISALLOW_ASSIGN
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000019#define DISALLOW_ASSIGN(TypeName) \
henrikg0de8ff42015-09-09 23:43:40 -070020 void operator=(const TypeName&) = delete
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021
henrikg0de8ff42015-09-09 23:43:40 -070022// A macro to disallow the copy constructor and operator= functions. This should
23// be used in the declarations for a class.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000024#undef DISALLOW_COPY_AND_ASSIGN
henrikg0de8ff42015-09-09 23:43:40 -070025#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
26 TypeName(const TypeName&) = delete; \
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000027 DISALLOW_ASSIGN(TypeName)
28
henrikg0de8ff42015-09-09 23:43:40 -070029// A macro to disallow all the implicit constructors, namely the default
30// constructor, copy constructor and operator= functions.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000031//
henrikg0de8ff42015-09-09 23:43:40 -070032// 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.org680555f2014-06-27 15:49:02 +000035#undef DISALLOW_IMPLICIT_CONSTRUCTORS
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000036#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
henrikg0de8ff42015-09-09 23:43:40 -070037 TypeName() = delete; \
Thiago Farinaae0f0ee2015-04-04 23:56:53 +000038 DISALLOW_COPY_AND_ASSIGN(TypeName)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000039
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000040#endif // WEBRTC_BASE_CONSTRUCTORMAGIC_H_