Home | History | Annotate | Download | only in system
      1 // Copyright 2013 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 // Annotate a virtual method indicating it must be overriding a virtual method
     11 // in the parent class. Use like:
     12 //   virtual void foo() OVERRIDE;
     13 #if defined(_MSC_VER) || defined(__clang__)
     14 #define MOJO_OVERRIDE override
     15 #else
     16 #define MOJO_OVERRIDE
     17 #endif
     18 
     19 // A macro to disallow the copy constructor and operator= functions.
     20 // This should be used in the private: declarations for a class.
     21 #define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \
     22     TypeName(const TypeName&); \
     23     void operator=(const TypeName&)
     24 
     25 // Used to calculate the number of elements in an array.
     26 // (See |arraysize()| in Chromium's base/basictypes.h for more details.)
     27 namespace mojo {
     28 template <typename T, size_t N>
     29 char (&ArraySizeHelper(T (&array)[N]))[N];
     30 #if !defined(_MSC_VER)
     31 template <typename T, size_t N>
     32 char (&ArraySizeHelper(const T (&array)[N]))[N];
     33 #endif
     34 }  // namespace mojo
     35 #define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array)))
     36 
     37 // Used to make a type move-only in C++03. See Chromium's base/move.h for more
     38 // details.
     39 #define MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \
     40    private: \
     41     struct rvalue_type { \
     42       explicit rvalue_type(type* object) : object(object) {} \
     43       type* object; \
     44     }; \
     45     type(type&); \
     46     void operator=(type&); \
     47    public: \
     48     operator rvalue_type() { return rvalue_type(this); } \
     49     type Pass() { return type(rvalue_type(this)); } \
     50     typedef void MoveOnlyTypeForCPP03; \
     51    private:
     52 
     53 #endif  // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_
     54