xlnt - community edition
format_impl_ptr.hpp
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  format_impl_ptr() = default;
35  format_impl_ptr(const format_impl_ptr& r) : format_(r.format_) {increment();}
36  format_impl_ptr(format_impl_ptr&& r) : format_(r.format_) {r.format_ = nullptr;}
37  format_impl_ptr(format_impl *format) : format_(format) {increment();}
38  ~format_impl_ptr() {decrement();}
39 
40  format_impl_ptr& operator=(const format_impl_ptr& r)
41  {
42  if (this == &r)
43  return *this;
44 
45  decrement();
46  format_ = r.format_;
47  increment();
48  return *this;
49  }
50 
51  format_impl_ptr& operator=(format_impl_ptr&& r)
52  {
53  decrement();
54  format_ = r.format_;
55  r.format_ = nullptr;
56  return *this;
57  }
58 
59  std::size_t use_count () const;
60 
61  bool is_set () const {return format_ != nullptr;}
62  void clear () {operator=(nullptr);}
63 
64  format_impl *get() const {return format_;}
65  format_impl *operator->() const {return get();}
66  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
Enumerates the possible types a cell can be determined by it's current value.
Definition: cell.hpp:36
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Definition: format_impl_ptr.hpp:31
Describes the formatting of a particular cell.
Definition: format.hpp:58