MP4::Atom::Atom(File *file)
{
+ children.setAutoDelete(true);
+
offset = file->tell();
ByteVector header = file->readBlock(8);
if (header.size() != 8) {
MP4::Atom::~Atom()
{
- for(unsigned int i = 0; i < children.size(); i++) {
- delete children[i];
- }
- children.clear();
}
MP4::Atom *
if(name1 == 0) {
return this;
}
- for(unsigned int i = 0; i < children.size(); i++) {
- if(children[i]->name == name1) {
- return children[i]->find(name2, name3, name4);
+ for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
+ if((*it)->name == name1) {
+ return (*it)->find(name2, name3, name4);
}
}
return 0;
MP4::Atom::findall(const char *name, bool recursive)
{
MP4::AtomList result;
- for(unsigned int i = 0; i < children.size(); i++) {
- if(children[i]->name == name) {
- result.append(children[i]);
+ for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
+ if((*it)->name == name) {
+ result.append(*it);
}
if(recursive) {
- result.append(children[i]->findall(name, recursive));
+ result.append((*it)->findall(name, recursive));
}
}
return result;
if(name1 == 0) {
return true;
}
- for(unsigned int i = 0; i < children.size(); i++) {
- if(children[i]->name == name1) {
- return children[i]->path(path, name2, name3);
+ for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
+ if((*it)->name == name1) {
+ return (*it)->path(path, name2, name3);
}
}
return false;
MP4::Atoms::Atoms(File *file)
{
+ atoms.setAutoDelete(true);
+
file->seek(0, File::End);
long end = file->tell();
file->seek(0);
MP4::Atoms::~Atoms()
{
- for(unsigned int i = 0; i < atoms.size(); i++) {
- delete atoms[i];
- }
- atoms.clear();
}
MP4::Atom *
MP4::Atoms::find(const char *name1, const char *name2, const char *name3, const char *name4)
{
- for(unsigned int i = 0; i < atoms.size(); i++) {
- if(atoms[i]->name == name1) {
- return atoms[i]->find(name2, name3, name4);
+ for(AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) {
+ if((*it)->name == name1) {
+ return (*it)->find(name2, name3, name4);
}
}
return 0;
MP4::Atoms::path(const char *name1, const char *name2, const char *name3, const char *name4)
{
MP4::AtomList path;
- for(unsigned int i = 0; i < atoms.size(); i++) {
- if(atoms[i]->name == name1) {
- if(!atoms[i]->path(path, name2, name3, name4)) {
+ for(AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) {
+ if((*it)->name == name1) {
+ if(!(*it)->path(path, name2, name3, name4)) {
path.clear();
}
return path;
}
return path;
}
-
class Atom
{
public:
- Atom(File *file);
- ~Atom();
- Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
- bool path(AtomList &path, const char *name1, const char *name2 = 0, const char *name3 = 0);
- AtomList findall(const char *name, bool recursive = false);
- long offset;
- long length;
- TagLib::ByteVector name;
- AtomList children;
+ Atom(File *file);
+ ~Atom();
+ Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
+ bool path(AtomList &path, const char *name1, const char *name2 = 0, const char *name3 = 0);
+ AtomList findall(const char *name, bool recursive = false);
+ long offset;
+ long length;
+ TagLib::ByteVector name;
+ AtomList children;
private:
- static const int numContainers = 11;
- static const char *containers[11];
+ static const int numContainers = 11;
+ static const char *containers[11];
};
//! Root-level atoms
class Atoms
{
public:
- Atoms(File *file);
- ~Atoms();
- Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
- AtomList path(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
- AtomList atoms;
+ Atoms(File *file);
+ ~Atoms();
+ Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
+ AtomList path(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
+ AtomList atoms;
};
}