xlnt
variant.hpp
1 // Copyright (c) 2017-2022 Thomas Fussell
2 // Copyright (c) 2024 xlnt-community
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <cstdint>
28 #include <string>
29 #include <vector>
30 
31 #include <xlnt/xlnt_config.hpp>
32 
33 namespace xlnt {
34 
35 struct datetime;
36 
40 class XLNT_API variant
41 {
42 public:
43  // TODO: implement remaining types?
44 
48  enum class type
49  {
50  vector,
51  //array,
52  //blob,
53  //oblob,
54  //empty,
55  null,
56  //i1,
57  //i2,
58  i4,
59  //i8,
60  //integer,
61  //ui1,
62  //ui2,
63  //ui4,
64  //ui8,
65  //uint,
66  //r4,
67  //r8,
68  //decimal,
69  lpstr, // TODO: how does this differ from lpwstr?
70  //lpwstr,
71  //bstr,
72  date,
73  //filetime,
74  boolean,
75  //cy,
76  //error,
77  //stream,
78  //ostream,
79  //storage,
80  //ostorage,
81  //vstream,
82  //clsid
83  };
84 
88  variant();
89 
93  variant(const std::string &value);
94 
98  variant(const char *value);
99 
103  variant(std::int32_t value);
104 
108  variant(bool value);
109 
113  variant(const datetime &value);
114 
118  variant(const std::initializer_list<std::int32_t> &value);
119 
123  variant(const std::vector<std::int32_t> &value);
124 
128  variant(const std::initializer_list<const char *> &value);
129 
133  variant(const std::vector<const char *> &value);
134 
138  variant(const std::initializer_list<std::string> &value);
139 
143  variant(const std::vector<std::string> &value);
144 
148  variant(const std::vector<variant> &value);
149 
153  bool is(type t) const;
154 
159  template <typename T>
160  T get() const;
161 
165  type value_type() const;
166 
167  bool operator==(const variant &rhs) const;
168 
169 private:
170  type type_;
171  std::vector<variant> vector_value_;
172  std::int32_t i4_value_;
173  std::string lpstr_value_;
174 };
175 
176 template <>
177 bool variant::get() const;
178 
179 template <>
180 std::int32_t variant::get() const;
181 
182 template <>
183 std::string variant::get() const;
184 
185 template <>
186 datetime variant::get() const;
187 
188 template <>
189 std::vector<std::int32_t> variant::get() const;
190 
191 template <>
192 std::vector<std::string> variant::get() const;
193 
194 template <>
195 std::vector<variant> variant::get() const;
196 
197 } // namespace xlnt
type
The possible types a variant can hold.
Definition: variant.hpp:48
Represents an object that can have variable type.
Definition: variant.hpp:40
T get() const
Returns the value of this variant as type T. An exception will be thrown if the types are not convert...
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
value is an ISO 8601 formatted date
A datetime is a combination of a date and a time. IMPORTANT: The datetime could be in an empty/invali...
Definition: datetime.hpp:41
value is TRUE or FALSE