TagLib API Documentation
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 <iosfwd>
30
31#include "tlist.h"
32#include "tmap.h"
33#include "taglib_export.h"
34
35// Forward declaration needed for friend function
36namespace TagLib { class Variant; }
37
43TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::Variant &v);
44
45namespace 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 {
82 };
83
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);
102
108 Variant(const Variant &v);
109
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;
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
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:42
A byte vector.
Definition: tbytevector.h:46
A generic, implicitly shared list.
Definition: tlist.h:54
A generic, implicitly shared map.
Definition: tmap.h:45
A list of strings.
Definition: tstringlist.h:44
A wide string class suitable for unicode.
Definition: tstring.h:83
An implicitly shared discriminated union.
Definition: tvariant.h:61
Variant(double val)
T value(bool *ok=nullptr) const
TagLib::StringList toStringList(bool *ok=nullptr) const
Variant(unsigned int val)
unsigned int toUInt(bool *ok=nullptr) const
Variant(const TagLib::List< TagLib::Variant > &val)
Variant(int val)
Variant(const TagLib::String &val)
TagLib::List< TagLib::Variant > toList(bool *ok=nullptr) const
Variant(const TagLib::ByteVector &val)
TagLib::ByteVectorList toByteVectorList(bool *ok=nullptr) const
Variant(const char *val)
Variant(const TagLib::ByteVectorList &val)
bool toBool(bool *ok=nullptr) const
bool operator!=(const Variant &v) const
int toInt(bool *ok=nullptr) const
Variant(bool val)
Type
Definition: tvariant.h:68
@ UInt
unsigned int
Definition: tvariant.h:72
@ VariantList
VariantList
Definition: tvariant.h:80
@ String
String.
Definition: tvariant.h:76
@ LongLong
long long
Definition: tvariant.h:73
@ Int
int
Definition: tvariant.h:71
@ Void
variant is empty
Definition: tvariant.h:69
@ ByteVector
ByteVector.
Definition: tvariant.h:78
@ Bool
bool
Definition: tvariant.h:70
@ ByteVectorList
ByteVectorList.
Definition: tvariant.h:79
@ Double
double
Definition: tvariant.h:75
@ StringList
StringList.
Definition: tvariant.h:77
@ ULongLong
unsigned long long
Definition: tvariant.h:74
Variant(const Variant &v)
Variant(const TagLib::Map< TagLib::String, TagLib::Variant > &val)
bool isEmpty() const
unsigned long long toULongLong(bool *ok=nullptr) const
double toDouble(bool *ok=nullptr) const
Variant & operator=(const Variant &v)
Type type() const
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::Variant &v)
TagLib::Map< TagLib::String, TagLib::Variant > toMap(bool *ok=nullptr) const
Variant(unsigned long long val)
TagLib::String toString(bool *ok=nullptr) const
Variant(long long val)
TagLib::ByteVector toByteVector(bool *ok=nullptr) const
Variant(const TagLib::StringList &val)
long long toLongLong(bool *ok=nullptr) const
bool operator==(const Variant &v) const
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition: taglib_export.h:55