1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "utils/ref_count.h"
17 namespace OHOS::DistributedData {
RefCount()18 RefCount::RefCount()
19 {
20 }
21 
RefCount(std::function<void ()> action)22 RefCount::RefCount(std::function<void()> action)
23 {
24     ref_ = std::shared_ptr<const char>("RefCount", [action](const char *) {
25         if (action) {
26             action();
27         }
28     });
29 }
30 
RefCount(const RefCount & other)31 RefCount::RefCount(const RefCount &other)
32 {
33     if (this == &other) {
34         return ;
35     }
36     ref_ = other.ref_;
37 }
38 
RefCount(RefCount && other)39 RefCount::RefCount(RefCount &&other) noexcept
40 {
41     if (this == &other) {
42         return ;
43     }
44     ref_ = std::move(other.ref_);
45 }
46 
operator =(const RefCount & other)47 RefCount &RefCount::operator=(const RefCount &other)
48 {
49     if (this == &other) {
50         return *this;
51     }
52     ref_ = other.ref_;
53     return *this;
54 }
55 
operator =(RefCount && other)56 RefCount &RefCount::operator=(RefCount &&other) noexcept
57 {
58     if (this == &other) {
59         return *this;
60     }
61     ref_ = std::move(other.ref_);
62     return *this;
63 }
64 
65 RefCount::operator bool() const
66 {
67     return ref_ != nullptr;
68 }
69 } // namespace OHOS::DistributedKv