TagLib  2.0.2
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  TextImplicit,
146  Text
147  };
148 
151 
156  ItemFactory();
157 
161  ~ItemFactory();
162 
170  virtual NameHandlerMap nameHandlerMap() const;
171 
177  virtual ItemHandlerType handlerTypeForName(const ByteVector &name) const;
178 
186  virtual Map<ByteVector, String> namePropertyMap() const;
187 
188  // Functions used by parseItem() to create items from atom data.
189  static MP4::AtomDataList parseData2(
190  const MP4::Atom *atom, const ByteVector &data, int expectedFlags = -1,
191  bool freeForm = false);
192  static ByteVectorList parseData(
193  const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = -1,
194  bool freeForm = false);
195  static std::pair<String, Item> parseText(
196  const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = 1);
197  static std::pair<String, Item> parseFreeForm(
198  const MP4::Atom *atom, const ByteVector &bytes);
199  static std::pair<String, Item> parseInt(
200  const MP4::Atom *atom, const ByteVector &bytes);
201  static std::pair<String, Item> parseByte(
202  const MP4::Atom *atom, const ByteVector &bytes);
203  static std::pair<String, Item> parseTextOrInt(
204  const MP4::Atom *atom, const ByteVector &bytes);
205  static std::pair<String, Item> parseUInt(
206  const MP4::Atom *atom, const ByteVector &bytes);
207  static std::pair<String, Item> parseLongLong(
208  const MP4::Atom *atom, const ByteVector &bytes);
209  static std::pair<String, Item> parseGnre(
210  const MP4::Atom *atom, const ByteVector &bytes);
211  static std::pair<String, Item> parseIntPair(
212  const MP4::Atom *atom, const ByteVector &bytes);
213  static std::pair<String, Item> parseBool(
214  const MP4::Atom *atom, const ByteVector &bytes);
215  static std::pair<String, Item> parseCovr(
216  const MP4::Atom *atom, const ByteVector &data);
217 
218  // Functions used by renderItem() to render atom data for items.
219  static ByteVector renderAtom(
220  const ByteVector &name, const ByteVector &data);
221  static ByteVector renderData(
222  const ByteVector &name, int flags, const ByteVectorList &data);
223  static ByteVector renderText(
224  const ByteVector &name, const MP4::Item &item, int flags = TypeUTF8);
225  static ByteVector renderFreeForm(
226  const String &name, const MP4::Item &item);
227  static ByteVector renderBool(
228  const ByteVector &name, const MP4::Item &item);
229  static ByteVector renderInt(
230  const ByteVector &name, const MP4::Item &item);
231  static ByteVector renderTextOrInt(
232  const ByteVector &name, const MP4::Item &item);
233  static ByteVector renderByte(
234  const ByteVector &name, const MP4::Item &item);
235  static ByteVector renderUInt(
236  const ByteVector &name, const MP4::Item &item);
237  static ByteVector renderLongLong(
238  const ByteVector &name, const MP4::Item &item);
239  static ByteVector renderIntPair(
240  const ByteVector &name, const MP4::Item &item);
241  static ByteVector renderIntPairNoTrailing(
242  const ByteVector &name, const MP4::Item &item);
243  static ByteVector renderCovr(
244  const ByteVector &name, const MP4::Item &item);
245 
246  private:
247  static ItemFactory factory;
248 
249  class ItemFactoryPrivate;
251  std::unique_ptr<ItemFactoryPrivate> d;
252  };
253 
254  } // namespace MP4
255 } // namespace TagLib
256 
257 #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
#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:36
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