Usage suggestions.

Providing alternative suggestions for using C++ stdlib types
instead of libutils types:
- higher interoperability
- fewer "legacy" quirks
- ability to use stl algorithms
- high optimization levels

Test: none
Change-Id: If81aa9982ca0ad229fa13c8142387906981b054d
This commit is contained in:
Steven Moreland 2017-12-18 16:14:13 -08:00
parent 3fca67514a
commit b8f152d3e2
15 changed files with 36 additions and 3 deletions

View file

@ -17,6 +17,8 @@
#ifndef ANDROID_UTILS_ATOMIC_H
#define ANDROID_UTILS_ATOMIC_H
// DO NOT USE: Please instead use std::atomic
#include <cutils/atomic.h>
#endif // ANDROID_UTILS_ATOMIC_H

View file

@ -22,6 +22,8 @@
/*
* Contains some bit manipulation helpers.
*
* DO NOT USE: std::bitset<32> or std::bitset<64> preferred
*/
namespace android {

View file

@ -34,6 +34,8 @@
namespace android {
// ---------------------------------------------------------------------------
// DO NOT USE: please use std::condition_variable instead.
/*
* Condition variable class. The implementation is system-dependent.
*

View file

@ -29,6 +29,8 @@ template<> struct CompileTimeAssert<true> {};
#define COMPILE_TIME_ASSERT(_exp) \
template class CompileTimeAssert< (_exp) >;
#endif
// DO NOT USE: Please use static_assert instead
#define COMPILE_TIME_ASSERT_FUNCTION_SCOPE(_exp) \
CompileTimeAssert<( _exp )>();

View file

@ -33,13 +33,13 @@ class FlattenableUtils {
public:
template<size_t N>
static size_t align(size_t size) {
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) );
static_assert(!(N & (N - 1)), "Can only align to a power of 2.");
return (size + (N-1)) & ~(N-1);
}
template<size_t N>
static size_t align(void const*& buffer) {
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) );
static_assert(!(N & (N - 1)), "Can only align to a power of 2.");
uintptr_t b = uintptr_t(buffer);
buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1));
return size_t(uintptr_t(buffer) - b);

View file

@ -21,6 +21,10 @@
namespace android {
// DO NOT USE: please use
// - C++ lambda
// - class with well-defined and specific functionality and semantics
class Functor {
public:
Functor() {}

View file

@ -30,6 +30,8 @@
namespace android {
// DO NOT USE: please use std::map
template <typename KEY, typename VALUE>
class KeyedVector
{

View file

@ -37,6 +37,8 @@ namespace android {
*
* Objects added to the list are copied using the assignment operator,
* so this must be defined.
*
* DO NOT USE: please use std::list<T>
*/
template<typename T>
class List

View file

@ -39,6 +39,11 @@ namespace android {
#pragma clang diagnostic ignored "-Wundefined-var-template"
#endif
// DO NOT USE: Please use scoped static initialization. For instance:
// MyClass& getInstance() {
// static MyClass gInstance(...);
// return gInstance;
// }
template <typename TYPE>
class ANDROID_API Singleton
{

View file

@ -30,6 +30,8 @@
namespace android {
// DO NOT USE: please use std::set
template <class TYPE>
class SortedVector : private SortedVectorImpl
{

View file

@ -37,6 +37,8 @@ namespace android {
class String8;
// DO NOT USE: please use std::u16string
//! This is a string holding UTF-16 characters.
class String16
{

View file

@ -32,6 +32,8 @@ namespace android {
class String16;
// DO NOT USE: please use std::string
//! This is a string holding UTF-8 characters. Does not allow the value more
// than 0x10FFFF, which is not valid unicode codepoint.
class String8

View file

@ -36,6 +36,8 @@
namespace android {
// ---------------------------------------------------------------------------
// DO NOT USE: please use std::thread
class Thread : virtual public RefBase
{
public:

View file

@ -49,6 +49,8 @@ class SortedVector;
* The main templated vector class ensuring type safety
* while making use of VectorImpl.
* This is the class users want to use.
*
* DO NOT USE: please use std::vector
*/
template <class TYPE>

View file

@ -22,7 +22,9 @@
#include <utils/Endian.h>
/* get #of elements in a static array */
/* get #of elements in a static array
* DO NOT USE: please use std::vector/std::array instead
*/
#ifndef NELEM
# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif