mp4chapterholder.h
Go to the documentation of this file.
/**************************************************************************
copyright : (C) 2006 by Urs Fleisch
email : ufleisch@users.sourceforge.net
**************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifndef TAGLIB_MP4CHAPTERHOLDER_H
#define TAGLIB_MP4CHAPTERHOLDER_H
#include "mp4chapter.h"
namespace TagLib {
class File;
namespace MP4 {
class ChapterHolder {
public:
ChapterList chapters() const { return chapterList; }
void setChapters(const ChapterList &chapters) { chapterList = chapters; }
bool isModified() const { return modified; }
void setModified(bool chaptersModified) { modified = chaptersModified; }
protected:
ChapterList chapterList;
bool modified = false;
};
template <typename T>
ChapterList getChaptersLazy(std::unique_ptr<T> &holder, TagLib::File *file)
{
if (!holder) {
holder = std::make_unique<T>();
holder->read(file);
}
return holder->chapters();
}
template <typename T>
void setChaptersLazy(std::unique_ptr<T> &holder, const ChapterList& chapters)
{
if (!holder) {
holder = std::make_unique<T>();
// The chapters have not been read before, so we do not know their
// current state and mark them as modified. Otherwise, the check below
// would not set the chapters if they are empty.
holder->setModified(true);
}
if(holder->isModified() || holder->chapters() != chapters) {
holder->setChapters(chapters);
holder->setModified(true);
}
}
template <typename T>
bool saveChaptersIfModified(std::unique_ptr<T> &holder, TagLib::File *file)
{
if(holder && holder->isModified()) {
if(holder->write(file)) {
holder->setModified(false);
return true;
}
return false;
}
return true;
}
} // namespace MP4
} // namespace TagLib
#endif
TagLib::File
A file class with some useful methods for tag manipulation.
Definition tfile.h:51
TagLib::MP4::ChapterHolder
Definition mp4chapterholder.h:37
TagLib::MP4::ChapterHolder::chapters
ChapterList chapters() const
Definition mp4chapterholder.h:42
TagLib::MP4::ChapterHolder::modified
bool modified
Definition mp4chapterholder.h:61
TagLib::MP4::ChapterHolder::chapterList
ChapterList chapterList
Definition mp4chapterholder.h:60
TagLib::MP4::ChapterHolder::setModified
void setModified(bool chaptersModified)
Definition mp4chapterholder.h:57
TagLib::MP4::ChapterHolder::setChapters
void setChapters(const ChapterList &chapters)
Definition mp4chapterholder.h:47
TagLib::MP4::ChapterHolder::isModified
bool isModified() const
Definition mp4chapterholder.h:52
mp4chapter.h
TagLib::MP4
An implementation of MP4 (AAC, ALAC, ...) metadata.
Definition mp4atom.h:35
TagLib::MP4::getChaptersLazy
ChapterList getChaptersLazy(std::unique_ptr< T > &holder, TagLib::File *file)
Definition mp4chapterholder.h:72
TagLib::MP4::ChapterList
List< Chapter > ChapterList
List of chapters.
Definition mp4chapter.h:103
TagLib::MP4::setChaptersLazy
void setChaptersLazy(std::unique_ptr< T > &holder, const ChapterList &chapters)
Definition mp4chapterholder.h:88
TagLib::MP4::saveChaptersIfModified
bool saveChaptersIfModified(std::unique_ptr< T > &holder, TagLib::File *file)
Definition mp4chapterholder.h:111
TagLib
A namespace for all TagLib related classes and functions.
Definition apefile.h:41