Commit efe46cbb authored by Scott Wheeler's avatar Scott Wheeler

Adding the basics for an explicitly shared "filehandle" class that can be

passed around in the JuK API without breaking encapsulation boundaries in
all sorts of ugly ways (like passing around playlistitems does).

Eventually the cache will be moved over to caching these items rather than
tags since this allows the flexibility of not being strictly connected to
in-file meta-data.

svn path=/trunk/kdemultimedia/juk/; revision=292622
parent 1ed5929d
......@@ -11,6 +11,7 @@ juk_SOURCES = \
directorylist.cpp \
directorylistbase.ui \
dynamicplaylist.cpp \
filehandle.cpp \
filerenamer.cpp \
filerenamerconfigdlg.cpp \
filerenamerconfigdlgwidget.ui \
......
/***************************************************************************
filehandle.cpp
-------------------
begin : Sun Feb 29 2004
copyright : (C) 2004 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "filehandle.h"
#include "tag.h"
/**
* A simple reference counter -- pasted from TagLib.
*/
class RefCounter
{
public:
RefCounter() : refCount(1) {}
void ref() { refCount++; }
bool deref() { return ! --refCount ; }
int count() const { return refCount; }
private:
uint refCount;
};
class FileHandle::FileHandlePrivate : public RefCounter
{
public:
FileHandlePrivate() :
tag(0) {}
Tag *tag;
};
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
FileHandle::FileHandle()
{
d = new FileHandlePrivate;
}
FileHandle::FileHandle(const FileHandle &f) : d(f.d)
{
d->ref();
}
FileHandle::~FileHandle()
{
if(d->deref())
delete d;
}
Tag *FileHandle::tag() const
{
return d->tag;
}
FileHandle &FileHandle::operator=(const FileHandle &f)
{
if(&f == this)
return *this;
if(d->deref())
delete d;
d = f.d;
d->ref();
return *this;
}
bool FileHandle::operator==(const FileHandle &f) const
{
return d == f.d;
}
/***************************************************************************
filehandle.h
-------------------
begin : Sun Feb 29 2004
copyright : (C) 2004 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef JUK_FILEHANDLE_H
#define JUK_FILEHANLDE_H
class Tag;
/**
* An value based, explicitly shared wrapper around file related information
* used in JuK's playlists.
*/
class FileHandle
{
public:
FileHandle();
FileHandle(const FileHandle &f);
~FileHandle();
Tag *tag() const;
FileHandle &operator=(const FileHandle &f);
bool operator==(const FileHandle &f) const;
private:
class FileHandlePrivate;
FileHandlePrivate *d;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment