I've been meaning to do this for a very long time...
Change-Id: Ia8c16eee7c026c3c9505399948485fb778fb0152
#include <pthread.h>
+#include "private/bionic_macros.h"
#include "pthread_internal.h"
class pthread_accessor {
is_locked_ = true;
}
- // Disallow copy and assignment.
- pthread_accessor(const pthread_accessor&);
- void operator=(const pthread_accessor&);
+ DISALLOW_COPY_AND_ASSIGN(pthread_accessor);
};
#endif // PTHREAD_ACCESSOR_H
#include <errno.h>
#include <stdlib.h>
+#include "private/bionic_macros.h"
#include "private/ScopedReaddir.h"
// A smart pointer to the scandir dirent**.
return copy;
}
- // Disallow copy and assignment.
- ScandirResult(const ScandirResult&);
- void operator=(const ScandirResult&);
+ DISALLOW_COPY_AND_ASSIGN(ScandirResult);
};
int scandir(const char* dirname, dirent*** name_list,
#include <sys/atomics.h>
#include "private/bionic_atomic_inline.h"
+#include "private/bionic_macros.h"
#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
}
private:
- // Disallow copy and assign.
- prop_bt(const prop_bt&);
- prop_bt& operator=(const prop_bt&);
+ DISALLOW_COPY_AND_ASSIGN(prop_bt);
};
struct prop_area {
}
private:
- // Disallow copy and assign.
- prop_area(const prop_area&);
- prop_area& operator=(const prop_area&);
+ DISALLOW_COPY_AND_ASSIGN(prop_area);
};
struct prop_info {
ANDROID_MEMBAR_FULL();
}
private:
- // Disallow copy and assign.
- prop_info(const prop_info&);
- prop_info& operator=(const prop_info&);
+ DISALLOW_COPY_AND_ASSIGN(prop_info);
};
struct find_nth_cookie {
#include <errno.h>
+#include "bionic_macros.h"
+
class ErrnoRestorer {
public:
explicit ErrnoRestorer() : saved_errno_(errno) {
private:
int saved_errno_;
- // Disallow copy and assignment.
- ErrnoRestorer(const ErrnoRestorer&);
- void operator=(const ErrnoRestorer&);
+ DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer);
};
#endif // ERRNO_RESTORER_H
#include <stdint.h>
#include <sys/auxv.h>
+#include "private/bionic_macros.h"
+
struct abort_msg_t;
// When the kernel starts the dynamic linker, it passes a pointer to a block
abort_msg_t** abort_message_ptr;
private:
- // Disallow copy and assignment.
- KernelArgumentBlock(const KernelArgumentBlock&);
- void operator=(const KernelArgumentBlock&);
+ DISALLOW_COPY_AND_ASSIGN(KernelArgumentBlock);
};
#endif // KERNEL_ARGUMENT_BLOCK_H
#include <pthread.h>
+#include "bionic_macros.h"
+
class ScopedPthreadMutexLocker {
public:
explicit ScopedPthreadMutexLocker(pthread_mutex_t* mu) : mu_(mu) {
private:
pthread_mutex_t* mu_;
- // Disallow copy and assignment.
- ScopedPthreadMutexLocker(const ScopedPthreadMutexLocker&);
- void operator=(const ScopedPthreadMutexLocker&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLocker);
};
#endif // SCOPED_PTHREAD_MUTEX_LOCKER_H
#include <dirent.h>
+#include "private/bionic_macros.h"
+
class ScopedReaddir {
public:
ScopedReaddir(const char* path) {
private:
DIR* dir_;
- // Disallow copy and assignment.
- ScopedReaddir(const ScopedReaddir&);
- void operator=(const ScopedReaddir&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedReaddir);
};
#endif // SCOPED_READDIR_H
--- /dev/null
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_MACROS_H_
+#define _BIONIC_MACROS_H_
+
+// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.
+// It goes in the private: declarations in a class.
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&); \
+ void operator=(const TypeName&)
+
+// A macro to disallow all the implicit constructors, namely the
+// default constructor, copy constructor and operator= functions.
+//
+// This should be used in the private: declarations for a class
+// that wants to prevent anyone from instantiating it. This is
+// especially useful for classes containing only static methods.
+#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
+ TypeName(); \
+ DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+#endif // _BIONIC_MACROS_H_