Apollo 10.0
自动驾驶开放平台
macros.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17// Commonly-used macro definitions. Some of them are copied from
18// https://chromium.googlesource.com/chromium/src/base/+/master/macros.h
19
20#pragma once
21
22#include <cstddef>
23
24// Put this in the declarations for a class to be uncopyable.
25#define DISABLE_COPY(TypeName) TypeName(const TypeName &) = delete
26
27// Put this in the declarations for a class to be unassignable.
28#define DISABLE_ASSIGN(TypeName) void operator=(const TypeName &) = delete
29
30// A macro to disallow the copy constructor and operator= functions.
31// This should be used in the private: declarations for a class.
32#define DISABLE_COPY_AND_ASSIGN(TypeName) \
33 DISABLE_COPY(TypeName); \
34 DISABLE_ASSIGN(TypeName)
35
36// A macro to disallow all the implicit constructors, namely the
37// default constructor, copy constructor and operator= functions.
38//
39// This should be used in the private: declarations for a class
40// that wants to prevent anyone from instantiating it. This is
41// especially useful for classes containing only static methods.
42#define DISABLE_IMPLICIT_CONSTRUCTORS(TypeName) \
43 TypeName() = delete; \
44 DISABLE_COPY_AND_ASSIGN(TypeName)
45
46// Creates a thread-safe singleton.
47#define MAKE_SINGLETON(TypeName) \
48 public: \
49 static TypeName *Instance() { \
50 static TypeName Instance; \
51 return &Instance; \
52 } \
53 \
54 private: \
55 DISABLE_COPY_AND_ASSIGN(TypeName)
56
57namespace apollo {
58
59// array_size(a) returns the number of elements in a.
60template <class T, size_t N>
61constexpr size_t array_size(T (&)[N]) {
62 return N;
63}
64
65} // namespace apollo
class register implement
Definition arena_queue.h:37
constexpr size_t array_size(T(&)[N])
Definition macros.h:61