MusicTreeBuilder Class Reference

#include <treebuilders.h>

Inheritance diagram for MusicTreeBuilder:

MusicDirectoryTreeBuilder MusicFieldTreeBuilder

List of all members.


Detailed Description

superclass for the objects that build trees of Metadata

This is the interface for objects that builds trees of Metadata objects into MusicNode objects.

The basic idea of operation is, that the superclass provices a makeTree method that depends on the subclasses for a few methods to determine which fields of the metadata objects are used in building the tree and where the metadata objects go.

This means that the superclass is fairly generic and does not itself operate on or query the metadata objects, but leaves that to the subclass. It's only responsibility is to determine the branches that go into the tree and then add metadata objects as leafs to the appropriate nodes.

Ie. if you wanted to build the MythMusic tree based on the size of the audio files by implementing a MusicSizeTreeBuilder, the approach would be to get MusicSizeTreeBuilder::getField return the number of MB or KB blocks depending on the current depth as obtained by getDept. Then you could either overload makeTree to stop at a certain depth (like MusicFieldBuilder does) or make MusicSizeTreeBuilder::isLeafDone return true if you've reached the desired granularity.

Note:
This method is fairly generic, and uses very little of the interfaces of MusicNode and Metadata, so it may someday be made more generic and of use to other plugins that needs trees.

Calling this repeated using the same or new instance on the same root node (ie. to progressively populate it) hasn't been tested.

Definition at line 45 of file treebuilders.h.


Public Member Functions

virtual ~MusicTreeBuilder ()
virtual void makeTree (MusicNode *root, const MetadataPtrList &metas)
 Create a tree using the list of Metadata objects and add them to the given root.

Static Public Member Functions

static MusicTreeBuildercreateBuilder (const QString &paths)
 Create an MusicTreeBuilder for the appropriate path.

Protected Member Functions

 MusicTreeBuilder ()
virtual MusicNodecreateNode (const QString &title)=0
 Allocates and returns a new MusicNode.
virtual bool isLeafDone (Metadata *m)=0
 Determine is a Metadata should be track at the current depth.
virtual QString getField (Metadata *m)=0
 Get the field value for the given Metadata at the current depth.
int getDepth (void)
 Get the current depth during tree building.

Private Attributes

int m_depth

Constructor & Destructor Documentation

MusicTreeBuilder::~MusicTreeBuilder (  )  [virtual]

Definition at line 94 of file treebuilders.cpp.

MusicTreeBuilder::MusicTreeBuilder (  )  [protected]

Definition at line 89 of file treebuilders.cpp.


Member Function Documentation

void MusicTreeBuilder::makeTree ( MusicNode root,
const MetadataPtrList metas 
) [virtual]

Create a tree using the list of Metadata objects and add them to the given root.

This method will recurse and operate of the list the metadata objects in metas. It's implementation may and probably will differ depending on the subclass of builder you've obtained, depending on the kind of tree it builds.

It relies heavily on subclasses implementing MusicTreeBuilder::isLeafDone and MusicTreeBuilder::getField for operation, and for performance, the subclasses should cache computed data in these methods as efficiently as possible.

Reimplemented in MusicFieldTreeBuilder.

Definition at line 98 of file treebuilders.cpp.

Referenced by AllMusic::buildTree(), and MusicFieldTreeBuilder::makeTree().

MusicTreeBuilder * MusicTreeBuilder::createBuilder ( const QString &  paths  )  [static]

Create an MusicTreeBuilder for the appropriate path.

Returns a MusicTreeBuilder subclass for building directory based or "artist album" field based trees.

Definition at line 336 of file treebuilders.cpp.

Referenced by AllMusic::buildTree().

virtual MusicNode* MusicTreeBuilder::createNode ( const QString &  title  )  [protected, pure virtual]

Allocates and returns a new MusicNode.

Implemented by the subclass. This method should allocate and a return a MusicNode with the approriate "level" set.

Implemented in MusicFieldTreeBuilder, and MusicDirectoryTreeBuilder.

Referenced by makeTree().

virtual bool MusicTreeBuilder::isLeafDone ( Metadata m  )  [protected, pure virtual]

Determine is a Metadata should be track at the current depth.

Ie. the directory builder will return true if the given Metadata's path at the current depth is the filename.

Gets called repeatedly from MusicTreeBuilder::makeTree during tree creation and should only get called once pr. depth pr. Metadata.

Implemented in MusicFieldTreeBuilder, and MusicDirectoryTreeBuilder.

Referenced by makeTree().

virtual QString MusicTreeBuilder::getField ( Metadata m  )  [protected, pure virtual]

Get the field value for the given Metadata at the current depth.

Ie. the field builder will call Metadata::getField with the appropriate field name for the current dept.

Gets called repeatedly from MusicTreeBuilder::makeTree during tree creation and may get called multiple times at the same depth for the same Metadata.

Implemented in MusicFieldTreeBuilder, and MusicDirectoryTreeBuilder.

Referenced by makeTree().

int MusicTreeBuilder::getDepth ( void   )  [inline, protected]

Get the current depth during tree building.

While MusicTreeBuilder::makeTree is recursing downwards to build the tree, this method will return the current depth and can/should be used in the subclass when implemented the virtual methods.

Ie. the directory builder can use this in isLeafDone to determine if the Metadata object under consideration has no more elements in it's path.

Definition at line 114 of file treebuilders.h.

Referenced by MusicFieldTreeBuilder::createNode(), MusicDirectoryTreeBuilder::getField(), MusicFieldTreeBuilder::getField(), MusicDirectoryTreeBuilder::isLeafDone(), and MusicFieldTreeBuilder::makeTree().


Member Data Documentation

Definition at line 117 of file treebuilders.h.

Referenced by getDepth(), makeTree(), and MusicTreeBuilder().


The documentation for this class was generated from the following files:

Generated on Sat Dec 18 05:16:07 2010 for MythTV by  doxygen 1.5.5