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
3 // found in the LICENSE file.
5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_
8 #include "mojo/public/c/system/macros.h"
10 // Define a set of C++ specific macros.
11 // Mojo C++ API users can assume that mojo/public/cpp/system/macros.h
12 // includes mojo/public/c/system/macros.h.
14 // Annotate a virtual method indicating it must be overriding a virtual method
15 // in the parent class. Use like:
16 // virtual void foo() OVERRIDE;
17 #if defined(_MSC_VER) || defined(__clang__)
18 #define MOJO_OVERRIDE override
23 // A macro to disallow the copy constructor and operator= functions.
24 // This should be used in the private: declarations for a class.
25 #define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \
26 TypeName(const TypeName&); \
27 void operator=(const TypeName&)
29 // Used to calculate the number of elements in an array.
30 // (See |arraysize()| in Chromium's base/basictypes.h for more details.)
32 template <typename T
, size_t N
>
33 char (&ArraySizeHelper(T (&array
)[N
]))[N
];
34 #if !defined(_MSC_VER)
35 template <typename T
, size_t N
>
36 char (&ArraySizeHelper(const T (&array
)[N
]))[N
];
39 #define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array)))
41 // Used to make a type move-only in C++03. See Chromium's base/move.h for more
43 #define MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \
45 struct rvalue_type { \
46 explicit rvalue_type(type* object) : object(object) {} \
50 void operator=(type&); \
52 operator rvalue_type() { return rvalue_type(this); } \
53 type Pass() { return type(rvalue_type(this)); } \
54 typedef void MoveOnlyTypeForCPP03; \
57 #endif // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_