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. 4 5#ifndef MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ 6#define MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ 7 8#include "mojo/public/c/system/macros.h" 9 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. 13 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 19#else 20#define MOJO_OVERRIDE 21#endif 22 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&) 28 29// Used to calculate the number of elements in an array. 30// (See |arraysize()| in Chromium's base/basictypes.h for more details.) 31namespace mojo { 32template <typename T, size_t N> 33char (&ArraySizeHelper(T (&array)[N]))[N]; 34#if !defined(_MSC_VER) 35template <typename T, size_t N> 36char (&ArraySizeHelper(const T (&array)[N]))[N]; 37#endif 38} // namespace mojo 39#define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array))) 40 41// Used to make a type move-only in C++03. See Chromium's base/move.h for more 42// details. 43#define MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \ 44 private: \ 45 struct rvalue_type { \ 46 explicit rvalue_type(type* object) : object(object) {} \ 47 type* object; \ 48 }; \ 49 type(type&); \ 50 void operator=(type&); \ 51 public: \ 52 operator rvalue_type() { return rvalue_type(this); } \ 53 type Pass() { return type(rvalue_type(this)); } \ 54 typedef void MoveOnlyTypeForCPP03; \ 55 private: 56 57#endif // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ 58