diff options
| author | Ian Rogers <irogers@google.com> | 2014-11-04 22:18:31 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-11-04 22:18:32 +0000 |
| commit | b99e26cde99d4dbdcc8411369d56c5c080526fcb (patch) | |
| tree | 62efd7244a969050e7d1872f7cd7c41a95f91d33 | |
| parent | 221e49a1ca260781ecdabdfa106d2e47d444e6de (diff) | |
| parent | 8288ddeb1bed3dca35c7e182f769c62e1f2a18fd (diff) | |
| download | platform_libnativehelper-b99e26cde99d4dbdcc8411369d56c5c080526fcb.tar.gz platform_libnativehelper-b99e26cde99d4dbdcc8411369d56c5c080526fcb.tar.bz2 platform_libnativehelper-b99e26cde99d4dbdcc8411369d56c5c080526fcb.zip | |
Merge "Add DISALLOW_COPY_AND_ASSIGN macro."
| -rw-r--r-- | JNIHelp.cpp | 6 | ||||
| -rw-r--r-- | include/nativehelper/JNIHelp.h | 14 | ||||
| -rw-r--r-- | include/nativehelper/ScopedBytes.h | 8 | ||||
| -rw-r--r-- | include/nativehelper/ScopedFd.h | 4 | ||||
| -rw-r--r-- | include/nativehelper/ScopedLocalFrame.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedLocalRef.h | 7 | ||||
| -rw-r--r-- | include/nativehelper/ScopedPrimitiveArray.h | 10 | ||||
| -rw-r--r-- | include/nativehelper/ScopedStringChars.h | 8 | ||||
| -rw-r--r-- | include/nativehelper/ScopedUtfChars.h | 8 | ||||
| -rw-r--r-- | include/nativehelper/UniquePtr.h | 9 |
10 files changed, 38 insertions, 42 deletions
diff --git a/JNIHelp.cpp b/JNIHelp.cpp index 9de3dfc..49c4f94 100644 --- a/JNIHelp.cpp +++ b/JNIHelp.cpp @@ -59,12 +59,10 @@ public: } private: - C_JNIEnv* mEnv; + C_JNIEnv* const mEnv; T mLocalRef; - // Disallow copy and assignment. - scoped_local_ref(const scoped_local_ref&); - void operator=(const scoped_local_ref&); + DISALLOW_COPY_AND_ASSIGN(scoped_local_ref); }; static jclass findClass(C_JNIEnv* env, const char* className) { diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h index cfab8f7..bf01986 100644 --- a/include/nativehelper/JNIHelp.h +++ b/include/nativehelper/JNIHelp.h @@ -172,6 +172,20 @@ inline void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowab jniLogException(&env->functions, priority, tag, exception); } +#if !defined(DISALLOW_COPY_AND_ASSIGN) +// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private: +// declarations in a class. +#if __cplusplus >= 201103L +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete +#else +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) +#endif // __has_feature(cxx_deleted_functions) +#endif // !defined(DISALLOW_COPY_AND_ASSIGN) + #endif /* diff --git a/include/nativehelper/ScopedBytes.h b/include/nativehelper/ScopedBytes.h index cb2614b..fec46e8 100644 --- a/include/nativehelper/ScopedBytes.h +++ b/include/nativehelper/ScopedBytes.h @@ -48,17 +48,15 @@ public: } private: - JNIEnv* mEnv; - jobject mObject; + JNIEnv* const mEnv; + const jobject mObject; jbyteArray mByteArray; protected: jbyte* mPtr; private: - // Disallow copy and assignment. - ScopedBytes(const ScopedBytes&); - void operator=(const ScopedBytes&); + DISALLOW_COPY_AND_ASSIGN(ScopedBytes); }; class ScopedBytesRO : public ScopedBytes<true> { diff --git a/include/nativehelper/ScopedFd.h b/include/nativehelper/ScopedFd.h index 795f50c..adf67c0 100644 --- a/include/nativehelper/ScopedFd.h +++ b/include/nativehelper/ScopedFd.h @@ -52,9 +52,7 @@ public: private: int fd; - // Disallow copy and assignment. - ScopedFd(const ScopedFd&); - void operator=(const ScopedFd&); + DISALLOW_COPY_AND_ASSIGN(ScopedFd); }; #endif // SCOPED_FD_H_included diff --git a/include/nativehelper/ScopedLocalFrame.h b/include/nativehelper/ScopedLocalFrame.h index 35b6ad8..b739e24 100644 --- a/include/nativehelper/ScopedLocalFrame.h +++ b/include/nativehelper/ScopedLocalFrame.h @@ -30,11 +30,9 @@ public: } private: - JNIEnv* mEnv; + JNIEnv* const mEnv; - // Disallow copy and assignment. - ScopedLocalFrame(const ScopedLocalFrame&); - void operator=(const ScopedLocalFrame&); + DISALLOW_COPY_AND_ASSIGN(ScopedLocalFrame); }; #endif // SCOPED_LOCAL_FRAME_H_included diff --git a/include/nativehelper/ScopedLocalRef.h b/include/nativehelper/ScopedLocalRef.h index 71d5776..6e30eb3 100644 --- a/include/nativehelper/ScopedLocalRef.h +++ b/include/nativehelper/ScopedLocalRef.h @@ -20,6 +20,7 @@ #include "jni.h" #include <stddef.h> +#include "JNIHelp.h" // for DISALLOW_COPY_AND_ASSIGN. // A smart pointer that deletes a JNI local reference when it goes out of scope. template<typename T> @@ -52,12 +53,10 @@ public: } private: - JNIEnv* mEnv; + JNIEnv* const mEnv; T mLocalRef; - // Disallow copy and assignment. - ScopedLocalRef(const ScopedLocalRef&); - void operator=(const ScopedLocalRef&); + DISALLOW_COPY_AND_ASSIGN(ScopedLocalRef); }; #endif // SCOPED_LOCAL_REF_H_included diff --git a/include/nativehelper/ScopedPrimitiveArray.h b/include/nativehelper/ScopedPrimitiveArray.h index d797b9d..b573bd6 100644 --- a/include/nativehelper/ScopedPrimitiveArray.h +++ b/include/nativehelper/ScopedPrimitiveArray.h @@ -50,11 +50,10 @@ const PRIMITIVE_TYPE& operator[](size_t n) const { return mRawArray[n]; } \ size_t size() const { return mEnv->GetArrayLength(mJavaArray); } \ private: \ - JNIEnv* mEnv; \ + JNIEnv* const mEnv; \ PRIMITIVE_TYPE ## Array mJavaArray; \ PRIMITIVE_TYPE* mRawArray; \ - Scoped ## NAME ## ArrayRO(const Scoped ## NAME ## ArrayRO&); \ - void operator=(const Scoped ## NAME ## ArrayRO&); \ + DISALLOW_COPY_AND_ASSIGN(Scoped ## NAME ## ArrayRO); \ } INSTANTIATE_SCOPED_PRIMITIVE_ARRAY_RO(jboolean, Boolean); @@ -101,11 +100,10 @@ INSTANTIATE_SCOPED_PRIMITIVE_ARRAY_RO(jshort, Short); PRIMITIVE_TYPE& operator[](size_t n) { return mRawArray[n]; } \ size_t size() const { return mEnv->GetArrayLength(mJavaArray); } \ private: \ - JNIEnv* mEnv; \ + JNIEnv* const mEnv; \ PRIMITIVE_TYPE ## Array mJavaArray; \ PRIMITIVE_TYPE* mRawArray; \ - Scoped ## NAME ## ArrayRW(const Scoped ## NAME ## ArrayRW&); \ - void operator=(const Scoped ## NAME ## ArrayRW&); \ + DISALLOW_COPY_AND_ASSIGN(Scoped ## NAME ## ArrayRW); \ } INSTANTIATE_SCOPED_PRIMITIVE_ARRAY_RW(jboolean, Boolean); diff --git a/include/nativehelper/ScopedStringChars.h b/include/nativehelper/ScopedStringChars.h index cfbd247..688291d 100644 --- a/include/nativehelper/ScopedStringChars.h +++ b/include/nativehelper/ScopedStringChars.h @@ -61,14 +61,12 @@ class ScopedStringChars { } private: - JNIEnv* env_; - jstring string_; + JNIEnv* const env_; + const jstring string_; const jchar* chars_; size_t size_; - // Disallow copy and assignment. - ScopedStringChars(const ScopedStringChars&); - void operator=(const ScopedStringChars&); + DISALLOW_COPY_AND_ASSIGN(ScopedStringChars); }; #endif // SCOPED_STRING_CHARS_H_included diff --git a/include/nativehelper/ScopedUtfChars.h b/include/nativehelper/ScopedUtfChars.h index 7761450..9cfa9a0 100644 --- a/include/nativehelper/ScopedUtfChars.h +++ b/include/nativehelper/ScopedUtfChars.h @@ -59,13 +59,11 @@ class ScopedUtfChars { } private: - JNIEnv* env_; - jstring string_; + JNIEnv* const env_; + const jstring string_; const char* utf_chars_; - // Disallow copy and assignment. - ScopedUtfChars(const ScopedUtfChars&); - void operator=(const ScopedUtfChars&); + DISALLOW_COPY_AND_ASSIGN(ScopedUtfChars); }; #endif // SCOPED_UTF_CHARS_H_included diff --git a/include/nativehelper/UniquePtr.h b/include/nativehelper/UniquePtr.h index 50f75b2..7890d52 100644 --- a/include/nativehelper/UniquePtr.h +++ b/include/nativehelper/UniquePtr.h @@ -18,6 +18,7 @@ #define UNIQUE_PTR_H_included #include <cstdlib> // For NULL. +#include "JNIHelp.h" // For DISALLOW_COPY_AND_ASSIGN. // This is a fake declaration of std::swap to avoid including <algorithm> namespace std { @@ -98,9 +99,7 @@ private: template <typename T2> bool operator==(const UniquePtr<T2>& p) const; template <typename T2> bool operator!=(const UniquePtr<T2>& p) const; - // Disallow copy and assignment. - UniquePtr(const UniquePtr&); - void operator=(const UniquePtr&); + DISALLOW_COPY_AND_ASSIGN(UniquePtr); }; // Partial specialization for array types. Like std::unique_ptr, this removes @@ -136,9 +135,7 @@ public: private: T* mPtr; - // Disallow copy and assignment. - UniquePtr(const UniquePtr&); - void operator=(const UniquePtr&); + DISALLOW_COPY_AND_ASSIGN(UniquePtr); }; #if UNIQUE_PTR_TESTS |
