/src/mozilla-central/security/pkix/lib/ScopedPtr.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This code is made available to you under your choice of the following sets |
4 | | * of licensing terms: |
5 | | */ |
6 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
9 | | */ |
10 | | /* Copyright 2013 Mozilla Contributors |
11 | | * |
12 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
13 | | * you may not use this file except in compliance with the License. |
14 | | * You may obtain a copy of the License at |
15 | | * |
16 | | * http://www.apache.org/licenses/LICENSE-2.0 |
17 | | * |
18 | | * Unless required by applicable law or agreed to in writing, software |
19 | | * distributed under the License is distributed on an "AS IS" BASIS, |
20 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
21 | | * See the License for the specific language governing permissions and |
22 | | * limitations under the License. |
23 | | */ |
24 | | |
25 | | #ifndef mozilla_pkix_ScopedPtr_h |
26 | | #define mozilla_pkix_ScopedPtr_h |
27 | | |
28 | | namespace mozilla { namespace pkix { |
29 | | |
30 | | // A subset polyfill of std::unique_ptr that does not support move construction |
31 | | // or move assignment. This is used instead of std::unique_ptr because some |
32 | | // important toolchains still don't provide std::unique_ptr, including in |
33 | | // particular Android NDK projects with APP_STL=stlport_static or |
34 | | // ALL_STL=stlport_shared. |
35 | | template <typename T, void (&Destroyer)(T*)> |
36 | | class ScopedPtr final |
37 | | { |
38 | | public: |
39 | 6 | explicit ScopedPtr(T* value = nullptr) : mValue(value) { } Unexecuted instantiation: mozilla::pkix::ScopedPtr<CERTSubjectPublicKeyInfoStr, SECKEY_DestroySubjectPublicKeyInfo>::ScopedPtr(CERTSubjectPublicKeyInfoStr*) Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPublicKeyStr, SECKEY_DestroyPublicKey>::ScopedPtr(SECKEYPublicKeyStr*) mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::ScopedPtr(mozilla::pkix::test::TestKeyPair*) Line | Count | Source | 39 | 6 | explicit ScopedPtr(T* value = nullptr) : mValue(value) { } |
Unexecuted instantiation: pkixocsp_VerifyEncodedOCSPResponse.cpp:mozilla::pkix::ScopedPtr<mozilla::pkix::CertID, (anonymous namespace)::deleteCertID(mozilla::pkix::CertID*)>::ScopedPtr(mozilla::pkix::CertID*) Unexecuted instantiation: mozilla::pkix::ScopedPtr<PK11SlotInfoStr, PK11_FreeSlot>::ScopedPtr(PK11SlotInfoStr*) Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPrivateKeyStr, SECKEY_DestroyPrivateKey>::ScopedPtr(SECKEYPrivateKeyStr*) Unexecuted instantiation: pkixtestnss.cpp:mozilla::pkix::ScopedPtr<SECKEYEncryptedPrivateKeyInfoStr, mozilla::pkix::test::(anonymous namespace)::SECKEY_DestroyEncryptedPrivateKeyInfo_true(SECKEYEncryptedPrivateKeyInfoStr*)>::ScopedPtr(SECKEYEncryptedPrivateKeyInfoStr*) Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::ScopedPtr(_IO_FILE*) |
40 | | |
41 | | ScopedPtr(const ScopedPtr&) = delete; |
42 | | |
43 | | ~ScopedPtr() |
44 | 0 | { |
45 | 0 | if (mValue) { |
46 | 0 | Destroyer(mValue); |
47 | 0 | } |
48 | 0 | } Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPublicKeyStr, SECKEY_DestroyPublicKey>::~ScopedPtr() Unexecuted instantiation: mozilla::pkix::ScopedPtr<CERTSubjectPublicKeyInfoStr, SECKEY_DestroySubjectPublicKeyInfo>::~ScopedPtr() Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::~ScopedPtr() Unexecuted instantiation: pkixocsp_VerifyEncodedOCSPResponse.cpp:mozilla::pkix::ScopedPtr<mozilla::pkix::CertID, (anonymous namespace)::deleteCertID(mozilla::pkix::CertID*)>::~ScopedPtr() Unexecuted instantiation: mozilla::pkix::ScopedPtr<PK11SlotInfoStr, PK11_FreeSlot>::~ScopedPtr() Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPrivateKeyStr, SECKEY_DestroyPrivateKey>::~ScopedPtr() Unexecuted instantiation: pkixtestnss.cpp:mozilla::pkix::ScopedPtr<SECKEYEncryptedPrivateKeyInfoStr, mozilla::pkix::test::(anonymous namespace)::SECKEY_DestroyEncryptedPrivateKeyInfo_true(SECKEYEncryptedPrivateKeyInfoStr*)>::~ScopedPtr() Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::~ScopedPtr() |
49 | | |
50 | | void operator=(const ScopedPtr&) = delete; |
51 | | |
52 | 0 | T& operator*() const { return *mValue; } Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::operator*() const Unexecuted instantiation: pkixocsp_VerifyEncodedOCSPResponse.cpp:mozilla::pkix::ScopedPtr<mozilla::pkix::CertID, (anonymous namespace)::deleteCertID(mozilla::pkix::CertID*)>::operator*() const |
53 | 0 | T* operator->() const { return mValue; } Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::operator->() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<CERTSubjectPublicKeyInfoStr, SECKEY_DestroySubjectPublicKeyInfo>::operator->() const Unexecuted instantiation: pkixtestnss.cpp:mozilla::pkix::ScopedPtr<SECKEYEncryptedPrivateKeyInfoStr, mozilla::pkix::test::(anonymous namespace)::SECKEY_DestroyEncryptedPrivateKeyInfo_true(SECKEYEncryptedPrivateKeyInfoStr*)>::operator->() const |
54 | | |
55 | 0 | explicit operator bool() const { return mValue; } Unexecuted instantiation: mozilla::pkix::ScopedPtr<CERTSubjectPublicKeyInfoStr, SECKEY_DestroySubjectPublicKeyInfo>::operator bool() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPublicKeyStr, SECKEY_DestroyPublicKey>::operator bool() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::operator bool() const Unexecuted instantiation: pkixocsp_VerifyEncodedOCSPResponse.cpp:mozilla::pkix::ScopedPtr<mozilla::pkix::CertID, (anonymous namespace)::deleteCertID(mozilla::pkix::CertID*)>::operator bool() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<PK11SlotInfoStr, PK11_FreeSlot>::operator bool() const Unexecuted instantiation: pkixtestnss.cpp:mozilla::pkix::ScopedPtr<SECKEYEncryptedPrivateKeyInfoStr, mozilla::pkix::test::(anonymous namespace)::SECKEY_DestroyEncryptedPrivateKeyInfo_true(SECKEYEncryptedPrivateKeyInfoStr*)>::operator bool() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPrivateKeyStr, SECKEY_DestroyPrivateKey>::operator bool() const Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::operator bool() const |
56 | | |
57 | 0 | T* get() const { return mValue; } Unexecuted instantiation: mozilla::pkix::ScopedPtr<CERTSubjectPublicKeyInfoStr, SECKEY_DestroySubjectPublicKeyInfo>::get() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPublicKeyStr, SECKEY_DestroyPublicKey>::get() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::get() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<PK11SlotInfoStr, PK11_FreeSlot>::get() const Unexecuted instantiation: mozilla::pkix::ScopedPtr<SECKEYPrivateKeyStr, SECKEY_DestroyPrivateKey>::get() const Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::get() const |
58 | | |
59 | | T* release() |
60 | 0 | { |
61 | 0 | T* result = mValue; |
62 | 0 | mValue = nullptr; |
63 | 0 | return result; |
64 | 0 | } Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::release() Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::release() |
65 | | |
66 | | void reset(T* newValue = nullptr) |
67 | 0 | { |
68 | 0 | // The C++ standard requires std::unique_ptr to destroy the old value |
69 | 0 | // pointed to by mValue, if any, *after* assigning the new value to mValue. |
70 | 0 | T* oldValue = mValue; |
71 | 0 | mValue = newValue; |
72 | 0 | if (oldValue) { |
73 | 0 | Destroyer(oldValue); |
74 | 0 | } |
75 | 0 | } Unexecuted instantiation: mozilla::pkix::ScopedPtr<mozilla::pkix::test::TestKeyPair, mozilla::pkix::test::DeleteTestKeyPair(mozilla::pkix::test::TestKeyPair*)>::reset(mozilla::pkix::test::TestKeyPair*) Unexecuted instantiation: pkixocsp_VerifyEncodedOCSPResponse.cpp:mozilla::pkix::ScopedPtr<mozilla::pkix::CertID, (anonymous namespace)::deleteCertID(mozilla::pkix::CertID*)>::reset(mozilla::pkix::CertID*) Unexecuted instantiation: pkixtestutil.cpp:mozilla::pkix::ScopedPtr<_IO_FILE, mozilla::pkix::test::(anonymous namespace)::fclose_void(_IO_FILE*)>::reset(_IO_FILE*) |
76 | | |
77 | | private: |
78 | | T* mValue; |
79 | | }; |
80 | | |
81 | | } } // namespace mozilla::pkix |
82 | | |
83 | | #endif // mozilla_pkix_ScopedPtr_h |