bionic_macros.h revision 0b13f29b2cc88e389bb85378c81ccc352361466d
18eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes/* 28eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Copyright (C) 2010 The Android Open Source Project 38eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * 48eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 58eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * you may not use this file except in compliance with the License. 68eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * You may obtain a copy of the License at 78eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * 88eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 98eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * 108eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Unless required by applicable law or agreed to in writing, software 118eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 128eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * See the License for the specific language governing permissions and 148eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * limitations under the License. 158eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes */ 168eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes 178eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#ifndef _BIONIC_MACROS_H_ 188eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define _BIONIC_MACROS_H_ 198eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes 2000bbc7f69f8b3fc2c37cc0f991a3ce03d801150fAndreas Gampe// Frameworks OpenGL code currently leaks this header and allows 2100bbc7f69f8b3fc2c37cc0f991a3ce03d801150fAndreas Gampe// collisions with other declarations, e.g., from libnativehelper. 2200bbc7f69f8b3fc2c37cc0f991a3ce03d801150fAndreas Gampe// TODO: Remove once cleaned up. b/18334516 2300bbc7f69f8b3fc2c37cc0f991a3ce03d801150fAndreas Gampe#if !defined(DISALLOW_COPY_AND_ASSIGN) 248eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. 258eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// It goes in the private: declarations in a class. 268eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 27d9ff7226613014056c9edd79a68dc5af939107a0Dmitriy Ivanov TypeName(const TypeName&) = delete; \ 28d9ff7226613014056c9edd79a68dc5af939107a0Dmitriy Ivanov void operator=(const TypeName&) = delete 2900bbc7f69f8b3fc2c37cc0f991a3ce03d801150fAndreas Gampe#endif // !defined(DISALLOW_COPY_AND_ASSIGN) 308eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes 318eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// A macro to disallow all the implicit constructors, namely the 328eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// default constructor, copy constructor and operator= functions. 338eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// 348eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// This should be used in the private: declarations for a class 358eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// that wants to prevent anyone from instantiating it. This is 368eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// especially useful for classes containing only static methods. 378eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 38d9ff7226613014056c9edd79a68dc5af939107a0Dmitriy Ivanov TypeName() = delete; \ 398eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes DISALLOW_COPY_AND_ASSIGN(TypeName) 408eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes 4103eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris#define BIONIC_ALIGN(value, alignment) \ 4203eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris (((value) + (alignment) - 1) & ~((alignment) - 1)) 4303eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris 4403eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris#define BIONIC_ROUND_UP_POWER_OF_2(value) \ 450b13f29b2cc88e389bb85378c81ccc352361466dChristopher Ferris ((sizeof(value) == 8) \ 4627047faf283cb9d3d025a984cd9934fd2c404407Christopher Ferris ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \ 470b13f29b2cc88e389bb85378c81ccc352361466dChristopher Ferris : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value))))) 4803eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris 498eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#endif // _BIONIC_MACROS_H_ 50