Branch data TLA Line data Source code
1 : : // Copyright (c) 2025 xlnt-community
2 : : //
3 : : // Permission is hereby granted, free of charge, to any person obtaining a copy
4 : : // of this software and associated documentation files (the "Software"), to deal
5 : : // in the Software without restriction, including without limitation the rights
6 : : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 : : // copies of the Software, and to permit persons to whom the Software is
8 : : // furnished to do so, subject to the following conditions:
9 : : //
10 : : // The above copyright notice and this permission notice shall be included in
11 : : // all copies or substantial portions of the Software.
12 : : //
13 : : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 : : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 : : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 : : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 : : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 : : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 : : // THE SOFTWARE
20 : : //
21 : : // @license: http://www.opensource.org/licenses/mit-license.php
22 : : // @author: see AUTHORS file
23 : :
24 : : #pragma once
25 : :
26 : : namespace xlnt {
27 : : namespace detail {
28 : :
29 : : struct format_impl;
30 : :
31 : : class XLNT_API format_impl_ptr
32 : : {
33 : : public:
34 :CBC 1769 : format_impl_ptr() = default;
35 : 1981 : format_impl_ptr(const format_impl_ptr& r) : format_(r.format_) {increment();}
36 : 3975 : format_impl_ptr(format_impl_ptr&& r) : format_(r.format_) {r.format_ = nullptr;}
37 : 2312 : format_impl_ptr(format_impl *format) : format_(format) {increment();}
38 : 10037 : ~format_impl_ptr() {decrement();}
39 : :
40 : 402 : format_impl_ptr& operator=(const format_impl_ptr& r)
41 : : {
42 [ + + ]: 402 : if (this == &r)
43 : 1 : return *this;
44 : :
45 : 401 : decrement();
46 : 401 : format_ = r.format_;
47 : 401 : increment();
48 : 401 : return *this;
49 : : }
50 : :
51 : 1967 : format_impl_ptr& operator=(format_impl_ptr&& r)
52 : : {
53 : 1967 : decrement();
54 : 1967 : format_ = r.format_;
55 : 1967 : r.format_ = nullptr;
56 : 1967 : return *this;
57 : : }
58 : :
59 : : std::size_t use_count () const;
60 : :
61 : 1936 : bool is_set () const {return format_ != nullptr;}
62 [ + + ]: 2 : void clear () {operator=(nullptr);}
63 : :
64 : 5186 : format_impl *get() const {return format_;}
65 : 2968 : format_impl *operator->() const {return get();}
66 : 2205 : operator format_impl *() const {return get();}
67 : :
68 : : bool operator== (const format_impl_ptr& r) const {return format_ == r.format_;}
69 : : bool operator== (format_impl *format) const {return format_ == format;}
70 : :
71 : : protected:
72 : : void increment();
73 : : void decrement();
74 : :
75 : : protected:
76 : : format_impl *format_ = nullptr;
77 : : };
78 : :
79 : : } // namespace detail
80 : : } // namespace xlnt
|