FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fpl_common.h
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPL_COMMON_H
16 #define FPL_COMMON_H
17 
18 namespace fplbase {
19 
20 // A macro to disallow the copy constructor and operator= functions
21 // This should be used in the private: declarations for a class
22 //
23 // For disallowing only assign or copy, write the code directly, but declare
24 // the intend in a comment, for example:
25 // void operator=(const TypeName&); // DISALLOW_ASSIGN
26 // Note, that most uses of DISALLOW_ASSIGN and DISALLOW_COPY are broken
27 // semantically, one should either use disallow both or neither. Try to
28 // avoid these in new code.
29 #define FPL_DISALLOW_COPY_AND_ASSIGN(TypeName) \
30  TypeName(const TypeName&); \
31  void operator=(const TypeName&)
32 
33 // Return the number of elements in an array 'a', as type `size_t`.
34 // If 'a' is not an array, generates an error by dividing by zero.
35 #define FPL_ARRAYSIZE(a) \
36  ((sizeof(a) / sizeof(*(a))) / \
37  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
38 
39 // Clang generates warnings if the fallthrough attribute is not specified.
40 #if defined(__clang__) && defined(__has_warning)
41 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
42 #define FPL_FALLTHROUGH_INTENDED [[clang::fallthrough]]; // NOLINT
43 #endif
44 #endif
45 #if !defined(FPL_FALLTHROUGH_INTENDED)
46 #define FPL_FALLTHROUGH_INTENDED
47 #endif
48 
49 } // namespace fplbase
50 
51 #endif // FPL_COMMON_H