TagLib  2.2.1
mp4itemfactory.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_MP4ITEMFACTORY_H
27 #define TAGLIB_MP4ITEMFACTORY_H
28 
29 #include <memory>
30 #include "taglib_export.h"
31 #include "mp4item.h"
32 
33 namespace TagLib {
34 
35  namespace MP4 {
36 
38 
70  {
71  public:
72  ItemFactory(const ItemFactory &) = delete;
73  ItemFactory &operator=(const ItemFactory &) = delete;
74 
75  static ItemFactory *instance();
76 
83  virtual std::pair<String, Item> parseItem(
84  const Atom *atom, const ByteVector &data) const;
85 
91  virtual ByteVector renderItem(
92  const String &itemName, const Item &item) const;
93 
99  virtual std::pair<ByteVector, Item> itemFromProperty(
100  const String &key, const StringList &values) const;
101 
108  virtual std::pair<String, StringList> itemToProperty(
109  const ByteVector &itemName, const Item &item) const;
110 
117  virtual String propertyKeyForName(const ByteVector &name) const;
118 
125  virtual ByteVector nameForPropertyKey(const String &key) const;
126 
127  protected:
132  enum class ItemHandlerType {
133  Unknown,
134  FreeForm,
135  IntPair,
136  IntPairNoTrailing,
137  Bool,
138  Int,
139  TextOrInt,
140  UInt,
141  LongLong,
142  Byte,
143  Gnre,
144  Covr,
145  Stem,
146  TextImplicit,
147  Text
148  };
149 
152 
157  ItemFactory();
158 
162  ~ItemFactory();
163 
171  virtual NameHandlerMap nameHandlerMap() const;
172 
178  virtual ItemHandlerType handlerTypeForName(const ByteVector &name) const;
179 
187  virtual Map<ByteVector, String> namePropertyMap() const;
188 
189  // Functions used by parseItem() to create items from atom data.
190  static MP4::AtomDataList parseData2(
191  const MP4::Atom *atom, const ByteVector &data, int expectedFlags = -1,
192  bool freeForm = false);
193  static ByteVectorList parseData(
194  const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = -1,
195  bool freeForm = false);
196  static std::pair<String, Item> parseText(
197  const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = 1);
198  static std::pair<String, Item> parseFreeForm(
199  const MP4::Atom *atom, const ByteVector &bytes);
200  static std::pair<String, Item> parseInt(
201  const MP4::Atom *atom, const ByteVector &bytes);
202  static std::pair<String, Item> parseByte(
203  const MP4::Atom *atom, const ByteVector &bytes);
204  static std::pair<String, Item> parseTextOrInt(
205  const MP4::Atom *atom, const ByteVector &bytes);
206  static std::pair<String, Item> parseUInt(
207  const MP4::Atom *atom, const ByteVector &bytes);
208  static std::pair<String, Item> parseLongLong(
209  const MP4::Atom *atom, const ByteVector &bytes);
210  static std::pair<String, Item> parseGnre(
211  const MP4::Atom *atom, const ByteVector &bytes);
212  static std::pair<String, Item> parseIntPair(
213  const MP4::Atom *atom, const ByteVector &bytes);
214  static std::pair<String, Item> parseBool(
215  const MP4::Atom *atom, const ByteVector &bytes);
216  static std::pair<String, Item> parseCovr(
217  const MP4::Atom *atom, const ByteVector &data);
218  static std::pair<String, Item> parseStem(
219  const MP4::Atom *atom, const ByteVector &data);
220 
221  // Functions used by renderItem() to render atom data for items.
222  static ByteVector renderAtom(
223  const ByteVector &name, const ByteVector &data);
224  static ByteVector renderData(
225  const ByteVector &name, int flags, const ByteVectorList &data);
226  static ByteVector renderText(
227  const ByteVector &name, const MP4::Item &item, int flags = TypeUTF8);
228  static ByteVector renderFreeForm(
229  const String &name, const MP4::Item &item);
230  static ByteVector renderBool(
231  const ByteVector &name, const MP4::Item &item);
232  static ByteVector renderInt(
233  const ByteVector &name, const MP4::Item &item);
234  static ByteVector renderTextOrInt(
235  const ByteVector &name, const MP4::Item &item);
236  static ByteVector renderByte(
237  const ByteVector &name, const MP4::Item &item);
238  static ByteVector renderUInt(
239  const ByteVector &name, const MP4::Item &item);
240  static ByteVector renderLongLong(
241  const ByteVector &name, const MP4::Item &item);
242  static ByteVector renderIntPair(
243  const ByteVector &name, const MP4::Item &item);
244  static ByteVector renderIntPairNoTrailing(
245  const ByteVector &name, const MP4::Item &item);
246  static ByteVector renderCovr(
247  const ByteVector &name, const MP4::Item &item);
248  static ByteVector renderStem(
249  const ByteVector &name, const MP4::Item &item);
250 
251  private:
252  static ItemFactory factory;
253 
254  class ItemFactoryPrivate;
256  std::unique_ptr<ItemFactoryPrivate> d;
257  };
258 
259  } // namespace MP4
260 } // namespace TagLib
261 
262 #endif
A list of ByteVectors.
Definition: tbytevectorlist.h:41
A wide string class suitable for unicode.
Definition: tstring.h:82
A byte vector.
Definition: tbytevector.h:45
Definition: mp4stem.h:40
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition: taglib_export.h:55
A generic, implicitly shared map.
Definition: tmap.h:44
MP4 item.
Definition: mp4item.h:37
A list of strings.
Definition: tstringlist.h:43
ItemHandlerType
Definition: mp4itemfactory.h:132
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
A factory for creating MP4 items during parsing.
Definition: mp4itemfactory.h:69
Definition: mp4atom.h:39
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41