TagLib  2.2.1
tvariant.h
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2023 by Urs Fleisch
3  email : ufleisch@users.sourceforge.net
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * This library is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU Lesser General Public License version *
9  * 2.1 as published by the Free Software Foundation. *
10  * *
11  * This library is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the Free Software *
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19  * 02110-1301 USA *
20  * *
21  * Alternatively, this file is available under the Mozilla Public *
22  * License Version 1.1. You may obtain a copy of the License at *
23  * http://www.mozilla.org/MPL/ *
24  ***************************************************************************/
25 
26 #ifndef TAGLIB_VARIANT_H
27 #define TAGLIB_VARIANT_H
28 
29 #include <sstream>
30 
31 #include "tlist.h"
32 #include "tmap.h"
33 #include "taglib_export.h"
34 
35 // Forward declaration needed for friend function
36 namespace TagLib { class Variant; }
37 
43 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::Variant &v);
44 
45 namespace TagLib {
46 
47  class String;
48  class StringList;
49  class ByteVector;
50  class ByteVectorList;
51 
53 
61  {
62  public:
66  // The number and order of these types must correspond to the template
67  // parameters for StdVariantType in tvariant.cpp!
68  enum Type {
69  Void,
70  Bool,
71  Int,
72  UInt,
82  };
83 
87  Variant();
88 
89  Variant(int val);
90  Variant(unsigned int val);
91  Variant(long long val);
92  Variant(unsigned long long val);
93  Variant(bool val);
94  Variant(double val);
95  Variant(const char *val);
96  Variant(const TagLib::String &val);
97  Variant(const TagLib::StringList &val);
98  Variant(const TagLib::ByteVector &val);
99  Variant(const TagLib::ByteVectorList &val);
102 
108  Variant(const Variant &v);
109 
113  ~Variant();
114 
118  Type type() const;
119 
123  bool isEmpty() const;
124 
132  int toInt(bool *ok = nullptr) const;
133 
135  unsigned int toUInt(bool *ok = nullptr) const;
137  long long toLongLong(bool *ok = nullptr) const;
139  unsigned long long toULongLong(bool *ok = nullptr) const;
141  bool toBool(bool *ok = nullptr) const;
143  double toDouble(bool *ok = nullptr) const;
145  TagLib::String toString(bool *ok = nullptr) const;
147  TagLib::StringList toStringList(bool *ok = nullptr) const;
149  TagLib::ByteVector toByteVector(bool *ok = nullptr) const;
151  TagLib::ByteVectorList toByteVectorList(bool *ok = nullptr) const;
153  TagLib::List<TagLib::Variant> toList(bool *ok = nullptr) const;
155  TagLib::Map<TagLib::String, TagLib::Variant> toMap(bool *ok = nullptr) const;
156 
164  template<typename T>
165  T value(bool *ok = nullptr) const;
166 
171  bool operator==(const Variant &v) const;
172 
176  bool operator!=(const Variant &v) const;
177 
182  Variant &operator=(const Variant &v);
183 
184  private:
185  friend TAGLIB_EXPORT std::ostream& ::operator<<(std::ostream &s, const TagLib::Variant &v);
186  class VariantPrivate;
188  std::shared_ptr<VariantPrivate> d;
189  };
190 
193 
196 
197  extern template TAGLIB_EXPORT bool Variant::value(bool *ok) const;
198  extern template TAGLIB_EXPORT int Variant::value(bool *ok) const;
199  extern template TAGLIB_EXPORT unsigned int Variant::value(bool *ok) const;
200  extern template TAGLIB_EXPORT long long Variant::value(bool *ok) const;
201  extern template TAGLIB_EXPORT unsigned long long Variant::value(bool *ok) const;
202  extern template TAGLIB_EXPORT double Variant::value(bool *ok) const;
203  extern template TAGLIB_EXPORT String Variant::value(bool *ok) const;
204  extern template TAGLIB_EXPORT StringList Variant::value(bool *ok) const;
205  extern template TAGLIB_EXPORT ByteVector Variant::value(bool *ok) const;
206  extern template TAGLIB_EXPORT ByteVectorList Variant::value(bool *ok) const;
207  extern template TAGLIB_EXPORT VariantList Variant::value(bool *ok) const;
208  extern template TAGLIB_EXPORT VariantMap Variant::value(bool *ok) const;
209 } // namespace TagLib
210 
211 #endif
A list of ByteVectors.
Definition: tbytevectorlist.h:41
A generic, implicitly shared list.
Definition: tlist.h:53
String.
Definition: tvariant.h:76
bool
Definition: tvariant.h:70
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
T value(bool *ok=nullptr) const
int
Definition: tvariant.h:71
An implicitly shared discriminated union.
Definition: tvariant.h:60
A wide string class suitable for unicode.
Definition: tstring.h:82
A byte vector.
Definition: tbytevector.h:45
VariantList
Definition: tvariant.h:80
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition: taglib_export.h:55
ByteVectorList.
Definition: tvariant.h:79
unsigned int
Definition: tvariant.h:72
A generic, implicitly shared map.
Definition: tmap.h:44
A list of strings.
Definition: tstringlist.h:43
StringList.
Definition: tvariant.h:77
ByteVector.
Definition: tvariant.h:78
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
double
Definition: tvariant.h:75
unsigned long long
Definition: tvariant.h:74
Type
Definition: tvariant.h:68
variant is empty
Definition: tvariant.h:69
long long
Definition: tvariant.h:73
TAGLIB_EXPORT unsigned int toUInt(const ByteVector &data)
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41