TagLib API Documentation
mp4chapterholder.h
Go to the documentation of this file.
1/**************************************************************************
2 copyright : (C) 2006 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_MP4CHAPTERHOLDER_H
27#define TAGLIB_MP4CHAPTERHOLDER_H
28
29#include "mp4chapter.h"
30
31namespace TagLib {
32 class File;
33 namespace MP4 {
38 public:
42 ChapterList chapters() const { return chapterList; }
43
48
52 bool isModified() const { return modified; }
53
58
59 protected:
61 bool modified = false;
62 };
63
71 template <typename T>
72 ChapterList getChaptersLazy(std::unique_ptr<T> &holder, TagLib::File *file)
73 {
74 if (!holder) {
75 holder = std::make_unique<T>();
76 holder->read(file);
77 }
78 return holder->chapters();
79 }
80
87 template <typename T>
88 void setChaptersLazy(std::unique_ptr<T> &holder, const ChapterList& chapters)
89 {
90 if (!holder) {
91 holder = std::make_unique<T>();
92 // The chapters have not been read before, so we do not know their
93 // current state and mark them as modified. Otherwise, the check below
94 // would not set the chapters if they are empty.
95 holder->setModified(true);
96 }
97 if(holder->isModified() || holder->chapters() != chapters) {
98 holder->setChapters(chapters);
99 holder->setModified(true);
100 }
101 }
102
110 template <typename T>
111 bool saveChaptersIfModified(std::unique_ptr<T> &holder, TagLib::File *file)
112 {
113 if(holder && holder->isModified()) {
114 if(holder->write(file)) {
115 holder->setModified(false);
116 return true;
117 }
118 return false;
119 }
120 return true;
121 }
122
123 } // namespace MP4
124} // namespace TagLib
125
126#endif
A file class with some useful methods for tag manipulation.
Definition tfile.h:51
Definition mp4chapterholder.h:37
ChapterList chapters() const
Definition mp4chapterholder.h:42
bool modified
Definition mp4chapterholder.h:61
ChapterList chapterList
Definition mp4chapterholder.h:60
void setModified(bool chaptersModified)
Definition mp4chapterholder.h:57
void setChapters(const ChapterList &chapters)
Definition mp4chapterholder.h:47
bool isModified() const
Definition mp4chapterholder.h:52
ChapterList getChaptersLazy(std::unique_ptr< T > &holder, TagLib::File *file)
Definition mp4chapterholder.h:72
void setChaptersLazy(std::unique_ptr< T > &holder, const ChapterList &chapters)
Definition mp4chapterholder.h:88
bool saveChaptersIfModified(std::unique_ptr< T > &holder, TagLib::File *file)
Definition mp4chapterholder.h:111
A namespace for all TagLib related classes and functions.
Definition apefile.h:41