xlnt - community edition
value_with_default.h
1 // Copyright (c) 2026 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 #include <cmath>
27 #include <cstdint>
28 #include <limits>
29 #include <utility>
30 
31 namespace xlnt {
32 namespace detail {
33 
34 template<typename T, T value>
36 {
37  static constexpr T get() {return value;}
38  static bool is(const T& v) {return get() == v;}
39 };
40 
41 template<typename T, std::int64_t numerator, std::int64_t denominator = 1>
42 struct default_fp
43 {
44  static constexpr T get() {return (T) numerator / denominator;}
45  static bool is(const T& v) {return get() == v;}
46 };
47 
48 template<typename T>
50 {
51  static constexpr T get() {return std::numeric_limits<T>::quiet_NaN();}
52  static bool is(const T& v) {return std::isnan(v);}
53 };
54 
58 template <typename T, typename DEFAULT>
60 {
61 public:
62  explicit value_with_default_type(T value = DEFAULT::get()) : value_(std::move(value)) {}
63 
64  bool is_default () const {return DEFAULT::is(value_);}
65  bool is_set () const {return !is_default();}
66 
67  const T& get () const {return value_;}
68  T& get () {return value_;}
69  operator const T&() const {return get();}
70  operator T&() {return get();}
71 
72  value_with_default_type& operator=(T value) {value_ = std::move(value); return *this;}
73 
74 private:
75  T value_;
76 };
77 
78 template<typename T, T default_value_>
80 
81 template<typename T, std::int64_t numerator, std::int64_t denominator = 1>
83 
84 template<std::int64_t numerator, std::int64_t denominator = 1>
86 
87 template<std::int64_t numerator, std::int64_t denominator = 1>
89 
90 template<typename T>
92 
93 } // namespace detail
94 } // namespace xlnt
Definition: value_with_default.h:42
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:36
Encapsulates a value with a default value
Definition: value_with_default.h:59
Definition: value_with_default.h:35
Definition: value_with_default.h:49