1 /* Copyright (c) 2012 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 LIBRARIES_SDK_UTIL_MACROS_H_
6 #define LIBRARIES_SDK_UTIL_MACROS_H_
7 
8 /**
9  * A macro to disallow the evil copy constructor and operator= functions
10  * This should be used in the private: declarations for a class.
11  */
12 #ifndef DISALLOW_COPY_AND_ASSIGN
13 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
14   TypeName(const TypeName&);               \
15   void operator=(const TypeName&)
16 #endif
17 
18 /** returns the size of a member of a struct. */
19 #define MEMBER_SIZE(struct_name, member) sizeof(((struct_name*)0)->member)
20 
21 /**
22  * Macros to prevent name mangling of definitions, allowing them to be
23  * referenced from C.
24  */
25 #ifdef __cplusplus
26 # define EXTERN_C_BEGIN  extern "C" {
27 # define EXTERN_C_END    }
28 #else
29 # define EXTERN_C_BEGIN
30 # define EXTERN_C_END
31 #endif  /* __cplusplus */
32 
33 /**
34  * Macro to error out when a printf-like function is passed incorrect arguments.
35  *
36  * Use like this:
37  * void foo(const char* fmt, ...) PRINTF_LIKE(1, 2);
38  *
39  * The first argument is the location of the fmt string (1-based).
40  * The second argument is the location of the first argument to validate (also
41  *   1-based, but can be zero if the function uses a va_list, like vprintf.)
42  */
43 #if defined(__GNUC__)
44 #define PRINTF_LIKE(a, b) __attribute__ ((format(printf, a, b)))
45 #else
46 #define PRINTF_LIKE(a, b)
47 #endif
48 
49 #endif  /* LIBRARIES_SDK_UTIL_MACROS_H_ */
50